C/C++ API Reference
Loading...
Searching...
No Matches
pw::sync::TimedMutex Class Reference

Overview

The TimedMutex is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads with timeouts and deadlines, extending the Mutex. It offers exclusive, non-recursive ownership semantics where priority inheritance is used to solve the classic priority-inversion problem. This is thread safe, but NOT IRQ safe.

Warning
In order to support global statically constructed TimedMutexes, the user and/or backend MUST ensure that any initialization required in your environment is done prior to the creation and/or initialization of the native synchronization primitives (e.g. kernel initialization).
Inheritance diagram for pw::sync::TimedMutex:
pw::sync::Mutex

Public Member Functions

 TimedMutex (const TimedMutex &)=delete
 
 TimedMutex (TimedMutex &&)=delete
 
TimedMutexoperator= (const TimedMutex &)=delete
 
TimedMutexoperator= (TimedMutex &&)=delete
 
bool try_lock_for (chrono::SystemClock::duration timeout)
 
bool try_lock_until (chrono::SystemClock::time_point deadline)
 
- Public Member Functions inherited from pw::sync::Mutex
 Mutex (const Mutex &)=delete
 
 Mutex (Mutex &&)=delete
 
Mutexoperator= (const Mutex &)=delete
 
Mutexoperator= (Mutex &&)=delete
 
void lock ()
 
bool try_lock ()
 
void unlock ()
 
native_handle_type native_handle ()
 

Additional Inherited Members

- Public Types inherited from pw::sync::Mutex
using native_handle_type = backend::NativeMutexHandle
 
- Protected Member Functions inherited from pw::sync::Mutex
backend::NativeMutex & native_type ()
 
const backend::NativeMutex & native_type () const
 

Member Function Documentation

◆ try_lock_for()

bool pw::sync::TimedMutex::try_lock_for ( chrono::SystemClock::duration  timeout)

Tries to lock the mutex. Blocks until specified the timeout has elapsed or the lock is acquired, whichever comes first. Returns true if the mutex was successfully acquired.

Precondition
The lock isn't already held by this thread. Recursive locking is undefined behavior.

◆ try_lock_until()

bool pw::sync::TimedMutex::try_lock_until ( chrono::SystemClock::time_point  deadline)

Tries to lock the mutex. Blocks until specified deadline has been reached or the lock is acquired, whichever comes first. Returns true if the mutex was successfully acquired.

Precondition
The lock isn't already held by this thread. Recursive locking is undefined behavior.

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