HALFRED  0.4.0
OSCntSem interface

Detailed Description

An interface to a counting semaphore mechanisms provided by the OS. The implementation of the OSCntSem depends on the OS used.


OSCntSem OSCNTSEM_Create (int init, int max)
void OSCNTSEM_Destroy (OSCntSem sem)
bool OSCNTSEM_IsValid (OSCntSem sem)
void OSCNTSEM_Give (OSCntSem sem)
int OSCNTSEM_Take (OSCntSem sem, OSTime timeout)

Function Documentation

OSCntSem OSCNTSEM_Create ( int  init,
int  max 

Creates a new counting semaphore instance. The semaphore implementation depends on the actual OS.

initinitial value of the counting semaphore
maxmaximum value of the counting semaphore
a newly created binary semaphore
void OSCNTSEM_Destroy ( OSCntSem  sem)

Destroys a counting semaphore

semcounting semaphore to destroy
bool OSCNTSEM_IsValid ( OSCntSem  sem)

Checks if a counting semaphore handle represents a valid semaphore. Can be used to test if OSCNTSEM_Create produced a valid semaphore. Beware, that checking handle of a semaphore, that has been destroyed (OSCNRSEM_Destroy) yields undefined behavior. On some ports such handle may still be reported as valid.

semcounting semaphore to check
true if semaphore is valid or false if not
void OSCNTSEM_Give ( OSCntSem  sem)

Increments the value of a counting semaphore.

semcounting semaphore to give
int OSCNTSEM_Take ( OSCntSem  sem,
OSTime  timeout 

Takes the counting semaphore. If the semaphore is not immediately available, the task from which the call was made is blocked. The maximum time spent waiting for the semaphore is specified by the timeout parameter.

semcounting semaphore to take
timeoutmaximum time spent waiting for the semaphore in miliseconds
0 if the semaphore was taken !0 if timeout or error occurred