Nut/OS  4.10.3
API Reference
Semaphore

Thread synchronization support. More...

Collaboration diagram for Semaphore:

Data Structures

struct  _SEM
 Semaphore. More...

Typedefs

typedef struct _SEM SEM
 Sempahore type.

Functions

void NutSemInit (SEM *sem, short value)
 Initialize an unnamed semaphore to value.
void NutSemWait (SEM *sem)
 Lock a semaphore.
int NutSemTryWait (SEM *sem)
 Attempt to lock a semaphore without blocking.
void NutSemPost (SEM *sem)
 Unlock a sempahore.
int NutSemDestroy (SEM *sem)
 Free resources allocated for a semaphore.

Detailed Description

Thread synchronization support.

In addition to posting and waiting for events, Threads can use the provided semaphore funxtions to handle a pool of shared resources.


Typedef Documentation

typedef struct _SEM SEM

Sempahore type.

Definition at line 72 of file semaphore.h.


Function Documentation

void NutSemInit ( SEM sem,
short  value 
)

Initialize an unnamed semaphore to value.

Definition at line 83 of file semaphore.c.

References NUTASSERT, _SEM::qhp, and _SEM::value.

Referenced by CANBufferInit().

void NutSemWait ( SEM sem)

Lock a semaphore.

If the semaphore value is currently zero, then the calling thread will not return from the call to sem_wait() the semaphore becomes available

Note:
: Should not be called from interrupt context

Definition at line 95 of file semaphore.c.

Referenced by CANBufferGetMutex(), CANBufferPutMutex(), and NutSemTryWait().

int NutSemTryWait ( SEM sem)

Attempt to lock a semaphore without blocking.

Return zero, if successful, otherwise the sempahore is already locked

Note:
: Should not be called from interrupt context

Definition at line 125 of file semaphore.c.

References NUTASSERT, NutSemWait(), and _SEM::value.

Here is the call graph for this function:

void NutSemPost ( SEM sem)

Unlock a sempahore.

Note:
: Should not be called from interrupt context

Definition at line 109 of file semaphore.c.

References NUTASSERT, NutEventPost(), _SEM::qhp, and _SEM::value.

Referenced by CANBufferGetMutex(), and CANBufferPutMutex().

Here is the call graph for this function:

int NutSemDestroy ( SEM sem)

Free resources allocated for a semaphore.

Return zero, if successful, otherwise there are threads blocked on the sempahore

Definition at line 141 of file semaphore.c.

References NUTASSERT, _SEM::qhp, and SIGNALED.