CoopSync for TBB 0.1.0
Cooperative synchronization primitives for TBB resumable tasks
Loading...
Searching...
No Matches
condition_variable.hpp
1// SPDX-FileCopyrightText: 2026 CERN
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#pragma once
6
7#include "coopsync_tbb/detail/macros.hpp"
8#include "coopsync_tbb/detail/wait_queue.hpp"
9
10namespace coopsync_tbb {
11
15class COOPSYNC_TBB_EXPORT condition_variable {
16 public:
18 condition_variable() = default;
19
22
25
28
31
37
40 void notify_one();
41
43 void notify_all();
44
50 template <typename Lock>
51 void wait(Lock& lock);
52
63 template <typename Lock, typename Pred>
64 void wait(Lock& lock, Pred pred);
65
66 private:
67 detail::wait_queue m_waiters;
68};
69
70template <typename Lock>
71inline void condition_variable::wait(Lock& lock) {
72 lock.unlock();
73 m_waiters.wait_if([] { return true; });
74
75 // Post-resumption, reacquire the lock.
76 lock.lock();
77}
78
79template <typename Lock, typename Pred>
80inline void condition_variable::wait(Lock& lock, Pred pred) {
81 while (!pred()) {
82 wait(lock);
83 }
84}
85
86} // namespace coopsync_tbb
condition_variable(const condition_variable &)=delete
The condition_variable is not copy-constructible.
condition_variable()=default
Constructs a new condition variable.
void notify_one()
Resumes one task suspended waiting on this condition variable, if there is any.
void notify_all()
Resumes all tasks suspended waiting on this condition variable.
condition_variable & operator=(const condition_variable &)=delete
The condition_variable is not copy-assignable.
condition_variable & operator=(condition_variable &&)=delete
The condition_variable is not move-assignable.
void wait(Lock &lock)
Suspends the calling task until it is notified.
Definition condition_variable.hpp:71
condition_variable(condition_variable &&)=delete
THe condition_variable is not move-constructible.
~condition_variable()
Destroys the condition variable.
Main namespace of the library, containing all public APIs.
Definition wait_for.hpp:11