Pigweed
 
Loading...
Searching...
No Matches
pw::sync::TimedThreadNotification Class Reference

#include <timed_thread_notification.h>

Inheritance diagram for pw::sync::TimedThreadNotification:
pw::sync::ThreadNotification

Public Member Functions

 TimedThreadNotification (const TimedThreadNotification &)=delete
 
 TimedThreadNotification (TimedThreadNotification &&)=delete
 
TimedThreadNotificationoperator= (const TimedThreadNotification &)=delete
 
TimedThreadNotificationoperator= (TimedThreadNotification &&)=delete
 
bool try_acquire_for (chrono::SystemClock::duration timeout)
 
bool try_acquire_until (chrono::SystemClock::time_point deadline)
 
- Public Member Functions inherited from pw::sync::ThreadNotification
 ThreadNotification (const ThreadNotification &)=delete
 
 ThreadNotification (ThreadNotification &&)=delete
 
ThreadNotificationoperator= (const ThreadNotification &)=delete
 
ThreadNotificationoperator= (ThreadNotification &&)=delete
 
void acquire ()
 
bool try_acquire ()
 
void release ()
 
native_handle_type native_handle ()
 

Additional Inherited Members

- Public Types inherited from pw::sync::ThreadNotification
using native_handle_type = backend::NativeThreadNotificationHandle
 

Detailed Description

The TimedThreadNotification is a synchronization primitive that can be used to permit a SINGLE thread to block and consume a latching, saturating notification from multiple notifiers.

IMPORTANT: This is a single consumer/waiter, multiple producer/notifier API! The acquire APIs must only be invoked by a single consuming thread. As a result, having multiple threads receiving notifications via the acquire API is unsupported.

This is effectively a subset of a binary semaphore API, except that only a single thread can be notified and block at a time.

The single consumer aspect of the API permits the use of a smaller and/or faster native APIs such as direct thread signaling.

The TimedThreadNotification is initialized to being empty (latch is not set).

Member Function Documentation

◆ try_acquire_for()

bool pw::sync::TimedThreadNotification::try_acquire_for ( chrono::SystemClock::duration  timeout)

Blocks until the specified timeout duration has elapsed or the thread has been notified (i.e. notification latch can be cleared because it was set), whichever comes first.

Clears the notification latch.

Returns true if the thread was notified, meaning the the internal latch was reset successfully.

IMPORTANT: This should only be used by a single consumer thread.

◆ try_acquire_until()

bool pw::sync::TimedThreadNotification::try_acquire_until ( chrono::SystemClock::time_point  deadline)

Blocks until the specified deadline time has been reached the thread has been notified (i.e. notification latch can be cleared because it was set), whichever comes first.

Clears the notification latch.

Returns true if the thread was notified, meaning the the internal latch was reset successfully.

IMPORTANT: This should only be used by a single consumer thread.


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