32#ifndef __STATEOS_CND_H
33#define __STATEOS_CND_H
47#define cndOne ( false )
48#define cndAll ( true )
54typedef struct __cnd cnd_t;
61typedef struct __cnd cnd_id [];
77#define _CND_INIT() { _OBJ_INIT() }
85#define OS_CND( cnd ) \
86 cnd_t cnd[] = { _CND_INIT() }
89#define static_CND( cnd ) \
90 static cnd_t cnd[] = { _CND_INIT() }
114#define CND_CREATE() \
198int cnd_waitFor( cnd_t *cnd, mtx_t *mtx, cnt_t delay );
251void cnd_give( cnd_t *cnd,
bool all );
285#if defined(__cplusplus) && (__cplusplus >= 201103L) && !defined(__STATEOS_STDCXX)
303 assert(_src.obj.queue ==
nullptr);
323 template<
typename T,
typename F>
324 int waitFor ( mtx_t& _mtx,
const T& _delay, F _stopWaiting )
331 template<
typename T,
typename F>
332 int waitUntil( mtx_t& _mtx,
const T& _time, F _stopWaiting )
336 if (result ==
E_TIMEOUT && _stopWaiting())
342 int wait ( mtx_t& _mtx, F _stopWaiting )
345 while (!_stopWaiting() && (result =
wait(_mtx)) ==
E_SUCCESS);
349#if __cplusplus >= 201402L
350 using Ptr = std::unique_ptr<ConditionVariable>;
368 cnd->__cnd::obj.res = cnd;
#define INFINITE
infinite waiting
Definition osbase.h:261
@ E_TIMEOUT
process was released as a result of the end of the timer countdown
Definition osbase.h:150
@ E_SUCCESS
process was released as a result of taking the supervising object
Definition osbase.h:146
cnt_t sys_time(void)
return current value of system counter
void cnd_notifyAll(cnd_t *cnd)
signal all tasks waiting on the condition variable
Definition osconditionvariable.h:276
void cnd_delete(cnd_t *cnd)
alias of cnd_destroy()
Definition osconditionvariable.h:175
int cnd_wait(cnd_t *cnd, mtx_t *mtx)
wait indefinitely on the condition variable releasing the currently owned mutex, and finally lock the...
Definition osconditionvariable.h:236
void cnd_init(cnd_t *cnd)
initialize a condition variable object
void cnd_reset(cnd_t *cnd)
reset the condition variable object and wake up all waiting tasks with 'E_STOPPED' event value
#define cndAll
notify all tasks (broadcast)
Definition osconditionvariable.h:48
void cnd_kill(cnd_t *cnd)
alias of cnd_reset()
Definition osconditionvariable.h:161
void cnd_destroy(cnd_t *cnd)
reset the condition variable object, wake up all waiting tasks with 'E_DELETED' event value and free ...
cnd_t * cnd_new(void)
alias of cnd_create()
Definition osconditionvariable.h:147
void cnd_notifyOne(cnd_t *cnd)
signal one task waiting on the condition variable
Definition osconditionvariable.h:265
cnd_t * cnd_create(void)
create and initialize a new condition variable object
int cnd_waitUntil(cnd_t *cnd, mtx_t *mtx, cnt_t time)
wait until given timepoint on the condition variable releasing the currently owned mutex,...
int cnd_waitFor(cnd_t *cnd, mtx_t *mtx, cnt_t delay)
wait for given duration of time on the condition variable releasing the currently owned mutex,...
void cnd_giveISR(cnd_t *cnd, bool all)
ISR alias of cnd_give().
Definition osconditionvariable.h:254
void cnd_give(cnd_t *cnd, bool all)
signal one or all tasks that are waiting on the condition variable
#define cndOne
notify one task
Definition osconditionvariable.h:47
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:109
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:116
create and initialize a condition variable object
Definition osconditionvariable.h:292
void notifyOne()
cnd_notifyOne()
Definition osconditionvariable.h:319
int wait(mtx_t &_mtx)
cnd_wait()
Definition osconditionvariable.h:316
static Ptr Create()
create and initialize dynamic object with manageable resources
Definition osconditionvariable.h:363
void notifyAll()
cnd_notifyAll()
Definition osconditionvariable.h:320
std::unique_ptr< ConditionVariable > Ptr
result type of Create()
Definition osconditionvariable.h:349
void reset()
cnd_reset()
Definition osconditionvariable.h:309
void kill()
cnd_kill()
Definition osconditionvariable.h:310
void giveISR(bool _all=cndAll)
cnd_giveISR()
Definition osconditionvariable.h:318
int waitUntil(mtx_t &_mtx, const T &_time)
cnd_waitUntil()
Definition osconditionvariable.h:315
void destroy()
cnd_destroy()
Definition osconditionvariable.h:311
void give(bool _all=cndAll)
cnd_give()
Definition osconditionvariable.h:317
int waitFor(mtx_t &_mtx, const T &_delay)
cnd_waitFor()
Definition osconditionvariable.h:313
constexpr ConditionVariable()
constructor, see the constructor parameters of the class
Definition osconditionvariable.h:295