1 | /** |
---|
2 | * @file rtems/rtems/sem.h |
---|
3 | * |
---|
4 | * This include file contains all the constants and structures associated |
---|
5 | * with the Semaphore Manager. This manager utilizes standard Dijkstra |
---|
6 | * counting semaphores to provide synchronization and mutual exclusion |
---|
7 | * capabilities. |
---|
8 | * |
---|
9 | * Directives provided are: |
---|
10 | * |
---|
11 | * - create a semaphore |
---|
12 | * - get an ID of a semaphore |
---|
13 | * - delete a semaphore |
---|
14 | * - acquire a semaphore |
---|
15 | * - release a semaphore |
---|
16 | */ |
---|
17 | |
---|
18 | /* COPYRIGHT (c) 1989-2008. |
---|
19 | * On-Line Applications Research Corporation (OAR). |
---|
20 | * |
---|
21 | * The license and distribution terms for this file may be |
---|
22 | * found in the file LICENSE in this distribution or at |
---|
23 | * http://www.rtems.com/license/LICENSE. |
---|
24 | * |
---|
25 | * $Id$ |
---|
26 | */ |
---|
27 | |
---|
28 | #ifndef _RTEMS_RTEMS_SEM_H |
---|
29 | #define _RTEMS_RTEMS_SEM_H |
---|
30 | |
---|
31 | /** |
---|
32 | * This constant is defined to extern most of the time when using |
---|
33 | * this header file. However by defining it to nothing, the data |
---|
34 | * declared in this header file can be instantiated. This is done |
---|
35 | * in a single per manager file. |
---|
36 | */ |
---|
37 | #ifndef RTEMS_SEM_EXTERN |
---|
38 | #define RTEMS_SEM_EXTERN extern |
---|
39 | #endif |
---|
40 | |
---|
41 | #ifdef __cplusplus |
---|
42 | extern "C" { |
---|
43 | #endif |
---|
44 | |
---|
45 | #include <rtems/rtems/types.h> |
---|
46 | #include <rtems/rtems/options.h> |
---|
47 | #include <rtems/rtems/support.h> |
---|
48 | #include <rtems/rtems/tasks.h> |
---|
49 | #include <rtems/rtems/attr.h> |
---|
50 | #include <rtems/score/coremutex.h> |
---|
51 | #include <rtems/score/object.h> |
---|
52 | #include <rtems/score/coresem.h> |
---|
53 | |
---|
54 | /** |
---|
55 | * @defgroup ClassicSem Semaphores |
---|
56 | * |
---|
57 | * @ingroup ClassicRTEMS |
---|
58 | * |
---|
59 | * This encapsulates functionality related to the Classic API |
---|
60 | * Semaphore Manager. |
---|
61 | */ |
---|
62 | /**@{*/ |
---|
63 | |
---|
64 | /** |
---|
65 | * The following defines the control block used to manage each semaphore. |
---|
66 | */ |
---|
67 | typedef struct { |
---|
68 | /** This field is the object management portion of a Semaphore instance. */ |
---|
69 | Objects_Control Object; |
---|
70 | |
---|
71 | /** |
---|
72 | * This is the Classic API attribute provided to the create directive. |
---|
73 | * It is translated into behavioral attributes on the SuperCore Semaphore |
---|
74 | * or Mutex instance. |
---|
75 | */ |
---|
76 | rtems_attribute attribute_set; |
---|
77 | |
---|
78 | /** |
---|
79 | * This contains the memory associated with the SuperCore Semaphore or |
---|
80 | * Mutex instance that provides the primary functionality of each |
---|
81 | * Classic API Semaphore instance. The structure used is dependent |
---|
82 | * on the attributes specified by the user on the create directive. |
---|
83 | * |
---|
84 | * @note Only one of these has meaning in a particular Classic API |
---|
85 | * Semaphore instance. |
---|
86 | */ |
---|
87 | union { |
---|
88 | /** |
---|
89 | * This is the SuperCore Mutex instance associated with this Classic |
---|
90 | * API Semaphore instance. |
---|
91 | */ |
---|
92 | CORE_mutex_Control mutex; |
---|
93 | |
---|
94 | /** |
---|
95 | * This is the SuperCore Semaphore instance associated with this Classic |
---|
96 | * API Semaphore instance. |
---|
97 | */ |
---|
98 | CORE_semaphore_Control semaphore; |
---|
99 | } Core_control; |
---|
100 | } Semaphore_Control; |
---|
101 | |
---|
102 | /** |
---|
103 | * The following defines the information control block used to manage |
---|
104 | * this class of objects. |
---|
105 | */ |
---|
106 | RTEMS_SEM_EXTERN Objects_Information _Semaphore_Information; |
---|
107 | |
---|
108 | /** |
---|
109 | * @brief Semaphore_Manager_initialization |
---|
110 | * |
---|
111 | * This routine performs the initialization necessary for this manager. |
---|
112 | */ |
---|
113 | void _Semaphore_Manager_initialization(void); |
---|
114 | |
---|
115 | /** |
---|
116 | * @brief rtems_semaphore_create |
---|
117 | * |
---|
118 | * This routine implements the rtems_semaphore_create directive. The |
---|
119 | * semaphore will have the name name. The starting count for |
---|
120 | * the semaphore is count. The attribute_set determines if |
---|
121 | * the semaphore is global or local and the thread queue |
---|
122 | * discipline. It returns the id of the created semaphore in ID. |
---|
123 | */ |
---|
124 | rtems_status_code rtems_semaphore_create( |
---|
125 | rtems_name name, |
---|
126 | uint32_t count, |
---|
127 | rtems_attribute attribute_set, |
---|
128 | rtems_task_priority priority_ceiling, |
---|
129 | rtems_id *id |
---|
130 | ); |
---|
131 | |
---|
132 | /** |
---|
133 | * @brief rtems_semaphore_ident |
---|
134 | * |
---|
135 | * This routine implements the rtems_semaphore_ident directive. |
---|
136 | * This directive returns the semaphore ID associated with name. |
---|
137 | * If more than one semaphore is named name, then the semaphore |
---|
138 | * to which the ID belongs is arbitrary. node indicates the |
---|
139 | * extent of the search for the ID of the semaphore named name. |
---|
140 | * The search can be limited to a particular node or allowed to |
---|
141 | * encompass all nodes. |
---|
142 | */ |
---|
143 | rtems_status_code rtems_semaphore_ident( |
---|
144 | rtems_name name, |
---|
145 | uint32_t node, |
---|
146 | rtems_id *id |
---|
147 | ); |
---|
148 | |
---|
149 | /** |
---|
150 | * @brief rtems_semaphore_delete |
---|
151 | * |
---|
152 | * This routine implements the rtems_semaphore_delete directive. The |
---|
153 | * semaphore indicated by ID is deleted. |
---|
154 | */ |
---|
155 | rtems_status_code rtems_semaphore_delete( |
---|
156 | rtems_id id |
---|
157 | ); |
---|
158 | |
---|
159 | /** |
---|
160 | * @brief rtems_semaphore_obtain |
---|
161 | * |
---|
162 | * This routine implements the rtems_semaphore_obtain directive. It |
---|
163 | * attempts to obtain a unit from the semaphore associated with ID. |
---|
164 | * If a unit can be allocated, the calling task will return immediately. |
---|
165 | * If no unit is available, then the task may return immediately or |
---|
166 | * block waiting for a unit with an optional timeout of timeout |
---|
167 | * clock ticks. Whether the task blocks or returns immediately |
---|
168 | * is based on the RTEMS_NO_WAIT option in the option_set. |
---|
169 | */ |
---|
170 | rtems_status_code rtems_semaphore_obtain( |
---|
171 | rtems_id id, |
---|
172 | rtems_option option_set, |
---|
173 | rtems_interval timeout |
---|
174 | ); |
---|
175 | |
---|
176 | /** |
---|
177 | * @brief rtems_semaphore_release |
---|
178 | * |
---|
179 | * This routine implements the rtems_semaphore_release directive. It |
---|
180 | * frees a unit to the semaphore associated with ID. If a task was |
---|
181 | * blocked waiting for a unit from this semaphore, then that task will |
---|
182 | * be readied and the unit given to that task. Otherwise, the unit |
---|
183 | * will be returned to the semaphore. |
---|
184 | */ |
---|
185 | rtems_status_code rtems_semaphore_release( |
---|
186 | rtems_id id |
---|
187 | ); |
---|
188 | |
---|
189 | /** |
---|
190 | * @brief rtems_semaphore_flush |
---|
191 | * pending on the semaphore. |
---|
192 | */ |
---|
193 | rtems_status_code rtems_semaphore_flush( |
---|
194 | rtems_id id |
---|
195 | ); |
---|
196 | |
---|
197 | /** |
---|
198 | * @brief _Semaphore_Seize |
---|
199 | * |
---|
200 | * This routine attempts to receive a unit from the_semaphore. |
---|
201 | * If a unit is available or if the RTEMS_NO_WAIT option is enabled in |
---|
202 | * option_set, then the routine returns. Otherwise, the calling task |
---|
203 | * is blocked until a unit becomes available. |
---|
204 | */ |
---|
205 | bool _Semaphore_Seize( |
---|
206 | Semaphore_Control *the_semaphore, |
---|
207 | uint32_t option_set |
---|
208 | ); |
---|
209 | |
---|
210 | /** |
---|
211 | * @brief _Semaphore_Translate_core_mutex_return_code |
---|
212 | * |
---|
213 | * This function returns a RTEMS status code based on the mutex |
---|
214 | * status code specified. |
---|
215 | */ |
---|
216 | rtems_status_code _Semaphore_Translate_core_mutex_return_code ( |
---|
217 | uint32_t the_mutex_status |
---|
218 | ); |
---|
219 | |
---|
220 | /** |
---|
221 | * @brief _Semaphore_Translate_core_semaphore_return_code |
---|
222 | * |
---|
223 | * This function returns a RTEMS status code based on the semaphore |
---|
224 | * status code specified. |
---|
225 | */ |
---|
226 | rtems_status_code _Semaphore_Translate_core_semaphore_return_code ( |
---|
227 | uint32_t the_mutex_status |
---|
228 | ); |
---|
229 | |
---|
230 | #ifndef __RTEMS_APPLICATION__ |
---|
231 | #include <rtems/rtems/sem.inl> |
---|
232 | #endif |
---|
233 | #if defined(RTEMS_MULTIPROCESSING) |
---|
234 | #include <rtems/rtems/semmp.h> |
---|
235 | #endif |
---|
236 | |
---|
237 | #ifdef __cplusplus |
---|
238 | } |
---|
239 | #endif |
---|
240 | |
---|
241 | /**@}*/ |
---|
242 | |
---|
243 | #endif |
---|
244 | /* end of include file */ |
---|