semaphore.h
Go to the documentation of this file.
1
6/*
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.0 (the "License"); you may not use this file except in
9 * compliance with the License. You may obtain a copy of the License
10 * at http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14 * the License for the specific language governing rights and
15 * limitations under the License.
16 *
17 * The Original Code is legOS code, released October 17, 1999.
18 *
19 * The Initial Developer of the Original Code is Markus L. Noga.
20 * Portions created by Markus L. Noga are Copyright (C) 1999
21 * Markus L. Noga. All Rights Reserved.
22 *
23 * Contributor(s): Markus L. Noga <markus@noga.de>
24 * Henner Zeller <H.Zeller@acm.org> (sem_timedwait())
25 */
26
27#ifndef __semaphore_h__
28#define __semaphore_h__
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <config.h>
35#include <time.h> /* time_t */
36#include <atomic.h>
37
38#ifdef CONF_SEMAPHORES
39
41//
42// Definitions
43//
45
46typedef atomic_t sem_t;
47
48#define EAGAIN 0xffff
49
51//
52// Functions
53//
55
57
64extern inline int sem_init(sem_t * sem, int pshared, unsigned int value)
65{
66 *sem = (sem_t) value;
67 return 0;
68}
69
71
78extern int sem_wait(sem_t * sem);
79
100extern int sem_timedwait(sem_t * sem,
101 const time_t abs_timeout);
102
104
114extern int sem_trywait(sem_t * sem);
115
117
123extern inline int sem_post(sem_t * sem)
124{
125 atomic_inc(sem);
126 return 0;
127}
128
129//
131//
132extern inline int sem_getvalue(sem_t * sem, int *sval)
133{
134 *sval = *sem;
135 return 0;
136}
137
139
147extern inline int sem_destroy(sem_t * sem)
148{
149 return 0;
150}
151
152#endif // CONF_SEMAPHORES
153
154#ifdef __cplusplus
155}
156#endif
157
158#endif // __semaphore_h__
void atomic_inc(atomic_t *counter)
increment atomic counter without interruption.
Interface: critical section management.
volatile unsigned char atomic_t
The data type that allows for atomic count operations.
Definition atomic.h:43
kernel configuration file
int sem_post(sem_t *sem)
Post a semaphore.
Definition semaphore.h:123
int sem_timedwait(sem_t *sem, const time_t abs_timeout)
Wait for semaphore (blocking with timeout).
int sem_trywait(sem_t *sem)
Try a wait for semaphore (non-blocking)
int sem_init(sem_t *sem, int pshared, unsigned int value)
Initialize a semaphore.
Definition semaphore.h:64
int sem_destroy(sem_t *sem)
We're done with the semaphore, destroy it.
Definition semaphore.h:147
int sem_getvalue(sem_t *sem, int *sval)
Get the semaphore value.
Definition semaphore.h:132
int sem_wait(sem_t *sem)
Wait for semaphore (blocking)
atomic_t sem_t
the semaphore data-type
Definition semaphore.h:46
Interface: Time-related data and types.
unsigned long time_t
time type
Definition time.h:50

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

Generated for brickOS Kernel Developer by doxygen 1.9.8