Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

include/semaphore.h File Reference

Interface: POSIX 1003.1b semaphores for task synchronization. More...

#include <config.h>

Include dependency graph for semaphore.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define EAGAIN   0xffff
 the error code. More...


Typedefs

typedef unsigned char sem_t
 the semaphore data-type. More...


Functions

int sem_init (sem_t *sem, int pshared, unsigned int value)
 Initialize a semaphore. More...

int sem_wait (sem_t *sem)
 Wait for semaphore (blocking). More...

int sem_trywait (sem_t *sem)
 Try a wait for semaphore (non-blocking). More...

int sem_post (sem_t *sem)
 Post a semaphore. More...

int sem_getvalue (sem_t *sem, int *sval)
 Get the semaphore value. More...

int sem_destroy (sem_t *sem)
 We're done with the semaphore, destroy it. More...


Detailed Description

Interface: POSIX 1003.1b semaphores for task synchronization.

Author:
Markus L. Noga <markus@noga.de>

Definition in file semaphore.h.


Define Documentation

#define EAGAIN   0xffff
 

the error code.

Definition at line 45 of file semaphore.h.


Typedef Documentation

typedef unsigned char sem_t
 

the semaphore data-type.

Definition at line 43 of file semaphore.h.

Referenced by sem_destroy(), sem_getvalue(), and sem_init().


Function Documentation

int sem_destroy sem_t   sem [inline]
 

We're done with the semaphore, destroy it.

sem_destroy() destroys a semaphore object, freeing the resources it might hold.

Parameters:
sem  a pointer to the semaphore to be destroyed
Returns:
(always returns 0)
NOTE: No tasks should be waiting on the semaphore at the time sem_destroy is called.

Definition at line 117 of file semaphore.h.

References sem_t.

int sem_getvalue sem_t   sem,
int *    sval
[inline]
 

Get the semaphore value.

Definition at line 102 of file semaphore.h.

References sem_t.

int sem_init sem_t   sem,
int    pshared,
unsigned int    value
[inline]
 

Initialize a semaphore.

sem_init() initializes the semaphore object pointed to by {sem} by setting its internal count to {value}

Parameters:
sem  a pointer to the semaphore to be initialized
value  the initial value for count
pshared  (this argument is ignored)
Returns:
(always 0)

Definition at line 61 of file semaphore.h.

References sem_t.

int sem_post sem_t   sem
 

Post a semaphore.

sem_post() atomically increases the count of the semaphore pointed to by {sem}. This function never blocks and can safely be used in asynchronous signal handlers.

Parameters:
sem  a pointer to the semaphore to be signaled
Returns:
(always returns 0)

int sem_trywait sem_t   sem
 

Try a wait for semaphore (non-blocking).

sem_trywait() is a non-blocking variant of sem_wait(). If the semaphore pointed to by {sem} has non-zero count, the count is atomically decreased and sem_trywait immediately returns 0. If the semaphore count is zero, sem_trywait immediately returns with error EAGAIN.

Parameters:
sem  a pointer to the semaphore on which to attempt a wait
Returns:
0 if decremented the semaphore or EAGAIN if can't
NOTE: this is IRQ handler safe.

int sem_wait sem_t   sem
 

Wait for semaphore (blocking).

sem_wait() suspends the calling task until the semaphore pointed to by {sem} has non-zero count. It then atomically decreases the semaphore count.

Parameters:
sem  a pointer to the semaphore on which to wait
Returns:
0 if wait returned immediately, EAGAIN if task did have to wait for the semaphore.


brickOS is released under the Mozilla Public License.
Original code copyright 1998-2002 by the authors.

Generated on Tue Dec 10 00:09:16 2002 for brickOS Kernel Developer by doxygen 1.2.15