IntrOS
Loading...
Searching...
No Matches
Semaphore

semaphores (binary, limited, counting) More...

Macros

#define semDirect   ( 0U )
 direct semaphore (producer can't free the semaphore, it can post the semaphore only to the pending task)
#define semBinary   ( 1U )
 binary semaphore
#define semCounting   ( 0U-1 )
 counting semaphore
#define semDefault   semCounting
 default semaphore type
#define OS_SEM(sem, init, ...)
 define and initialize a semaphore object
#define static_SEM(sem, init, ...)
 static alias of OS_SEM()
#define SEM_INIT(init, ...)
 create and initialize a semaphore object
#define SEM_CREATE(init, ...)
 create and initialize a semaphore object
#define SEM_NEW   SEM_CREATE
 alias of SEM_CREATE()

Functions

void sem_init (sem_t *sem, unsigned init, unsigned limit)
 initialize a semaphore object
void sem_reset (sem_t *sem)
 reset the semaphore object and wake up all waiting tasks with 'E_STOPPED' event value
void sem_kill (sem_t *sem)
 alias of sem_reset()
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_tryWait (sem_t *sem)
 alias of sem_take()
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 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 immediately
int sem_wait (sem_t *sem)
 try to lock the semaphore object, wait indefinitely if the semaphore object can't be locked immediately
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_post (sem_t *sem)
 alias of sem_give()
int sem_giveAsync (sem_t *sem)
 Async alias of sem_give().
int sem_release (sem_t *sem, unsigned num)
 try to increment the internal semaphore counter by the value of num
unsigned sem_getValue (sem_t *sem)
 return current value of semaphore

Detailed Description

semaphores (binary, limited, counting)

Macro Definition Documentation

◆ OS_SEM

#define OS_SEM ( sem,
init,
... )
Value:
sem_t sem[] = { _SEM_INIT( init, _VA_SEM(__VA_ARGS__) ) }

define and initialize a semaphore object

Parameters
semname of a pointer to semaphore object
initinitial value of semaphore counter
...limit: (optional) maximum value of semaphore counter
  • semDirect: direct semaphore
  • semBinary: binary semaphore
  • semCounting: counting semaphore (default)
  • otherwise: limited semaphore

◆ static_SEM

#define static_SEM ( sem,
init,
... )
Value:
static sem_t sem[] = { _SEM_INIT( init, _VA_SEM(__VA_ARGS__) ) }

static alias of OS_SEM()

◆ SEM_INIT

#define SEM_INIT ( init,
... )
Value:
_SEM_INIT( init, _VA_SEM(__VA_ARGS__) )

create and initialize a semaphore object

Parameters
initinitial value of semaphore counter
...limit: (optional) maximum value of semaphore counter
  • semDirect: direct semaphore
  • semBinary: binary semaphore
  • semCounting: counting semaphore (default)
  • otherwise: limited semaphore
Returns
semaphore object
Note
use only in 'C' code

◆ SEM_CREATE

#define SEM_CREATE ( init,
... )
Value:
{ SEM_INIT ( init, _VA_SEM(__VA_ARGS__) ) }
#define SEM_INIT(init,...)
create and initialize a semaphore object
Definition ossemaphore.h:135

create and initialize a semaphore object

Parameters
initinitial value of semaphore counter
...limit: (optional) maximum value of semaphore counter
  • semDirect: direct semaphore
  • semBinary: binary semaphore
  • semCounting: counting semaphore (default)
  • otherwise: limited semaphore
Returns
semaphore object as array (id)
Note
use only in 'C' code

Function Documentation

◆ sem_init()

void sem_init ( sem_t * sem,
unsigned init,
unsigned limit )

initialize a semaphore object

Parameters
sempointer to semaphore object
initinitial value of semaphore counter
limitmaximum value of semaphore counter
  • semDirect: direct semaphore
  • semBinary: binary semaphore
  • semCounting: counting semaphore
  • otherwise: limited semaphore

◆ sem_reset()

void sem_reset ( sem_t * sem)

reset the semaphore object and wake up all waiting tasks with 'E_STOPPED' event value

Parameters
sempointer to semaphore object
Note
use only in thread mode

◆ sem_take()

int sem_take ( sem_t * sem)

try to lock the semaphore object, don't wait if the semaphore object can't be locked immediately

Parameters
sempointer to semaphore object
Return values
E_SUCCESSsemaphore object was successfully locked
E_TIMEOUTsemaphore object can't be locked immediately, try again
Note
use Async alias for communication with unmasked interrupt handlers

◆ sem_waitFor()

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 locked immediately

Parameters
sempointer to semaphore object
delayduration of time (maximum number of ticks to wait for lock the semaphore object)
  • IMMEDIATE: don't wait if the semaphore object can't be locked immediately
  • INFINITE: wait indefinitely until the semaphore object has been locked
Return values
E_SUCCESSsemaphore object was successfully locked
E_STOPPEDsemaphore object was reseted before the specified timeout expired
E_TIMEOUTsemaphore object was not locked before the specified timeout expired

◆ sem_waitUntil()

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 immediately

Parameters
sempointer to semaphore object
timetimepoint value
Return values
E_SUCCESSsemaphore object was successfully locked
E_STOPPEDsemaphore object was reseted before the specified timeout expired
E_TIMEOUTsemaphore object was not locked before the specified timeout expired

◆ sem_wait()

int sem_wait ( sem_t * sem)
inline

try to lock the semaphore object, wait indefinitely if the semaphore object can't be locked immediately

Parameters
sempointer to semaphore object
Return values
E_SUCCESSsemaphore object was successfully locked
E_STOPPEDsemaphore object was reseted (unavailable for async version)
Note
use Async alias for communication with unmasked interrupt handlers

◆ sem_give()

int sem_give ( sem_t * sem)

try to unlock the semaphore object, don't wait if the semaphore object can't be unlocked immediately

Parameters
sempointer to semaphore object
Return values
E_SUCCESSsemaphore object was successfully unlocked
E_TIMEOUTsemaphore object can't be unlocked immediately, try again
Note
use Async alias for communication with unmasked interrupt handlers

◆ sem_release()

int sem_release ( sem_t * sem,
unsigned num )

try to increment the internal semaphore counter by the value of num

Parameters
sempointer to semaphore object
numupdate value of semaphore counter
Return values
E_SUCCESSsemaphore counter was successfully updated
E_TIMEOUTsemaphore counter was updated to the limit value

◆ sem_getValue()

unsigned sem_getValue ( sem_t * sem)

return current value of semaphore

Parameters
sempointer to semaphore object
Returns
current value of semaphore