OmniSciDB
a5dc49c757
|
Utility type that implemnts behavior of a blocking binary semaphore, with an optional timeout. May be removed in favor of the C++20 std::binary_semaphore as soon as we can upgrade to gcc 11. More...
#include <BinarySemaphore.h>
Public Member Functions | |
void | try_acquire () |
Blocks calling thread until it can acquire the semaphore, i.e. release is called by another thread. More... | |
bool | try_acquire_for (const size_t max_wait_in_ms) |
Blocks calling thread until it can acquire the semaphore, i.e. release is called by another thread, or max_wait_in_ms duration passes, whichever occurs first. More... | |
void | release () |
Sets internal is_ready variable to true, allowing another thread waiting for the semaphore to proceed. More... | |
void | reset () |
Resets the semaphore's ready condition to false. More... | |
void | set_ready () |
Private Attributes | |
bool | is_ready_ {false} |
std::mutex | state_mutex_ |
std::condition_variable | condition_ |
Utility type that implemnts behavior of a blocking binary semaphore, with an optional timeout. May be removed in favor of the C++20 std::binary_semaphore as soon as we can upgrade to gcc 11.
Definition at line 32 of file BinarySemaphore.h.
|
inline |
Sets internal is_ready variable to true, allowing another thread waiting for the semaphore to proceed.
Definition at line 74 of file BinarySemaphore.h.
References condition_, is_ready_, and state_mutex_.
|
inline |
Resets the semaphore's ready condition to false.
Definition at line 86 of file BinarySemaphore.h.
References is_ready_, and state_mutex_.
|
inline |
Definition at line 91 of file BinarySemaphore.h.
References is_ready_, and state_mutex_.
|
inline |
Blocks calling thread until it can acquire the semaphore, i.e. release is called by another thread.
Note that this call will block indefinitely. If a timeout is required, use try_acquire_for()
Definition at line 42 of file BinarySemaphore.h.
References condition_, is_ready_, and state_mutex_.
|
inline |
Blocks calling thread until it can acquire the semaphore, i.e. release is called by another thread, or max_wait_in_ms duration passes, whichever occurs first.
Note that this function does not throw to maximize its performance in performance-critical scenarios. Instead, it returns true if the call completed successfully and false if it timed out.
Definition at line 62 of file BinarySemaphore.h.
References condition_, is_ready_, and state_mutex_.
|
private |
Definition at line 99 of file BinarySemaphore.h.
Referenced by release(), try_acquire(), and try_acquire_for().
|
private |
Definition at line 97 of file BinarySemaphore.h.
Referenced by release(), reset(), set_ready(), try_acquire(), and try_acquire_for().
|
private |
Definition at line 98 of file BinarySemaphore.h.
Referenced by release(), reset(), set_ready(), try_acquire(), and try_acquire_for().