-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIWaitingStack.hpp
More file actions
43 lines (39 loc) · 1.3 KB
/
Copy pathIWaitingStack.hpp
File metadata and controls
43 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include "IStack.hpp"
#include <chrono>
/**
* @brief Extension of IStack that provides blocking operations.
*
* This interface is intended for stacks that support waiting semantics,
* allowing threads to block until data becomes available.
*/
template <typename T>
class IWaitingStack : public IStack<T> {
public:
/**
* @brief Blocks until an element is available, then pops it into `value`.
*
* @param value Reference where the popped value will be stored.
*/
virtual void waitAndPop(T& value) = 0;
/**
* @brief Blocks until an element is available, then returns it.
*
* @return Shared pointer to the removed element.
*/
[[nodiscard]] virtual std::shared_ptr<T> waitAndPop() = 0;
/**
* @brief Waits for an element to become available up to a specified timeout.
*
* @param value Reference where the popped value will be stored.
* @param timeout Maximum time to wait.
* @return true if an element was successfully popped, false if the timeout expired.
*
* @note Template methods cannot be virtual in C++, therefore the timeout
* type is fixed to std::chrono::milliseconds.
*/
[[nodiscard]] virtual bool waitAndPopFor(
T& value,
const std::chrono::milliseconds& timeout
) = 0;
};