SEM_pendBinary
Application Program Interface
2-377
C Interface
Syntax
status = SEM_pendBinary(sem, timeout);
Parameters
SEM_Handle sem;
/* semaphore object handle */
Uns
timeout;
/* return after this many system clock ticks */
Return Value
Bool
status;
/* TRUE if successful, FALSE if timeout */
Description
SEM_pendBinary and SEM_postBinary are for use with binary
semaphores. These are semaphores that can have only two states:
available and unavailable. They can be used to share a single resource
between tasks. They can also be used for a basic signaling mechanism,
where the semaphore can be posted multiple times and a subsequent
call to SEM_pendBinary clears the count and returns. Binary
semaphores do not keep track of the count; they simply track whether the
semaphore has been posted or not.
In contrast, SEM_pend and SEM_post are for use with counting
semaphores, which keep track of the number of times the semaphore has
been posted. This is useful, for example, if you have a group of resources
that are shared between tasks. The APIs for binary and counting
semaphores cannot be mixed for a single semaphore.
If the semaphore count is non-zero (available), SEM_pendBinary sets
the count to zero (unavailable) and returns TRUE.
If the semaphore count is zero (unavailable), SEM_pendBinary suspends
execution of this task until SEM_post is called or the timeout expires.
If timeout is SYS_FOREVER, a task remains suspended until
SEM_postBinary is called on this semaphore. If timeout is 0,
SEM_pendBinary returns immediately.
If timeout expires (or timeout is 0) before the semaphore is available,
SEM_pendBinary returns FALSE. Otherwise SEM_pendBinary returns
TRUE.
If timeout is not equal to SYS_FOREVER or 0, the task suspension time
can be up to 1 system clock tick less than timeout due to granularity in
system timekeeping.
A task switch occurs when calling SEM_pendBinary if the semaphore
count is 0 and timeout is not zero.
Constraints and
Calling Context
❏
This API can be called from a TSK with any timeout value, but if
called from an HWI or SWI the timeout must be 0.
SEM_pendBinary
Wait for a binary semaphore