Main Page   Class Hierarchy   Compound List   File List   Header Files   Compound Members   File Members  

legOS/include/semaphore.h File Reference

POSIX 1003.1b semaphores for process synchronization. More...


Defines

#define EAGAIN
an error code.


Typedefs

typedef unsigned char sem_t
the semaphore type.


Functions

int sem_init (sem_t * sem, int pshared, unsigned int value)
int sem_wait (sem_t * sem)
wait on a semaphore. More...

int sem_trywait (sem_t * sem)
non-blocking check on a semaphore. More...

int sem_post (sem_t * sem)
increase semaphore count. More...

int sem_getvalue (sem_t * sem, int *sval)
int sem_destroy (sem_t * sem)


Detailed Description

POSIX 1003.1b semaphores for process synchronization.

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

Define Documentation

#define EAGAIN ()

an error code.


Typedef Documentation

typedef unsigned char sem_t

the semaphore type.


Function Documentation

int sem_init (sem_t * sem, int pshared, unsigned int value) [inline]

int sem_wait (sem_t * sem)

wait on a semaphore.

Parameters:
sem   a valid semaphore

suspends the calling thread until the semaphore has non-zero count. It then atomically decreases the semaphore count.

implemented with wait_event().

int sem_trywait (sem_t * sem)

non-blocking check on a semaphore.

Parameters:
sem   a valid semaphore

a non-blocking variant of sem_wait. If the semaphore 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.

this is IRQ handler safe.

int sem_post (sem_t * sem)

increase semaphore count.

Parameters:
sem   a valid semaphore

atomically increases the count of the semaphore. This function never blocks and can safely be used in asynchronous signal handlers.

int sem_getvalue (sem_t * sem, int * sval) [inline]

int sem_destroy (sem_t * sem) [inline]

legOS-0.2.4 is released under the Mozilla Public License. Original code copyright 1998-1999 by the authors.