MCPcopy Create free account
hub / github.com/bloomberg/quantum / ConditionVariable

Class ConditionVariable

quantum/quantum_condition_variable.h:36–241  ·  view source on GitHub ↗

============================================================================================== class ConditionVariable ============================================================================================== @class ConditionVariable @brief This class represents a coroutine-compatible implementation of the std::condition_variable. Most methods of the latter have been recreated with the same b

Source from the content-addressed store, hash-verified

34/// Most methods of the latter have been recreated with the same behavior. This object will yield
35/// instead of blocking if called from a coroutine.
36class ConditionVariable
37{
38public:
39 /// @brief Default constructor.
40 ConditionVariable();
41
42 /// @warning Copy constructor is explicitly deleted.
43 ConditionVariable(const ConditionVariable& other) = delete;
44
45 /// @warning Move constructor is explicitly deleted.
46 ConditionVariable(ConditionVariable&& other) = delete;
47
48 /// @warning Assignment operator is explicitly deleted.
49 ConditionVariable& operator=(const ConditionVariable& other) = delete;
50
51 /// @warning Move assignment operator is explicitly deleted.
52 ConditionVariable& operator=(ConditionVariable&& other) = delete;
53
54 /// @brief Destructor.
55 /// @warning Deleting this object while there are still waiting threads results in undefined behavior. Ensure that
56 /// all threads have been notified before doing so. Once the destructor is called, no other wait attempts
57 /// should be made on this object.
58 ~ConditionVariable();
59
60 /// @brief Notify one waiting thread or coroutine.
61 void notifyOne();
62
63 /// @brief Notify one waiting thread or coroutine.
64 /// @param[in] sync Pointer to a coroutine synchronization object.
65 void notifyOne(ICoroSync::Ptr sync);
66
67 /// @brief Notify all waiting threads and coroutines.
68 void notifyAll();
69
70 /// @brief Notify all waiting threads and coroutines.
71 /// @param[in] sync Pointer to a coroutine synchronization object.
72 void notifyAll(ICoroSync::Ptr sync);
73
74 /// @brief Block the current thread until the condition is signalled via notifyOne() or notifyAll().
75 /// @details When this function returns, the mutex is guaranteed to be locked.
76 /// @param[in] mutex Mutex object which is locked by the current thread.
77 /// @note This function should be called from a regular thread not from a coroutine.
78 void wait(Mutex& mutex);
79
80 /// @brief Yield the current coroutine until the condition is signalled via notifyOne() or notifyAll().
81 /// @details When this function returns, the mutex is guaranteed to be locked.
82 /// @param[in] sync Pointer to a coroutine synchronization object.
83 /// @param[in] mutex Mutex object which is locked by the current coroutine.
84 /// @note This function should be called from a coroutine.
85 void wait(ICoroSync::Ptr sync,
86 Mutex& mutex);
87
88 /// @brief Block the current thread until the condition is signalled via notifyOne() or notifyAll().
89 /// @details When this function returns, the mutex is guaranteed to be locked. This function calls wait() in a loop
90 /// until the predicate returns true. This ensures that the condition has not changed after notifyOne()
91 /// or notifyAll() have been called. The internal logic is equivalent to:
92 /// @code
93 /// while(!predicate())

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected