46#define RDR_LIMIT ( 0U-1 )
52typedef struct __rwl rwl_t;
63typedef struct __rwl rwl_id [];
79#define _RWL_INIT() { _OBJ_INIT(), NULL, false, 0 }
87#define OS_RWL( rwl ) \
88 rwl_t rwl[] = { _RWL_INIT() }
91#define static_RWL( rwl ) \
92 static rwl_t rwl[] = { _RWL_INIT() }
116#define RWL_CREATE() \
305#if defined(__cplusplus)
312struct RWLock :
public __rwl
316 RWLock(): __rwl _RWL_INIT() {}
318 ~RWLock() { assert(__rwl::write ==
false && __rwl::count == 0); }
323 assert(_src.write ==
false && _src.count == 0 && _src.obj.queue ==
nullptr && _src.queue ==
nullptr);
367 int result = lck_->lockRead();
386 bool ownsLock()
const {
return lck_ !=
nullptr; }
389 operator bool()
const {
return ownsLock(); }
412 int result = lck_->lockWrite();
431 bool ownsLock()
const {
return lck_ !=
nullptr; }
434 operator bool()
const {
return ownsLock(); }
#define INFINITE
infinite waiting
Definition osbase.h:250
@ E_SUCCESS
process was released as a result of taking the supervising object
Definition osbase.h:150
@ E_STOPPED
process was released as a result of reset the supervising object
Definition osbase.h:152
void rwl_unlockRead(rwl_t *rwl)
alias of rwl_giveRead()
Definition osrwlock.h:221
int rwl_waitReadFor(rwl_t *rwl, cnt_t delay)
try to lock the reader, wait for given duration of time if the reader can't be locked immediately
int rwl_waitWriteUntil(rwl_t *rwl, cnt_t time)
try to lock the writer, wait until given timepoint if the writer can't be locked immediately
int rwl_lockRead(rwl_t *rwl)
alias of rwl_waitRead()
Definition osrwlock.h:209
int rwl_tryLockWrite(rwl_t *rwl)
alias of rwl_takeWrite()
Definition osrwlock.h:237
void rwl_unlockWrite(rwl_t *rwl)
alias of rwl_giveWrite()
Definition osrwlock.h:296
int rwl_waitRead(rwl_t *rwl)
try to lock the reader, wait indefinitely if the reader can't be locked immediately
Definition osrwlock.h:205
void rwl_giveWrite(rwl_t *rwl)
unlock the writer
int rwl_lockWrite(rwl_t *rwl)
alias of rwl_waitWrite()
Definition osrwlock.h:284
int rwl_waitWriteFor(rwl_t *rwl, cnt_t delay)
try to lock the writer, wait for given duration of time if the writer can't be locked immediately
int rwl_waitWrite(rwl_t *rwl)
try to lock the writer, wait indefinitely if the writer can't be locked immediately
Definition osrwlock.h:280
void rwl_giveRead(rwl_t *rwl)
unlock the reader
int rwl_waitReadUntil(rwl_t *rwl, cnt_t time)
try to lock the reader, wait until given timepoint if the reader can't be locked immediately
void rwl_kill(rwl_t *rwl)
alias of rwl_reset()
Definition osrwlock.h:146
void rwl_init(rwl_t *rwl)
initialize a read/write lock object
int rwl_takeRead(rwl_t *rwl)
try to lock the reader, don't wait if the reader can't be locked immediately
int rwl_tryLockRead(rwl_t *rwl)
alias of rwl_takeRead()
Definition osrwlock.h:162
int rwl_takeWrite(rwl_t *rwl)
try to lock the writer, don't wait if the writer can't be locked immediately
void rwl_reset(rwl_t *rwl)
reset the read/write lock object and wake up all waiting tasks with 'E_STOPPED' event value
static constexpr rep until(const std::chrono::time_point< Clock, _Duration > &_time)
time point in ticks, rounded up to whole ticks (only a time point of this clock)
Definition osclock.h:109
static constexpr rep count(const std::chrono::duration< _Rep, _Period > &_delay)
delay in ticks, rounded up to whole ticks; negative delay: IMMEDIATE, delay out of range: INFINITE
Definition osclock.h:102
create and initialize a read/write lock object
Definition osrwlock.h:312
int waitWrite()
rwl_waitWrite()
Definition osrwlock.h:347
int lockWrite()
rwl_lockWrite()
Definition osrwlock.h:348
int tryLockRead()
rwl_tryLockRead()
Definition osrwlock.h:332
void reset()
rwl_reset()
Definition osrwlock.h:329
int tryLockWrite()
rwl_tryLockWrite()
Definition osrwlock.h:342
int waitWriteFor(const T &_delay)
rwl_waitWriteFor()
Definition osrwlock.h:344
int waitRead()
rwl_waitRead()
Definition osrwlock.h:337
void giveWrite()
rwl_giveWrite()
Definition osrwlock.h:349
int lockRead()
rwl_lockRead()
Definition osrwlock.h:338
int waitReadUntil(const T &_time)
rwl_waitReadUntil()
Definition osrwlock.h:336
void unlockRead()
rwl_unlockRead()
Definition osrwlock.h:340
int waitWriteUntil(const T &_time)
rwl_waitWriteUntil()
Definition osrwlock.h:346
void kill()
rwl_kill()
Definition osrwlock.h:330
void giveRead()
rwl_giveRead()
Definition osrwlock.h:339
int takeRead()
rwl_takeRead()
Definition osrwlock.h:331
constexpr RWLock()
constructor, see the constructor parameters of the class
Definition osrwlock.h:315
int takeWrite()
rwl_takeWrite()
Definition osrwlock.h:341
void unlockWrite()
rwl_unlockWrite()
Definition osrwlock.h:350
int waitReadFor(const T &_delay)
rwl_waitReadFor()
Definition osrwlock.h:334
create and initialize a read guard object
Definition osrwlock.h:361
bool ownsLock() const
true: the lock is held by the guard; false: the lock was reset while waiting (or the guard was moved)
Definition osrwlock.h:385
ReadLock(RWLock &_rwl)
constructor, see the constructor parameters of the class
Definition osrwlock.h:364
create and initialize a write guard object
Definition osrwlock.h:406
bool ownsLock() const
true: the lock is held by the guard; false: the lock was reset while waiting (or the guard was moved)
Definition osrwlock.h:430
WriteLock(RWLock &_rwl)
constructor, see the constructor parameters of the class
Definition osrwlock.h:409