distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
Semaphore C-API

Semaphore-related C-API of distortos. More...

Collaboration diagram for Semaphore C-API:

Classes

struct  distortos_Semaphore
 C-API equivalent of distortos::Semaphore. More...
 

Macros

#define DISTORTOS_SEMAPHORE_INITIALIZER(self, value, maxValue)   {ESTD_INTRUSIVELIST_INITIALIZER((self).blockedList), (value) < (maxValue) ? (value) : (maxValue), (maxValue)}
 Initializer for distortos_Semaphore. More...
 
#define DISTORTOS_SEMAPHORE_CONSTRUCT_1(name, value, maxValue)   struct distortos_Semaphore name = DISTORTOS_SEMAPHORE_INITIALIZER(name, value, maxValue)
 C-API equivalent of distortos::Semaphore's constructor. More...
 
#define DISTORTOS_SEMAPHORE_CONSTRUCT(name, value)   DISTORTOS_SEMAPHORE_CONSTRUCT_1(name, value, UINT_MAX)
 C-API equivalent of distortos::Semaphore's constructor, maxValue == UINT_MAX. More...
 

Functions

int distortos_Semaphore_construct_1 (struct distortos_Semaphore *semaphore, unsigned int value, unsigned int maxValue)
 C-API equivalent of distortos::Semaphore's constructor. More...
 
static int distortos_Semaphore_construct (struct distortos_Semaphore *const semaphore, const unsigned int value)
 C-API equivalent of distortos::Semaphore's constructor, maxValue == UINT_MAX. More...
 
int distortos_Semaphore_destruct (struct distortos_Semaphore *semaphore)
 C-API equivalent of distortos::Semaphore's destructor. More...
 
int distortos_Semaphore_getMaxValue (const struct distortos_Semaphore *semaphore, unsigned int *maxValue)
 C-API equivalent of distortos::Semaphore::getMaxValue() More...
 
int distortos_Semaphore_getValue (const struct distortos_Semaphore *semaphore, unsigned int *value)
 C-API equivalent of distortos::Semaphore::getValue() More...
 
int distortos_Semaphore_post (struct distortos_Semaphore *semaphore)
 C-API equivalent of distortos::Semaphore::post() More...
 
int distortos_Semaphore_tryWait (struct distortos_Semaphore *semaphore)
 C-API equivalent of distortos::Semaphore::tryWait() More...
 
int distortos_Semaphore_tryWaitFor (struct distortos_Semaphore *semaphore, int64_t duration)
 C-API equivalent of distortos::Semaphore::tryWaitFor() More...
 
int distortos_Semaphore_tryWaitUntil (struct distortos_Semaphore *semaphore, int64_t timePoint)
 C-API equivalent of distortos::Semaphore::tryWaitUntil() More...
 
int distortos_Semaphore_wait (struct distortos_Semaphore *semaphore)
 C-API equivalent of distortos::Semaphore::wait() More...
 

Detailed Description

Semaphore-related C-API of distortos.

Macro Definition Documentation

◆ DISTORTOS_SEMAPHORE_CONSTRUCT

#define DISTORTOS_SEMAPHORE_CONSTRUCT (   name,
  value 
)    DISTORTOS_SEMAPHORE_CONSTRUCT_1(name, value, UINT_MAX)

C-API equivalent of distortos::Semaphore's constructor, maxValue == UINT_MAX.

See also
distortos::Semaphore::Semaphore()
Parameters
[in]nameis the name of the object that will be instantiated
[in]valueis the initial value of the semaphore, if this value is greater than UINT_MAX, it will be truncated

◆ DISTORTOS_SEMAPHORE_CONSTRUCT_1

#define DISTORTOS_SEMAPHORE_CONSTRUCT_1 (   name,
  value,
  maxValue 
)    struct distortos_Semaphore name = DISTORTOS_SEMAPHORE_INITIALIZER(name, value, maxValue)

C-API equivalent of distortos::Semaphore's constructor.

See also
distortos::Semaphore::Semaphore()
Parameters
[in]nameis the name of the object that will be instantiated
[in]valueis the initial value of the semaphore, if this value is greater than maxValue, it will be truncated
[in]maxValueis the max value of the semaphore before post() returns EOVERFLOW

◆ DISTORTOS_SEMAPHORE_INITIALIZER

#define DISTORTOS_SEMAPHORE_INITIALIZER (   self,
  value,
  maxValue 
)    {ESTD_INTRUSIVELIST_INITIALIZER((self).blockedList), (value) < (maxValue) ? (value) : (maxValue), (maxValue)}

Initializer for distortos_Semaphore.

See also
distortos::Semaphore::Semaphore()
Parameters
[in]selfis an equivalent of this hidden argument
[in]valueis the initial value of the semaphore, if this value is greater than maxValue, it will be truncated
[in]maxValueis the max value of the semaphore before post() returns EOVERFLOW

Function Documentation

◆ distortos_Semaphore_construct()

static int distortos_Semaphore_construct ( struct distortos_Semaphore *const  semaphore,
const unsigned int  value 
)
inlinestatic

C-API equivalent of distortos::Semaphore's constructor, maxValue == UINT_MAX.

Similar to sem_init() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_init.html#

