23 #ifndef ETCPAL_CPP_LOCK_H_
24 #define ETCPAL_CPP_LOCK_H_
28 #include "etcpal/lock.h"
100 bool TryLock(
int timeout_ms = 0);
218 bool TryWait(
int timeout_ms = 0);
503 bool TryWait(
int timeout_ms = 0);
627 inline void MutexGuard::GetLock()
630 ETCPAL_THROW(std::runtime_error(
"etcpal_mutex_lock failed."));
686 inline void ReadGuard::GetReadLock()
689 ETCPAL_THROW(std::runtime_error(
"etcpal_rwlock_readlock failed."));
745 inline void WriteGuard::GetWriteLock()
748 ETCPAL_THROW(std::runtime_error(
"etcpal_rwlock_writelock failed."));
Lock guard around a mutex.
Definition: lock.h:590
~MutexGuard()
Release the lock upon going out-of-scope.
Definition: lock.h:622
MutexGuard(Mutex &mutex)
Lock an etcpal::Mutex.
Definition: lock.h:609
A wrapper class for the EtcPal mutex type.
Definition: lock.h:89
~Mutex()
Destroy the mutex.
Definition: lock.h:116
Mutex()
Create a new mutex.
Definition: lock.h:110
bool Lock()
Lock the mutex.
Definition: lock.h:123
bool TryLock(int timeout_ms=0)
Attempt to lock the mutex.
Definition: lock.h:139
void Unlock()
Unlock the mutex.
Definition: lock.h:147
etcpal_mutex_t & get()
Get a reference to the underlying etcpal_mutex_t type.
Definition: lock.h:153
Read lock guard around a read-write lock.
Definition: lock.h:649
ReadGuard(RwLock &rwlock)
Lock an etcpal::RwLock for reading.
Definition: lock.h:668
~ReadGuard()
Release the read lock upon going out-of-scope.
Definition: lock.h:681
A wrapper class for the EtcPal read-write lock type.
Definition: lock.h:352
bool WriteLock()
Access the read-write lock for writing.
Definition: lock.h:421
etcpal_rwlock_t & get()
Get a reference to the underlying etcpal_rwlock_t type.
Definition: lock.h:451
void ReadUnlock()
Release a read lock on the read-write lock.
Definition: lock.h:414
~RwLock()
Destroy the read-write lock.
Definition: lock.h:383
void WriteUnlock()
Release a write lock on the read-write lock.
Definition: lock.h:445
bool TryReadLock(int timeout_ms=0)
Try to access the read-write lock for reading.
Definition: lock.h:406
RwLock()
Create a new read-write lock.
Definition: lock.h:377
bool TryWriteLock(int timeout_ms=0)
Try to access the read-write lock for writing.
Definition: lock.h:437
bool ReadLock()
Access the read-write lock for reading.
Definition: lock.h:390
A wrapper class for the EtcPal counting semaphore type.
Definition: lock.h:488
static constexpr unsigned int kDefaultMaxCount
The default value used for the semaphore's max_count.
Definition: lock.h:492
etcpal_sem_t & get()
Get a reference to the underlying etcpal_sem_t type.
Definition: lock.h:565
bool PostFromIsr()
Post the semaphore from an interrupt context.
Definition: lock.h:559
~Semaphore()
Destroy the semaphore.
Definition: lock.h:520
bool Post()
Post the semaphore.
Definition: lock.h:549
Semaphore(unsigned int initial_count=0, unsigned int max_count=kDefaultMaxCount)
Create a new semaphore.
Definition: lock.h:514
bool TryWait(int timeout_ms=0)
Wait for the semaphore until either it is received or a timeout expires.
Definition: lock.h:541
bool Wait()
Wait for the semaphore.
Definition: lock.h:527
A wrapper class for the EtcPal signal type.
Definition: lock.h:207
~Signal()
Destroy the signal.
Definition: lock.h:235
Signal()
Create a new signal.
Definition: lock.h:229
etcpal_signal_t & get()
Get a reference to the underlying etcpal_signal_t type.
Definition: lock.h:280
void Notify()
Notify those waiting on the signal.
Definition: lock.h:264
bool TryWait(int timeout_ms=0)
Wait for the signal until either it is received or a timeout expires.
Definition: lock.h:256
void NotifyFromIsr()
Notify those waiting on the signal from an interrupt context.
Definition: lock.h:274
bool Wait()
Wait for the signal.
Definition: lock.h:242
Write lock guard around a read-write lock.
Definition: lock.h:708
WriteGuard(RwLock &rwlock)
Lock an etcpal::RwLock for writing.
Definition: lock.h:727
~WriteGuard()
Release the write lock upon going out-of-scope.
Definition: lock.h:740
Common definitions used by EtcPal C++ wrappers.
void etcpal_mutex_destroy(etcpal_mutex_t *id)
Destroy a mutex object.
PLATFORM_DEFINED etcpal_mutex_t
The mutex identifier.
Definition: lock.dox:93
void etcpal_mutex_unlock(etcpal_mutex_t *id)
Unlock a mutex.
bool etcpal_mutex_create(etcpal_mutex_t *id)
Create a new mutex.
bool etcpal_mutex_timed_lock(etcpal_mutex_t *id, int timeout_ms)
Try to lock a mutex, giving up after a timeout.
bool etcpal_mutex_lock(etcpal_mutex_t *id)
Lock a mutex.
bool etcpal_rwlock_timed_writelock(etcpal_rwlock_t *id, int timeout_ms)
Try to access a read-write lock for writing, giving up after a timeout.
void etcpal_rwlock_destroy(etcpal_rwlock_t *id)
Destroy a read-write lock object.
void etcpal_rwlock_readunlock(etcpal_rwlock_t *id)
Release a read lock on a read-write lock object.
PLATFORM_DEFINED etcpal_rwlock_t
The read-write lock identifier.
Definition: lock.dox:417
bool etcpal_rwlock_create(etcpal_rwlock_t *id)
Create a new read-write lock.
void etcpal_rwlock_writeunlock(etcpal_rwlock_t *id)
Release a write lock on a read-write lock object.
bool etcpal_rwlock_readlock(etcpal_rwlock_t *id)
Access a read-write lock for reading.
bool etcpal_rwlock_writelock(etcpal_rwlock_t *id)
Access a read-write lock for writing.
bool etcpal_rwlock_timed_readlock(etcpal_rwlock_t *id, int timeout_ms)
Try to access a read-write lock for reading, giving up after a timeout.
bool etcpal_sem_create(etcpal_sem_t *id, unsigned int initial_count, unsigned int max_count)
Create a new counting semaphore.
PLATFORM_DEFINED etcpal_sem_t
The semaphore identifier.
Definition: lock.dox:610
bool etcpal_sem_post(etcpal_sem_t *id)
Post a semaphore.
void etcpal_sem_destroy(etcpal_sem_t *id)
Destroy a semaphore object.
bool etcpal_sem_post_from_isr(etcpal_sem_t *id)
Post a semaphore from an interrupt context.
bool etcpal_sem_timed_wait(etcpal_sem_t *id, int timeout_ms)
Wait for a semaphore, giving up after a timeout.
bool etcpal_sem_wait(etcpal_sem_t *id)
Wait for a semaphore.
bool etcpal_signal_wait(etcpal_signal_t *id)
Wait for a signal.
bool etcpal_signal_create(etcpal_signal_t *id)
Create a new signal.
void etcpal_signal_destroy(etcpal_signal_t *id)
Destroy a signal object.
bool etcpal_signal_timed_wait(etcpal_signal_t *id, int timeout_ms)
Wait for a signal, giving up after a timeout.
PLATFORM_DEFINED etcpal_signal_t
The signal identifier.
Definition: lock.dox:243
void etcpal_signal_post_from_isr(etcpal_signal_t *id)
Post a signal from an interrupt context.
void etcpal_signal_post(etcpal_signal_t *id)
Post a signal.