1 | /** |
---|
2 | * @file rtems/score/corerwlock.h |
---|
3 | * |
---|
4 | * This include file contains all the constants and structures associated |
---|
5 | * with the RWLock Handler. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2006. |
---|
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.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_CORERWLOCK_H |
---|
20 | #define _RTEMS_SCORE_CORERWLOCK_H |
---|
21 | |
---|
22 | /** |
---|
23 | * @defgroup ScoreRWLock RWLock Handler |
---|
24 | * |
---|
25 | * This handler encapsulates functionality which provides the foundation |
---|
26 | * RWLock services used in all of the APIs supported by RTEMS. |
---|
27 | */ |
---|
28 | /**@{*/ |
---|
29 | |
---|
30 | #ifdef __cplusplus |
---|
31 | extern "C" { |
---|
32 | #endif |
---|
33 | |
---|
34 | #include <rtems/score/thread.h> |
---|
35 | #include <rtems/score/threadq.h> |
---|
36 | #include <rtems/score/priority.h> |
---|
37 | #include <rtems/score/watchdog.h> |
---|
38 | |
---|
39 | /** |
---|
40 | * The following type defines the callout which the API provides |
---|
41 | * to support global/multiprocessor operations on RWLocks. |
---|
42 | */ |
---|
43 | typedef void ( *CORE_RWLock_API_mp_support_callout )( |
---|
44 | Thread_Control *, |
---|
45 | Objects_Id |
---|
46 | ); |
---|
47 | |
---|
48 | /** |
---|
49 | * RWLock State. |
---|
50 | */ |
---|
51 | typedef enum { |
---|
52 | /** This indicates the the RWLock is not currently locked. |
---|
53 | */ |
---|
54 | CORE_RWLOCK_UNLOCKED, |
---|
55 | /** This indicates the the RWLock is currently locked for reading. |
---|
56 | */ |
---|
57 | CORE_RWLOCK_LOCKED_FOR_READING, |
---|
58 | /** This indicates the the RWLock is currently locked for reading. |
---|
59 | */ |
---|
60 | CORE_RWLOCK_LOCKED_FOR_WRITING |
---|
61 | } CORE_RWLock_States; |
---|
62 | |
---|
63 | /** |
---|
64 | * Core RWLock handler return statuses. |
---|
65 | */ |
---|
66 | typedef enum { |
---|
67 | /** This status indicates that the operation completed successfully. */ |
---|
68 | CORE_RWLOCK_SUCCESSFUL, |
---|
69 | /** This status indicates that the thread was blocked waiting for an */ |
---|
70 | CORE_RWLOCK_WAS_DELETED, |
---|
71 | /** This status indicates that the rwlock was not immediately available. */ |
---|
72 | CORE_RWLOCK_UNAVAILABLE, |
---|
73 | /** This status indicates that the calling task was willing to block |
---|
74 | * but the operation was unable to complete within the time allotted |
---|
75 | * because the resource never became available. |
---|
76 | */ |
---|
77 | CORE_RWLOCK_TIMEOUT |
---|
78 | } CORE_RWLock_Status; |
---|
79 | |
---|
80 | /** This is the last status value. |
---|
81 | */ |
---|
82 | #define CORE_RWLOCK_STATUS_LAST CORE_RWLOCK_TIMEOUT |
---|
83 | |
---|
84 | /** |
---|
85 | * This is used to denote that a thread is blocking waiting for |
---|
86 | * read-only access to the RWLock. |
---|
87 | */ |
---|
88 | #define CORE_RWLOCK_THREAD_WAITING_FOR_READ 0 |
---|
89 | |
---|
90 | /** |
---|
91 | * This is used to denote that a thread is blocking waiting for |
---|
92 | * write-exclusive access to the RWLock. |
---|
93 | */ |
---|
94 | #define CORE_RWLOCK_THREAD_WAITING_FOR_WRITE 1 |
---|
95 | |
---|
96 | /** |
---|
97 | * The following defines the control block used to manage the |
---|
98 | * attributes of each RWLock. |
---|
99 | */ |
---|
100 | typedef struct { |
---|
101 | /** This field indicates XXX. |
---|
102 | */ |
---|
103 | int XXX; |
---|
104 | } CORE_RWLock_Attributes; |
---|
105 | |
---|
106 | /** |
---|
107 | * The following defines the control block used to manage each |
---|
108 | * RWLock. |
---|
109 | */ |
---|
110 | typedef struct { |
---|
111 | /** This field is the Waiting Queue used to manage the set of tasks |
---|
112 | * which are blocked waiting for the RWLock to be released. |
---|
113 | */ |
---|
114 | Thread_queue_Control Wait_queue; |
---|
115 | /** This element is the set of attributes which define this instance's |
---|
116 | * behavior. |
---|
117 | */ |
---|
118 | CORE_RWLock_Attributes Attributes; |
---|
119 | /** This element is the current state of the RWLock. |
---|
120 | */ |
---|
121 | CORE_RWLock_States current_state; |
---|
122 | /** This element contains the current number of thread waiting for this |
---|
123 | * RWLock to be released. */ |
---|
124 | uint32_t number_of_readers; |
---|
125 | } CORE_RWLock_Control; |
---|
126 | |
---|
127 | /** |
---|
128 | * This routine initializes the RWLock based on the parameters passed. |
---|
129 | * |
---|
130 | * @param[in] the_rwlock is the RWLock to initialize |
---|
131 | * @param[in] the_rwlock_attributes define the behavior of this instance |
---|
132 | */ |
---|
133 | void _CORE_RWLock_Initialize( |
---|
134 | CORE_RWLock_Control *the_rwlock, |
---|
135 | CORE_RWLock_Attributes *the_rwlock_attributes |
---|
136 | ); |
---|
137 | |
---|
138 | /** |
---|
139 | * This routine attempts to obtain the RWLock for read access. |
---|
140 | * |
---|
141 | * @param[in] the_rwlock is the RWLock to wait for |
---|
142 | * @param[in] id is the id of the object being waited upon |
---|
143 | * @param[in] wait is TRUE if the calling thread is willing to wait |
---|
144 | * @param[in] timeout is the number of ticks the calling thread is willing |
---|
145 | * to wait if @a wait is TRUE. |
---|
146 | * @param[in] api_rwlock_mp_support is the routine to invoke if the |
---|
147 | * thread unblocked is remote |
---|
148 | * |
---|
149 | * @note Status is returned via the thread control block. |
---|
150 | */ |
---|
151 | void _CORE_RWLock_Obtain_for_reading( |
---|
152 | CORE_RWLock_Control *the_rwlock, |
---|
153 | Objects_Id id, |
---|
154 | boolean wait, |
---|
155 | Watchdog_Interval timeout, |
---|
156 | CORE_RWLock_API_mp_support_callout api_rwlock_mp_support |
---|
157 | ); |
---|
158 | |
---|
159 | /** |
---|
160 | * This routine attempts to obtain the RWLock for write exclusive access. |
---|
161 | * |
---|
162 | * @param[in] the_rwlock is the RWLock to wait for |
---|
163 | * @param[in] id is the id of the object being waited upon |
---|
164 | * @param[in] wait is TRUE if the calling thread is willing to wait |
---|
165 | * @param[in] timeout is the number of ticks the calling thread is willing |
---|
166 | * to wait if @a wait is TRUE. |
---|
167 | * @param[in] api_rwlock_mp_support is the routine to invoke if the |
---|
168 | * thread unblocked is remote |
---|
169 | * |
---|
170 | * @note Status is returned via the thread control block. |
---|
171 | */ |
---|
172 | void _CORE_RWLock_Obtain_for_writing( |
---|
173 | CORE_RWLock_Control *the_rwlock, |
---|
174 | Objects_Id id, |
---|
175 | boolean wait, |
---|
176 | Watchdog_Interval timeout, |
---|
177 | CORE_RWLock_API_mp_support_callout api_rwlock_mp_support |
---|
178 | ); |
---|
179 | |
---|
180 | /** |
---|
181 | * This routine manually releases the RWLock. All of the threads waiting |
---|
182 | * for the RWLock will be readied. |
---|
183 | * |
---|
184 | * @param[in] the_rwlock is the RWLock to surrender |
---|
185 | * |
---|
186 | * @return Status is returned to indicate successful or failure. |
---|
187 | */ |
---|
188 | CORE_RWLock_Status _CORE_RWLock_Release( |
---|
189 | CORE_RWLock_Control *the_rwlock |
---|
190 | ); |
---|
191 | |
---|
192 | /** |
---|
193 | * This routine assists in the deletion of a RWLock by flushing the |
---|
194 | * associated wait queue. |
---|
195 | * |
---|
196 | * @param[in] the_rwlock is the RWLock to flush |
---|
197 | * @param[in] remote_extract_callout is the routine to invoke if the |
---|
198 | * thread unblocked is remote |
---|
199 | * @param[in] status is the status to be returned to the unblocked thread |
---|
200 | */ |
---|
201 | #define _CORE_RWLock_Flush( _the_rwlock, _remote_extract_callout, _status) \ |
---|
202 | _Thread_queue_Flush( \ |
---|
203 | &((_the_rwlock)->Wait_queue), \ |
---|
204 | (_remote_extract_callout), \ |
---|
205 | (_status) \ |
---|
206 | ) |
---|
207 | |
---|
208 | #ifndef __RTEMS_APPLICATION__ |
---|
209 | #include <rtems/score/corerwlock.inl> |
---|
210 | #endif |
---|
211 | |
---|
212 | #ifdef __cplusplus |
---|
213 | } |
---|
214 | #endif |
---|
215 | |
---|
216 | /**@}*/ |
---|
217 | |
---|
218 | #endif |
---|
219 | /* end of include file */ |
---|