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 |
|
) |
| |
Creates a new counting semaphore instance. The semaphore implementation depends on the actual OS.
- Parameters
-
init | initial value of the counting semaphore |
max | maximum value of the counting semaphore |
- Returns
- a newly created binary semaphore
void OSCNTSEM_Destroy |
( |
OSCntSem |
sem | ) |
|
Destroys a counting semaphore
- Parameters
-
sem | counting 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.
- Parameters
-
sem | counting semaphore to check |
- Returns
- true if semaphore is valid or false if not
void OSCNTSEM_Give |
( |
OSCntSem |
sem | ) |
|
Increments the value of a counting semaphore.
- Parameters
-
sem | counting 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.
- Parameters
-
sem | counting semaphore to take |
timeout | maximum time spent waiting for the semaphore in miliseconds |
- Returns
- 0 if the semaphore was taken !0 if timeout or error occurred