1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Private Inlined Routines for POSIX Semaphores |
---|
5 | * |
---|
6 | * This include file contains the static inline implementation of the private |
---|
7 | * inlined routines for POSIX Semaphores. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2011. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.com/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_POSIX_SEMAPHOREIMPL_H |
---|
20 | #define _RTEMS_POSIX_SEMAPHOREIMPL_H |
---|
21 | |
---|
22 | #include <rtems/posix/semaphore.h> |
---|
23 | #include <rtems/posix/posixapi.h> |
---|
24 | #include <rtems/score/coresemimpl.h> |
---|
25 | |
---|
26 | #include <errno.h> |
---|
27 | |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif |
---|
31 | |
---|
32 | /* |
---|
33 | * The following defines the information control block used to manage |
---|
34 | * this class of objects. |
---|
35 | */ |
---|
36 | |
---|
37 | POSIX_EXTERN Objects_Information _POSIX_Semaphore_Information; |
---|
38 | |
---|
39 | extern const int |
---|
40 | _POSIX_Semaphore_Return_codes[CORE_SEMAPHORE_STATUS_LAST + 1]; |
---|
41 | |
---|
42 | /* |
---|
43 | * _POSIX_Semaphore_Manager_initialization |
---|
44 | * |
---|
45 | * DESCRIPTION: |
---|
46 | * |
---|
47 | * This routine performs the initialization necessary for this manager. |
---|
48 | */ |
---|
49 | |
---|
50 | void _POSIX_Semaphore_Manager_initialization(void); |
---|
51 | |
---|
52 | /* |
---|
53 | * _POSIX_Semaphore_Allocate |
---|
54 | * |
---|
55 | * DESCRIPTION: |
---|
56 | * |
---|
57 | * This function allocates a semaphore control block from |
---|
58 | * the inactive chain of free semaphore control blocks. |
---|
59 | */ |
---|
60 | |
---|
61 | RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void ); |
---|
62 | |
---|
63 | /* |
---|
64 | * _POSIX_Semaphore_Free |
---|
65 | * |
---|
66 | * DESCRIPTION: |
---|
67 | * |
---|
68 | * This routine frees a semaphore control block to the |
---|
69 | * inactive chain of free semaphore control blocks. |
---|
70 | */ |
---|
71 | |
---|
72 | RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free ( |
---|
73 | POSIX_Semaphore_Control *the_semaphore |
---|
74 | ); |
---|
75 | |
---|
76 | /* |
---|
77 | * _POSIX_Semaphore_Get |
---|
78 | * |
---|
79 | * DESCRIPTION: |
---|
80 | * |
---|
81 | * This function maps semaphore IDs to semaphore control blocks. |
---|
82 | * If ID corresponds to a local semaphore, then it returns |
---|
83 | * the_semaphore control pointer which maps to ID and location |
---|
84 | * is set to OBJECTS_LOCAL. if the semaphore ID is global and |
---|
85 | * resides on a remote node, then location is set to OBJECTS_REMOTE, |
---|
86 | * and the_semaphore is undefined. Otherwise, location is set |
---|
87 | * to OBJECTS_ERROR and the_semaphore is undefined. |
---|
88 | */ |
---|
89 | |
---|
90 | RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get ( |
---|
91 | sem_t *id, |
---|
92 | Objects_Locations *location |
---|
93 | ); |
---|
94 | |
---|
95 | /* |
---|
96 | * _POSIX_Semaphore_Create_support |
---|
97 | * |
---|
98 | * DESCRIPTION: |
---|
99 | * |
---|
100 | * This routine supports the sem_init and sem_open routines. |
---|
101 | */ |
---|
102 | |
---|
103 | int _POSIX_Semaphore_Create_support( |
---|
104 | const char *name, |
---|
105 | size_t name_len, |
---|
106 | int pshared, |
---|
107 | unsigned int value, |
---|
108 | POSIX_Semaphore_Control **the_sem |
---|
109 | ); |
---|
110 | |
---|
111 | /** |
---|
112 | * @brief POSIX delete a semaphore. |
---|
113 | * |
---|
114 | * DESCRIPTION: |
---|
115 | * |
---|
116 | * This routine supports the sem_close and sem_unlink routines. |
---|
117 | */ |
---|
118 | void _POSIX_Semaphore_Delete( |
---|
119 | POSIX_Semaphore_Control *the_semaphore |
---|
120 | ); |
---|
121 | |
---|
122 | /** |
---|
123 | * @brief POSIX semaphore wait support. |
---|
124 | * |
---|
125 | * DESCRIPTION: |
---|
126 | * |
---|
127 | * This routine supports the sem_wait, sem_trywait, and sem_timedwait |
---|
128 | * services. |
---|
129 | */ |
---|
130 | int _POSIX_Semaphore_Wait_support( |
---|
131 | sem_t *sem, |
---|
132 | bool blocking, |
---|
133 | Watchdog_Interval timeout |
---|
134 | ); |
---|
135 | |
---|
136 | /* |
---|
137 | * _POSIX_Semaphore_Translate_core_semaphore_return_code |
---|
138 | * |
---|
139 | * DESCRIPTION: |
---|
140 | * |
---|
141 | * A support routine which converts core semaphore status codes into the |
---|
142 | * appropriate POSIX status values. |
---|
143 | */ |
---|
144 | |
---|
145 | RTEMS_INLINE_ROUTINE int |
---|
146 | _POSIX_Semaphore_Translate_core_semaphore_return_code( |
---|
147 | CORE_semaphore_Status the_semaphore_status |
---|
148 | ) |
---|
149 | { |
---|
150 | /* |
---|
151 | * Internal consistency check for bad status from SuperCore |
---|
152 | */ |
---|
153 | #if defined(RTEMS_DEBUG) |
---|
154 | if ( the_semaphore_status > CORE_SEMAPHORE_STATUS_LAST ) |
---|
155 | return EINVAL; |
---|
156 | #endif |
---|
157 | return _POSIX_Semaphore_Return_codes[the_semaphore_status]; |
---|
158 | } |
---|
159 | |
---|
160 | /* |
---|
161 | * _POSIX_Semaphore_Allocate |
---|
162 | */ |
---|
163 | |
---|
164 | RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void ) |
---|
165 | { |
---|
166 | return (POSIX_Semaphore_Control *) |
---|
167 | _Objects_Allocate( &_POSIX_Semaphore_Information ); |
---|
168 | } |
---|
169 | |
---|
170 | /* |
---|
171 | * _POSIX_Semaphore_Free |
---|
172 | */ |
---|
173 | |
---|
174 | RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free ( |
---|
175 | POSIX_Semaphore_Control *the_semaphore |
---|
176 | ) |
---|
177 | { |
---|
178 | _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object ); |
---|
179 | } |
---|
180 | |
---|
181 | /* |
---|
182 | * _POSIX_Semaphore_Namespace_remove |
---|
183 | */ |
---|
184 | |
---|
185 | RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Namespace_remove ( |
---|
186 | POSIX_Semaphore_Control *the_semaphore |
---|
187 | ) |
---|
188 | { |
---|
189 | _Objects_Namespace_remove( |
---|
190 | &_POSIX_Semaphore_Information, &the_semaphore->Object ); |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | /* |
---|
196 | * _POSIX_Semaphore_Get |
---|
197 | */ |
---|
198 | RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get ( |
---|
199 | sem_t *id, |
---|
200 | Objects_Locations *location |
---|
201 | ) |
---|
202 | { |
---|
203 | return (POSIX_Semaphore_Control *) |
---|
204 | _Objects_Get( &_POSIX_Semaphore_Information, (Objects_Id)*id, location ); |
---|
205 | } |
---|
206 | |
---|
207 | /** |
---|
208 | * @see _POSIX_Name_to_id(). |
---|
209 | */ |
---|
210 | RTEMS_INLINE_ROUTINE int _POSIX_Semaphore_Name_to_id( |
---|
211 | const char *name, |
---|
212 | Objects_Id *id, |
---|
213 | size_t *len |
---|
214 | ) |
---|
215 | { |
---|
216 | return _POSIX_Name_to_id( &_POSIX_Semaphore_Information, name, id, len ); |
---|
217 | } |
---|
218 | |
---|
219 | #ifdef __cplusplus |
---|
220 | } |
---|
221 | #endif |
---|
222 | |
---|
223 | #endif |
---|
224 | /* end of include file */ |
---|