Semaphore Support
2-11
Operating System Abstraction API
Delete Semaphore
SemDelete
Syntax
void SemDelete( HANDLE hSem );
Parameter(s)
hSem
Handle to Semaphore
Return Value
nothing
Description
Deletes the semaphore object and frees related memory.
Any task currently waiting on this semaphore is blocked forever – even if it orig-
inally specified a timeout to SemPend(). With a little care in programming, this
will not occur.
Wait for a Semaphore
SemPend
Syntax
int SemPend( HANDLE hSem, UINT32 Timeout );
Parameter(s)
hSem
Handle to Semaphore
Timeout
Max time to wait (in milliseconds)
Return Value
1 if the semaphore was obtained, and 0 if not
Description
This function is used to wait on a semaphore.
If the semaphore count is greater than 0, the semaphore count is decrement
and this function immediately returns.
If the semaphore count is zero, the task is placed on a waiting list for the sema-
phore and blocked. If the semaphore becomes available in the time period
specified in Timeout, the function returns. However the function returns re-
gardless once the timeout has expired. A timeout value of 0 always returns
without blocking or yielding. A timeout value of SEM_FOREVER causes the
caller to wait on the semaphore without timeout.
The waiting list is “first in, first out”, without regard to priority. Thus semaphores
can be used to round-robin task threads at different priority levels.
Calling this function may cause a task switch (unless called with Timeout set
to 0).