|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
State created by a CancellationSource. More...
#include <thread_pool.H>
Public Member Functions | |
| std::list< Locked_Observer >::iterator | register_locked (std::condition_variable &cv, std::mutex &mutex) |
Register cv, whose waiters hold mutex. | |
| void | unregister_locked (const std::list< Locked_Observer >::iterator it) noexcept |
| End a registration, once no cancellation is notifying it. | |
| void | notify_locked_observers () noexcept |
| Notify every registration made with a mutex. | |
Public Member Functions inherited from Aleph::CancellationState | |
| void | register_condition_variable (std::condition_variable *cv) |
| void | unregister_condition_variable (std::condition_variable *cv) |
| void | notify_observers () noexcept |
Public Attributes | |
| std::list< Locked_Observer > | locked_observers |
Registrations made with a mutex, in order, under observer_mutex. | |
| std::condition_variable | not_busy |
| Notified when an ended registration stops being busy. | |
Public Attributes inherited from Aleph::CancellationState | |
| std::atomic< bool > | stop_requested {false} |
| std::mutex | observer_mutex |
| std::vector< std::condition_variable * > | observers |
State created by a CancellationSource.
It adds to CancellationState, which stays as it is, the registrations made with a mutex. A cancellation takes the mutex of each one before it notifies its condition variable, and it must not wait for that mutex while it holds observer_mutex. Otherwise a thread that holds the mutex of one registration and ends another one of the same source would wait for observer_mutex while the cancellation waits for its mutex. So the cancellation marks the registration that it notifies as busy and releases observer_mutex while it uses it, and ending a registration waits only until that registration is not busy.
Definition at line 218 of file thread_pool.H.
|
inlinenoexcept |
Notify every registration made with a mutex.
Taking and releasing the mutex of a registration before notifying it means that each waiter is either before its check of the token, which then sees the cancellation, or waiting, and then woken up.
Definition at line 257 of file thread_pool.H.
References Aleph::and, locked_observers, Aleph::next(), not_busy, and Aleph::CancellationState::observer_mutex.
|
inline |
Register cv, whose waiters hold mutex.
| cv | Condition variable to notify on cancellation. |
| mutex | Mutex that the waiters on cv hold. |
| std::bad_alloc | if the registration cannot be allocated. |
Definition at line 233 of file thread_pool.H.
References locked_observers, and Aleph::CancellationState::observer_mutex.
|
inlinenoexcept |
End a registration, once no cancellation is notifying it.
| it | Position returned by register_locked(). |
Definition at line 243 of file thread_pool.H.
References locked_observers, not_busy, and Aleph::CancellationState::observer_mutex.
| std::list<Locked_Observer> Aleph::cancellation_detail::Exact_State::locked_observers |
Registrations made with a mutex, in order, under observer_mutex.
Definition at line 221 of file thread_pool.H.
Referenced by notify_locked_observers(), register_locked(), and unregister_locked().
| std::condition_variable Aleph::cancellation_detail::Exact_State::not_busy |
Notified when an ended registration stops being busy.
Definition at line 224 of file thread_pool.H.
Referenced by notify_locked_observers(), and unregister_locked().