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
31 extern "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 
46 typedef atomic_t sem_t;
47 
48 #define EAGAIN 0xffff
49 
50 
51 //
52 // Functions
53 //
55 
57 
64 extern inline int sem_init(sem_t * sem, int pshared, unsigned int value)
65 {
66  *sem = (sem_t) value;
67  return 0;
68 }
69 
71 
78 extern int sem_wait(sem_t * sem);
79 
100 extern int sem_timedwait(sem_t * sem,
101  const time_t abs_timeout);
102 
104 
114 extern int sem_trywait(sem_t * sem);
115 
117 
123 extern inline int sem_post(sem_t * sem)
124 {
125  atomic_inc(sem);
126  return 0;
127 }
128 
129 //
131 //
132 extern inline int sem_getvalue(sem_t * sem, int *sval)
133 {
134  *sval = *sem;
135  return 0;
136 }
137 
139 
147 extern 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__

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

Generated on Sat Mar 15 2014 11:28:19 for brickOS C by doxygen 1.8.1.2