See also
distortos::Semaphore::Semaphore()
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
[in]valueis the initial value of the semaphore, if this value is greater than UINT_MAX, it will be truncated
Returns
0 on success, error code otherwise:
  • EINVAL - semaphore is invalid;
Here is the call graph for this function:

◆ distortos_Semaphore_construct_1()

int distortos_Semaphore_construct_1 ( struct distortos_Semaphore semaphore,
unsigned int  value,
unsigned int  maxValue 
)

C-API equivalent of distortos::Semaphore's constructor.

Similar to sem_init() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_init.html#

See also
distortos::Semaphore::Semaphore()
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
[in]valueis the initial value of the semaphore, if this value is greater than maxValue, it will be truncated
[in]maxValueis the max value of the semaphore before post() returns EOVERFLOW
Returns
0 on success, error code otherwise:
  • EINVAL - semaphore is invalid;

◆ distortos_Semaphore_destruct()

int distortos_Semaphore_destruct ( struct distortos_Semaphore semaphore)

C-API equivalent of distortos::Semaphore's destructor.

Similar to sem_destroy() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_destroy.html#

See also
distortos::Semaphore::~Semaphore()
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
Returns
0 on success, error code otherwise:
  • EINVAL - semaphore is invalid;
Here is the call graph for this function:

◆ distortos_Semaphore_getMaxValue()

int distortos_Semaphore_getMaxValue ( const struct distortos_Semaphore semaphore,
unsigned int *  maxValue 
)

C-API equivalent of distortos::Semaphore::getMaxValue()

See also
distortos::Semaphore::getMaxValue()
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
[out]maxValueis a pointer to variable into which semaphore's max value will be written
Returns
0 on success, error code otherwise:
  • EINVAL - semaphore and/or maxValue are invalid;
Here is the call graph for this function:

◆ distortos_Semaphore_getValue()

int distortos_Semaphore_getValue ( const struct distortos_Semaphore semaphore,
unsigned int *  value 
)

C-API equivalent of distortos::Semaphore::getValue()

Similar to sem_getvalue() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_getvalue.html#

See also
distortos::Semaphore::getValue()
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
[out]valueis a pointer to variable into which semaphore's value will be written
Returns
0 on success, error code otherwise:
  • EINVAL - semaphore and/or value are invalid;
Here is the call graph for this function:

◆ distortos_Semaphore_post()

int distortos_Semaphore_post ( struct distortos_Semaphore semaphore)

C-API equivalent of distortos::Semaphore::post()

Similar to sem_post() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_post.html#

See also
distortos::Semaphore::post()
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
Returns
0 on success, error code otherwise:
  • EINVAL - semaphore value is invalid;
  • EOVERFLOW - the maximum allowable value for a semaphore would be exceeded;
Here is the call graph for this function:

◆ distortos_Semaphore_tryWait()

int distortos_Semaphore_tryWait ( struct distortos_Semaphore semaphore)

C-API equivalent of distortos::Semaphore::tryWait()

Similar to sem_trywait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_trywait.html#

See also
distortos::Semaphore::tryWait()
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
Returns
0 on success, error code otherwise:
  • EAGAIN - semaphore was already locked, so it cannot be immediately locked by the distortos_Semaphore_tryWait() operation;
  • EINVAL - semaphore value is invalid;
Here is the call graph for this function:

◆ distortos_Semaphore_tryWaitFor()

int distortos_Semaphore_tryWaitFor ( struct distortos_Semaphore semaphore,
int64_t  duration 
)

C-API equivalent of distortos::Semaphore::tryWaitFor()

Similar to sem_timedwait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_timedwait.html#

See also
distortos::Semaphore::tryWaitFor()
Warning
This function must not be called from interrupt context!
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
[in]durationis the duration in system ticks after which the wait will be terminated without locking the semaphore
Returns
0 on success, error code otherwise:
  • EINTR - the wait was interrupted by an unmasked, caught signal;
  • EINVAL - semaphore value is invalid;
  • ETIMEDOUT - the semaphore could not be locked before the specified timeout expired;
Here is the call graph for this function:

◆ distortos_Semaphore_tryWaitUntil()

int distortos_Semaphore_tryWaitUntil ( struct distortos_Semaphore semaphore,
int64_t  timePoint 
)

C-API equivalent of distortos::Semaphore::tryWaitUntil()

Similar to sem_timedwait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_timedwait.html#

See also
distortos::Semaphore::tryWaitUntil()
Warning
This function must not be called from interrupt context!
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
[in]timePointis the time point in system ticks at which the wait will be terminated without locking the semaphore
Returns
0 on success, error code otherwise:
  • EINTR - the wait was interrupted by an unmasked, caught signal;
  • EINVAL - semaphore value is invalid;
  • ETIMEDOUT - the semaphore could not be locked before the specified timeout expired;
Here is the call graph for this function:

◆ distortos_Semaphore_wait()

int distortos_Semaphore_wait ( struct distortos_Semaphore semaphore)

C-API equivalent of distortos::Semaphore::wait()

Similar to sem_wait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_trywait.html#

See also
distortos::Semaphore::wait()
Warning
This function must not be called from interrupt context!
Parameters
[in]semaphoreis a pointer to distortos_Semaphore object
Returns
0 on success, error code otherwise:
  • EINTR - the wait was interrupted by an unmasked, caught signal;
  • EINVAL - semaphore value is invalid;
Here is the call graph for this function: