Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::cancellation_detail::Exact_State Struct Reference

State created by a CancellationSource. More...

#include <thread_pool.H>

Inheritance diagram for Aleph::cancellation_detail::Exact_State:
[legend]
Collaboration diagram for Aleph::cancellation_detail::Exact_State:
[legend]

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
 

Detailed Description

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.

Member Function Documentation

◆ notify_locked_observers()

void Aleph::cancellation_detail::Exact_State::notify_locked_observers ( )
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.

◆ register_locked()

std::list< Locked_Observer >::iterator Aleph::cancellation_detail::Exact_State::register_locked ( std::condition_variable &  cv,
std::mutex &  mutex 
)
inline

Register cv, whose waiters hold mutex.

Parameters
cvCondition variable to notify on cancellation.
mutexMutex that the waiters on cv hold.
Returns
Position of the registration, for unregister_locked().
Exceptions
std::bad_allocif the registration cannot be allocated.

Definition at line 233 of file thread_pool.H.

References locked_observers, and Aleph::CancellationState::observer_mutex.

◆ unregister_locked()

void Aleph::cancellation_detail::Exact_State::unregister_locked ( const std::list< Locked_Observer >::iterator  it)
inlinenoexcept

End a registration, once no cancellation is notifying it.

Parameters
itPosition returned by register_locked().

Definition at line 243 of file thread_pool.H.

References locked_observers, not_busy, and Aleph::CancellationState::observer_mutex.

Member Data Documentation

◆ locked_observers

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().

◆ not_busy

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().


The documentation for this struct was generated from the following file: