46#define semDirect ( 0U )
47#define semBinary ( 1U )
48#define semCounting ( 0U-1 )
49#define semDefault semCounting
55typedef struct __sem sem_t;
65typedef struct __sem sem_id [];
87#define _SEM_INIT( _init, _limit ) { _OBJ_INIT(), _init < _limit ? _init : _limit, _limit }
99#define _VA_SEM( _limit ) ( (_limit + 0) ? (_limit + 0) : (semDefault) )
113#define OS_SEM( sem, init, ... ) \
114 sem_t sem[] = { _SEM_INIT( init, _VA_SEM(__VA_ARGS__) ) }
117#define static_SEM( sem, init, ... ) \
118 static sem_t sem[] = { _SEM_INIT( init, _VA_SEM(__VA_ARGS__) ) }
136#define SEM_INIT( init, ... ) \
137 _SEM_INIT( init, _VA_SEM(__VA_ARGS__) )
156#define SEM_CREATE( init, ... ) \
157 { SEM_INIT ( init, _VA_SEM(__VA_ARGS__) ) }
179void sem_init( sem_t *sem,
unsigned init,
unsigned limit );
319#if defined(__cplusplus)
341 Semaphore(
const unsigned _init,
const unsigned _limit =
semDefault ): __sem _SEM_INIT(_init, _limit) {}
343 ~Semaphore() { assert(__sem::obj.queue ==
nullptr); }
348 assert(_src.obj.queue ==
nullptr);
374#if __cplusplus >= 201402L
375 using Ptr = std::unique_ptr<Semaphore>;
#define INFINITE
infinite waiting
Definition osbase.h:250
int sem_post(sem_t *sem)
alias of sem_give()
Definition ossemaphore.h:283
int sem_takeAsync(sem_t *sem)
Async alias of sem_take().
int sem_waitFor(sem_t *sem, cnt_t delay)
try to lock the semaphore object, wait for given duration of time if the semaphore object can't be lo...
void sem_init(sem_t *sem, unsigned init, unsigned limit)
initialize a semaphore object
int sem_tryWait(sem_t *sem)
alias of sem_take()
Definition ossemaphore.h:210
#define semDefault
default semaphore type
Definition ossemaphore.h:49
void sem_kill(sem_t *sem)
alias of sem_reset()
Definition ossemaphore.h:192
int sem_take(sem_t *sem)
try to lock the semaphore object, don't wait if the semaphore object can't be locked immediately
int sem_waitUntil(sem_t *sem, cnt_t time)
try to lock the semaphore object, wait until given timepoint if the semaphore object can't be locked ...
#define semDirect
direct semaphore (producer can't free the semaphore, it can post the semaphore only to the pending ta...
Definition ossemaphore.h:46
unsigned sem_getValue(sem_t *sem)
return current value of semaphore
#define semBinary
binary semaphore
Definition ossemaphore.h:47
int sem_wait(sem_t *sem)
try to lock the semaphore object, wait indefinitely if the semaphore object can't be locked immediate...
Definition ossemaphore.h:260
int sem_release(sem_t *sem, unsigned num)
try to increment the internal semaphore counter by the value of num
int sem_waitAsync(sem_t *sem)
Async alias of sem_wait().
int sem_give(sem_t *sem)
try to unlock the semaphore object, don't wait if the semaphore object can't be unlocked immediately
int sem_giveAsync(sem_t *sem)
Async alias of sem_give().
#define semCounting
counting semaphore
Definition ossemaphore.h:48
void sem_reset(sem_t *sem)
reset the semaphore 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 semaphore object
Definition ossemaphore.h:334
int wait()
sem_wait()
Definition ossemaphore.h:362
int take()
sem_take()
Definition ossemaphore.h:356
int waitUntil(const T &_time)
sem_waitUntil()
Definition ossemaphore.h:361
int tryWait()
sem_tryWait()
Definition ossemaphore.h:357
std::unique_ptr< Semaphore > Ptr
result type of Create()
Definition ossemaphore.h:374
int post()
sem_post()
Definition ossemaphore.h:364
static Semaphore Binary(const unsigned _init=0)
create and initialize static binary semaphore
Definition ossemaphore.h:400
unsigned getValue()
sem_getValue()
Definition ossemaphore.h:366
constexpr Semaphore()
constructor, see the constructor parameters of the class
Definition ossemaphore.h:337
void reset()
sem_reset()
Definition ossemaphore.h:354
int takeAsync()
sem_takeAsync()
Definition ossemaphore.h:368
int giveAsync()
sem_giveAsync()
Definition ossemaphore.h:370
void kill()
sem_kill()
Definition ossemaphore.h:355
int waitFor(const T &_delay)
sem_waitFor()
Definition ossemaphore.h:359
int release(unsigned _num)
sem_release()
Definition ossemaphore.h:365
static Semaphore Counting(const unsigned _init=0)
create and initialize static counting semaphore
Definition ossemaphore.h:414
static Semaphore Direct()
create and initialize static direct semaphore
Definition ossemaphore.h:386
int give()
sem_give()
Definition ossemaphore.h:363
int waitAsync()
sem_waitAsync()
Definition ossemaphore.h:369