source: rtems/c/src/exec/rtems/include/rtems/rtems/sem.h @ 5e9b32b

4.104.114.84.95
Last change on this file since 5e9b32b was 5e9b32b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/26/95 at 19:27:15

posix support initially added

  • Property mode set to 100644
File size: 7.2 KB
Line 
1/*  semaphore.h
2 *
3 *  This include file contains all the constants and structures associated
4 *  with the Semaphore Manager.  This manager utilizes standard Dijkstra
5 *  counting semaphores to provide synchronization and mutual exclusion
6 *  capabilities.
7 *
8 *  Directives provided are:
9 *
10 *     + create a semaphore
11 *     + get an ID of a semaphore
12 *     + delete a semaphore
13 *     + acquire a semaphore
14 *     + release a semaphore
15 *
16 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
17 *  On-Line Applications Research Corporation (OAR).
18 *  All rights assigned to U.S. Government, 1994.
19 *
20 *  This material may be reproduced by or for the U.S. Government pursuant
21 *  to the copyright license under the clause at DFARS 252.227-7013.  This
22 *  notice must appear in all copies of this file and its derivatives.
23 *
24 *  $Id$
25 */
26
27#ifndef __RTEMS_SEMAPHORE_h
28#define __RTEMS_SEMAPHORE_h
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <rtems/rtems/types.h>
35#include <rtems/rtems/support.h>
36#include <rtems/rtems/tasks.h>
37#include <rtems/rtems/attr.h>
38#include <rtems/score/coremutex.h>
39#include <rtems/score/object.h>
40#include <rtems/score/coresem.h>
41#include <rtems/score/threadq.h>
42
43/*
44 *  The following defines the control block used to manage each semaphore.
45 */
46
47typedef struct {
48  Objects_Control          Object;
49  rtems_attribute          attribute_set;
50  union {
51    CORE_mutex_Control     mutex;
52    CORE_semaphore_Control semaphore;
53  } Core_control;
54}   Semaphore_Control;
55
56/*
57 *  The following defines the information control block used to manage
58 *  this class of objects.
59 */
60
61EXTERN Objects_Information  _Semaphore_Information;
62
63/*
64 *  _Semaphore_Manager_initialization
65 *
66 *  DESCRIPTION:
67 *
68 *  This routine performs the initialization necessary for this manager.
69 */
70
71void _Semaphore_Manager_initialization(
72  unsigned32 maximum_semaphores
73);
74
75/*
76 *  rtems_semaphore_create
77 *
78 *  DESCRIPTION:
79 *
80 *  This routine implements the rtems_semaphore_create directive.  The
81 *  semaphore will have the name name.  The starting count for
82 *  the semaphore is count.  The attribute_set determines if
83 *  the semaphore is global or local and the thread queue
84 *  discipline.  It returns the id of the created semaphore in ID.
85 */
86
87rtems_status_code rtems_semaphore_create(
88  rtems_name           name,
89  unsigned32           count,
90  rtems_attribute      attribute_set,
91  rtems_task_priority  priority_ceiling,
92  rtems_id            *id
93);
94
95/*
96 *  rtems_semaphore_ident
97 *
98 *  DESCRIPTION:
99 *
100 *  This routine implements the rtems_semaphore_ident directive.
101 *  This directive returns the semaphore ID associated with name.
102 *  If more than one semaphore is named name, then the semaphore
103 *  to which the ID belongs is arbitrary.  node indicates the
104 *  extent of the search for the ID of the semaphore named name.
105 *  The search can be limited to a particular node or allowed to
106 *  encompass all nodes.
107 */
108
109rtems_status_code rtems_semaphore_ident(
110  rtems_name    name,
111  unsigned32    node,
112  rtems_id     *id
113);
114
115/*
116 *  rtems_semaphore_delete
117 *
118 *  DESCRIPTION:
119 *
120 *  This routine implements the rtems_semaphore_delete directive.  The
121 *  semaphore indicated by ID is deleted.
122 */
123
124rtems_status_code rtems_semaphore_delete(
125  rtems_id   id
126);
127
128/*
129 *  rtems_semaphore_obtain
130 *
131 *  DESCRIPTION:
132 *
133 *  This routine implements the rtems_semaphore_obtain directive.  It
134 *  attempts to obtain a unit from the semaphore associated with ID.
135 *  If a unit can be allocated, the calling task will return immediately.
136 *  If no unit is available, then the task may return immediately or
137 *  block waiting for a unit with an optional timeout of timeout
138 *  clock ticks.  Whether the task blocks or returns immediately
139 *  is based on the RTEMS_NO_WAIT option in the option_set.
140 */
141
142rtems_status_code rtems_semaphore_obtain(
143  rtems_id       id,
144  unsigned32     option_set,
145  rtems_interval timeout
146);
147
148/*
149 *  rtems_semaphore_release
150 *
151 *  DESCRIPTION:
152 *
153 *  This routine implements the rtems_semaphore_release directive.  It
154 *  frees a unit to the semaphore associated with ID.  If a task was
155 *  blocked waiting for a unit from this semaphore, then that task will
156 *  be readied and the unit given to that task.  Otherwise, the unit
157 *  will be returned to the semaphore.
158 */
159
160rtems_status_code rtems_semaphore_release(
161  rtems_id   id
162);
163
164/*
165 *  _Semaphore_Seize
166 *
167 *  DESCRIPTION:
168 *
169 *  This routine attempts to receive a unit from the_semaphore.
170 *  If a unit is available or if the RTEMS_NO_WAIT option is enabled in
171 *  option_set, then the routine returns.  Otherwise, the calling task
172 *  is blocked until a unit becomes available.
173 */
174
175boolean _Semaphore_Seize(
176  Semaphore_Control *the_semaphore,
177  unsigned32         option_set
178);
179
180/*
181 *  _Semaphore_Allocate
182 *
183 *  DESCRIPTION:
184 *
185 *  This function allocates a semaphore control block from
186 *  the inactive chain of free semaphore control blocks.
187 */
188
189STATIC INLINE Semaphore_Control *_Semaphore_Allocate( void );
190
191/*
192 *  _Semaphore_Free
193 *
194 *  DESCRIPTION:
195 *
196 *  This routine frees a semaphore control block to the
197 *  inactive chain of free semaphore control blocks.
198 */
199
200STATIC INLINE void _Semaphore_Free (
201  Semaphore_Control *the_semaphore
202);
203
204/*
205 *  _Semaphore_Get
206 *
207 *  DESCRIPTION:
208 *
209 *  This function maps semaphore IDs to semaphore control blocks.
210 *  If ID corresponds to a local semaphore, then it returns
211 *  the_semaphore control pointer which maps to ID and location
212 *  is set to OBJECTS_LOCAL.  if the semaphore ID is global and
213 *  resides on a remote node, then location is set to OBJECTS_REMOTE,
214 *  and the_semaphore is undefined.  Otherwise, location is set
215 *  to OBJECTS_ERROR and the_semaphore is undefined.
216 */
217
218STATIC INLINE Semaphore_Control *_Semaphore_Get (
219  rtems_id           id,
220  Objects_Locations *location
221);
222
223/*
224 *  _Semaphore_Is_null
225 *
226 *  DESCRIPTION:
227 *
228 *  This function returns TRUE if the_semaphore is NULL and FALSE otherwise.
229 */
230
231STATIC INLINE boolean _Semaphore_Is_null (
232  Semaphore_Control *the_semaphore
233);
234
235/*
236 *  _Semaphore_Translate_core_mutex_return_code
237 *
238 *  DESCRIPTION:
239 *
240 *  This function returns a RTEMS status code based on the mutex
241 *  status code specified.
242 */
243 
244rtems_status_code _Semaphore_Translate_core_mutex_return_code (
245  unsigned32 the_mutex_status
246);
247
248/*
249 *  _Semaphore_Translate_core_semaphore_return_code
250 *
251 *  DESCRIPTION:
252 *
253 *  This function returns a RTEMS status code based on the semaphore
254 *  status code specified.
255 */
256 
257rtems_status_code _Semaphore_Translate_core_semaphore_return_code (
258  unsigned32 the_mutex_status
259);
260 
261/*PAGE
262 *
263 *  _Semaphore_Core_mutex_mp_support
264 *
265 *  DESCRIPTION:
266 *
267 *  This function processes the global actions necessary for remote
268 *  accesses to a global semaphore based on a core mutex.  This function
269 *  is called by the core.
270 */
271
272void  _Semaphore_Core_mutex_mp_support (
273  Thread_Control *the_thread,
274  rtems_id        id
275);
276
277/*PAGE
278 *
279 *  _Semaphore_Core_mp_support
280 *
281 *  DESCRIPTION:
282 *
283 *  This function processes the global actions necessary for remote
284 *  accesses to a global semaphore based on a core semaphore.  This function
285 *  is called by the core.
286 */
287 
288void  _Semaphore_Core_semaphore_mp_support (
289  Thread_Control *the_thread,
290  rtems_id        id
291);
292
293#include <rtems/rtems/sem.inl>
294#include <rtems/rtems/semmp.h>
295
296#ifdef __cplusplus
297}
298#endif
299
300#endif
301/*  end of include file */
Note: See TracBrowser for help on using the repository browser.