1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ClassicSem |
---|
5 | * |
---|
6 | * @brief Classic Semaphores Implementation |
---|
7 | */ |
---|
8 | |
---|
9 | /* COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef _RTEMS_RTEMS_SEMIMPL_H |
---|
18 | #define _RTEMS_RTEMS_SEMIMPL_H |
---|
19 | |
---|
20 | #include <rtems/rtems/sem.h> |
---|
21 | #include <rtems/score/coremuteximpl.h> |
---|
22 | #include <rtems/score/coresemimpl.h> |
---|
23 | #include <rtems/score/mrspimpl.h> |
---|
24 | |
---|
25 | #ifdef __cplusplus |
---|
26 | extern "C" { |
---|
27 | #endif |
---|
28 | |
---|
29 | /** |
---|
30 | * @brief Instantiate Semaphore Data |
---|
31 | * |
---|
32 | * Semaphore Manager -- Data Instantiation |
---|
33 | * |
---|
34 | * This constant is defined to extern most of the time when using |
---|
35 | * this header file. However by defining it to nothing, the data |
---|
36 | * declared in this header file can be instantiated. This is done |
---|
37 | * in a single per manager file. |
---|
38 | * |
---|
39 | */ |
---|
40 | #ifndef RTEMS_SEM_EXTERN |
---|
41 | #define RTEMS_SEM_EXTERN extern |
---|
42 | #endif |
---|
43 | |
---|
44 | /** |
---|
45 | * The following defines the information control block used to manage |
---|
46 | * this class of objects. |
---|
47 | */ |
---|
48 | RTEMS_SEM_EXTERN Objects_Information _Semaphore_Information; |
---|
49 | |
---|
50 | extern const rtems_status_code |
---|
51 | _Semaphore_Translate_core_mutex_return_code_[]; |
---|
52 | |
---|
53 | extern const rtems_status_code |
---|
54 | _Semaphore_Translate_core_semaphore_return_code_[]; |
---|
55 | |
---|
56 | /** |
---|
57 | * @brief Semaphore Manager Initialization |
---|
58 | * |
---|
59 | * This routine performs the initialization necessary for this manager. |
---|
60 | */ |
---|
61 | void _Semaphore_Manager_initialization(void); |
---|
62 | |
---|
63 | /** |
---|
64 | * @brief Semaphore Translate Core Mutex Return Code |
---|
65 | * |
---|
66 | * This function returns a RTEMS status code based on the mutex |
---|
67 | * status code specified. |
---|
68 | * |
---|
69 | * @param[in] status is the mutex status code to translate |
---|
70 | * |
---|
71 | * @retval translated RTEMS status code |
---|
72 | */ |
---|
73 | RTEMS_INLINE_ROUTINE rtems_status_code |
---|
74 | _Semaphore_Translate_core_mutex_return_code( |
---|
75 | uint32_t status |
---|
76 | ) |
---|
77 | { |
---|
78 | /* |
---|
79 | * If this thread is blocking waiting for a result on a remote operation. |
---|
80 | */ |
---|
81 | #if defined(RTEMS_MULTIPROCESSING) |
---|
82 | if ( _Thread_Is_proxy_blocking(status) ) |
---|
83 | return RTEMS_PROXY_BLOCKING; |
---|
84 | #endif |
---|
85 | |
---|
86 | /* |
---|
87 | * Internal consistency check for bad status from SuperCore |
---|
88 | */ |
---|
89 | #if defined(RTEMS_DEBUG) |
---|
90 | if ( status > CORE_MUTEX_STATUS_LAST ) |
---|
91 | return RTEMS_INTERNAL_ERROR; |
---|
92 | #endif |
---|
93 | return _Semaphore_Translate_core_mutex_return_code_[status]; |
---|
94 | } |
---|
95 | |
---|
96 | #if defined(RTEMS_SMP) |
---|
97 | RTEMS_INLINE_ROUTINE rtems_status_code |
---|
98 | _Semaphore_Translate_MRSP_status_code( MRSP_Status mrsp_status ) |
---|
99 | { |
---|
100 | return (rtems_status_code) mrsp_status; |
---|
101 | } |
---|
102 | #endif |
---|
103 | |
---|
104 | /** |
---|
105 | * @brief Semaphore Translate Core Semaphore Return Code |
---|
106 | * |
---|
107 | * This function returns a RTEMS status code based on the semaphore |
---|
108 | * status code specified. |
---|
109 | * |
---|
110 | * @param[in] status is the semaphore status code to translate |
---|
111 | * |
---|
112 | * @retval translated RTEMS status code |
---|
113 | */ |
---|
114 | RTEMS_INLINE_ROUTINE rtems_status_code |
---|
115 | _Semaphore_Translate_core_semaphore_return_code( |
---|
116 | uint32_t status |
---|
117 | ) |
---|
118 | { |
---|
119 | #if defined(RTEMS_MULTIPROCESSING) |
---|
120 | if ( _Thread_Is_proxy_blocking(status) ) |
---|
121 | return RTEMS_PROXY_BLOCKING; |
---|
122 | #endif |
---|
123 | /* |
---|
124 | * Internal consistency check for bad status from SuperCore |
---|
125 | */ |
---|
126 | #if defined(RTEMS_DEBUG) |
---|
127 | if ( status > CORE_SEMAPHORE_STATUS_LAST ) |
---|
128 | return RTEMS_INTERNAL_ERROR; |
---|
129 | #endif |
---|
130 | return _Semaphore_Translate_core_semaphore_return_code_[status]; |
---|
131 | } |
---|
132 | |
---|
133 | /** |
---|
134 | * @brief Allocates a semaphore control block from |
---|
135 | * the inactive chain of free semaphore control blocks. |
---|
136 | * |
---|
137 | * This function allocates a semaphore control block from |
---|
138 | * the inactive chain of free semaphore control blocks. |
---|
139 | */ |
---|
140 | RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Allocate( void ) |
---|
141 | { |
---|
142 | return (Semaphore_Control *) _Objects_Allocate( &_Semaphore_Information ); |
---|
143 | } |
---|
144 | |
---|
145 | /** |
---|
146 | * @brief Frees a semaphore control block to the |
---|
147 | * inactive chain of free semaphore control blocks. |
---|
148 | * |
---|
149 | * This routine frees a semaphore control block to the |
---|
150 | * inactive chain of free semaphore control blocks. |
---|
151 | */ |
---|
152 | RTEMS_INLINE_ROUTINE void _Semaphore_Free ( |
---|
153 | Semaphore_Control *the_semaphore |
---|
154 | ) |
---|
155 | { |
---|
156 | _Objects_Free( &_Semaphore_Information, &the_semaphore->Object ); |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * @brief Maps semaphore IDs to semaphore control blocks. |
---|
161 | * |
---|
162 | * This function maps semaphore IDs to semaphore control blocks. |
---|
163 | * If ID corresponds to a local semaphore, then it returns |
---|
164 | * the_semaphore control pointer which maps to ID and location |
---|
165 | * is set to OBJECTS_LOCAL. if the semaphore ID is global and |
---|
166 | * resides on a remote node, then location is set to OBJECTS_REMOTE, |
---|
167 | * and the_semaphore is undefined. Otherwise, location is set |
---|
168 | * to OBJECTS_ERROR and the_semaphore is undefined. |
---|
169 | */ |
---|
170 | RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Get ( |
---|
171 | Objects_Id id, |
---|
172 | Objects_Locations *location |
---|
173 | ) |
---|
174 | { |
---|
175 | return (Semaphore_Control *) |
---|
176 | _Objects_Get( &_Semaphore_Information, id, location ); |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | * @brief Maps semaphore IDs to semaphore control blocks. |
---|
181 | * |
---|
182 | * This function maps semaphore IDs to semaphore control blocks. |
---|
183 | * If ID corresponds to a local semaphore, then it returns |
---|
184 | * the_semaphore control pointer which maps to ID and location |
---|
185 | * is set to OBJECTS_LOCAL. if the semaphore ID is global and |
---|
186 | * resides on a remote node, then location is set to OBJECTS_REMOTE, |
---|
187 | * and the_semaphore is undefined. Otherwise, location is set |
---|
188 | * to OBJECTS_ERROR and the_semaphore is undefined. |
---|
189 | */ |
---|
190 | RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Get_interrupt_disable ( |
---|
191 | Objects_Id id, |
---|
192 | Objects_Locations *location, |
---|
193 | ISR_lock_Context *lock_context |
---|
194 | ) |
---|
195 | { |
---|
196 | return (Semaphore_Control *) _Objects_Get_isr_disable( |
---|
197 | &_Semaphore_Information, |
---|
198 | id, |
---|
199 | location, |
---|
200 | lock_context |
---|
201 | ); |
---|
202 | } |
---|
203 | |
---|
204 | #ifdef __cplusplus |
---|
205 | } |
---|
206 | #endif |
---|
207 | |
---|
208 | #ifdef RTEMS_MULTIPROCESSING |
---|
209 | #include <rtems/rtems/semmp.h> |
---|
210 | #endif |
---|
211 | |
---|
212 | #endif |
---|
213 | /* end of include file */ |
---|