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 | * The following defines the information control block used to manage |
---|
31 | * this class of objects. |
---|
32 | */ |
---|
33 | extern Objects_Information _Semaphore_Information; |
---|
34 | |
---|
35 | extern const rtems_status_code |
---|
36 | _Semaphore_Translate_core_mutex_return_code_[]; |
---|
37 | |
---|
38 | extern const rtems_status_code |
---|
39 | _Semaphore_Translate_core_semaphore_return_code_[]; |
---|
40 | |
---|
41 | /** |
---|
42 | * @brief Semaphore Translate Core Mutex Return Code |
---|
43 | * |
---|
44 | * This function returns a RTEMS status code based on the mutex |
---|
45 | * status code specified. |
---|
46 | * |
---|
47 | * @param[in] status is the mutex status code to translate |
---|
48 | * |
---|
49 | * @retval translated RTEMS status code |
---|
50 | */ |
---|
51 | RTEMS_INLINE_ROUTINE rtems_status_code |
---|
52 | _Semaphore_Translate_core_mutex_return_code( |
---|
53 | uint32_t status |
---|
54 | ) |
---|
55 | { |
---|
56 | /* |
---|
57 | * If this thread is blocking waiting for a result on a remote operation. |
---|
58 | */ |
---|
59 | #if defined(RTEMS_MULTIPROCESSING) |
---|
60 | if ( _Thread_Is_proxy_blocking(status) ) |
---|
61 | return RTEMS_PROXY_BLOCKING; |
---|
62 | #endif |
---|
63 | |
---|
64 | /* |
---|
65 | * Internal consistency check for bad status from SuperCore |
---|
66 | */ |
---|
67 | #if defined(RTEMS_DEBUG) |
---|
68 | if ( status > CORE_MUTEX_STATUS_LAST ) |
---|
69 | return RTEMS_INTERNAL_ERROR; |
---|
70 | #endif |
---|
71 | return _Semaphore_Translate_core_mutex_return_code_[status]; |
---|
72 | } |
---|
73 | |
---|
74 | #if defined(RTEMS_SMP) |
---|
75 | RTEMS_INLINE_ROUTINE rtems_status_code |
---|
76 | _Semaphore_Translate_MRSP_status_code( MRSP_Status mrsp_status ) |
---|
77 | { |
---|
78 | return (rtems_status_code) mrsp_status; |
---|
79 | } |
---|
80 | #endif |
---|
81 | |
---|
82 | /** |
---|
83 | * @brief Semaphore Translate Core Semaphore Return Code |
---|
84 | * |
---|
85 | * This function returns a RTEMS status code based on the semaphore |
---|
86 | * status code specified. |
---|
87 | * |
---|
88 | * @param[in] status is the semaphore status code to translate |
---|
89 | * |
---|
90 | * @retval translated RTEMS status code |
---|
91 | */ |
---|
92 | RTEMS_INLINE_ROUTINE rtems_status_code |
---|
93 | _Semaphore_Translate_core_semaphore_return_code( |
---|
94 | uint32_t status |
---|
95 | ) |
---|
96 | { |
---|
97 | #if defined(RTEMS_MULTIPROCESSING) |
---|
98 | if ( _Thread_Is_proxy_blocking(status) ) |
---|
99 | return RTEMS_PROXY_BLOCKING; |
---|
100 | #endif |
---|
101 | /* |
---|
102 | * Internal consistency check for bad status from SuperCore |
---|
103 | */ |
---|
104 | #if defined(RTEMS_DEBUG) |
---|
105 | if ( status > CORE_SEMAPHORE_STATUS_LAST ) |
---|
106 | return RTEMS_INTERNAL_ERROR; |
---|
107 | #endif |
---|
108 | return _Semaphore_Translate_core_semaphore_return_code_[status]; |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
112 | * @brief Allocates a semaphore control block from |
---|
113 | * the inactive chain of free semaphore control blocks. |
---|
114 | * |
---|
115 | * This function allocates a semaphore control block from |
---|
116 | * the inactive chain of free semaphore control blocks. |
---|
117 | */ |
---|
118 | RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Allocate( void ) |
---|
119 | { |
---|
120 | return (Semaphore_Control *) _Objects_Allocate( &_Semaphore_Information ); |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | * @brief Frees a semaphore control block to the |
---|
125 | * inactive chain of free semaphore control blocks. |
---|
126 | * |
---|
127 | * This routine frees a semaphore control block to the |
---|
128 | * inactive chain of free semaphore control blocks. |
---|
129 | */ |
---|
130 | RTEMS_INLINE_ROUTINE void _Semaphore_Free ( |
---|
131 | Semaphore_Control *the_semaphore |
---|
132 | ) |
---|
133 | { |
---|
134 | _Objects_Free( &_Semaphore_Information, &the_semaphore->Object ); |
---|
135 | } |
---|
136 | |
---|
137 | RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Get( |
---|
138 | Objects_Id id, |
---|
139 | ISR_lock_Context *lock_context |
---|
140 | ) |
---|
141 | { |
---|
142 | return (Semaphore_Control *) _Objects_Get( |
---|
143 | id, |
---|
144 | lock_context, |
---|
145 | &_Semaphore_Information |
---|
146 | ); |
---|
147 | } |
---|
148 | |
---|
149 | #ifdef __cplusplus |
---|
150 | } |
---|
151 | #endif |
---|
152 | |
---|
153 | #ifdef RTEMS_MULTIPROCESSING |
---|
154 | #include <rtems/rtems/semmp.h> |
---|
155 | #endif |
---|
156 | |
---|
157 | #endif |
---|
158 | /* end of include file */ |
---|