SEM_pend
2-376
C Interface
Syntax
status = SEM_pend(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_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. In contrast, SEM_pendBinary and SEM_postBinary are
for use with binary semaphores, which can have only an available or
unavailable state. The APIs for binary and counting semaphores cannot
be mixed for a single semaphore.
If the semaphore count is greater than zero (available), SEM_pend
decrements the count and returns TRUE. If the semaphore count is zero
(unavailable), SEM_pend suspends execution of the current task until
SEM_post is called or the timeout expires.
If timeout is SYS_FOREVER, a task stays suspended until SEM_post is
called on this semaphore. If timeout is 0, SEM_pend returns immediately.
If timeout expires (or timeout is 0) before the semaphore is available,
SEM_pend returns FALSE. Otherwise SEM_pend 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_pend if the semaphore count is
0 and timeout is not zero.
Constraints and
Calling Context
❏
SEM_pend can be called from a TSK with any timeout value, but if
called from an HWI or SWI the timeout must be 0.
❏
SEM_pend cannot be called from the program’s main() function.
❏
If you need to call SEM_pend within a TSK_disable/TSK_enable
block, you must use a timeout of 0.
❏
SEM_pend should not be called from within an IDL function. Doing
so prevents analysis tools from gathering run-time information.
See Also
SEM_pend
Wait for a semaphore