1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Inlined Routines Associated with the SuperCore RWLock |
---|
5 | * |
---|
6 | * This include file contains all of the inlined routines associated |
---|
7 | * with the SuperCore RWLock. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2008. |
---|
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.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_CORERWLOCKIMPL_H |
---|
20 | #define _RTEMS_SCORE_CORERWLOCKIMPL_H |
---|
21 | |
---|
22 | #include <rtems/score/corerwlock.h> |
---|
23 | #include <rtems/score/thread.h> |
---|
24 | #include <rtems/score/threadqimpl.h> |
---|
25 | #include <rtems/score/watchdog.h> |
---|
26 | |
---|
27 | #ifdef __cplusplus |
---|
28 | extern "C" { |
---|
29 | #endif |
---|
30 | |
---|
31 | /** |
---|
32 | * @addtogroup ScoreRWLock |
---|
33 | */ |
---|
34 | /**@{**/ |
---|
35 | |
---|
36 | #define CORE_RWLOCK_TQ_OPERATIONS &_Thread_queue_Operations_FIFO |
---|
37 | |
---|
38 | /** |
---|
39 | * Core RWLock handler return statuses. |
---|
40 | */ |
---|
41 | typedef enum { |
---|
42 | /** This status indicates that the operation completed successfully. */ |
---|
43 | CORE_RWLOCK_SUCCESSFUL, |
---|
44 | /** This status indicates that the thread was blocked waiting for an */ |
---|
45 | CORE_RWLOCK_WAS_DELETED, |
---|
46 | /** This status indicates that the rwlock was not immediately available. */ |
---|
47 | CORE_RWLOCK_UNAVAILABLE, |
---|
48 | /** This status indicates that the calling task was willing to block |
---|
49 | * but the operation was unable to complete within the time allotted |
---|
50 | * because the resource never became available. |
---|
51 | */ |
---|
52 | CORE_RWLOCK_TIMEOUT |
---|
53 | } CORE_RWLock_Status; |
---|
54 | |
---|
55 | /** This is the last status value. |
---|
56 | */ |
---|
57 | #define CORE_RWLOCK_STATUS_LAST CORE_RWLOCK_TIMEOUT |
---|
58 | |
---|
59 | /** |
---|
60 | * This is used to denote that a thread is blocking waiting for |
---|
61 | * read-only access to the RWLock. |
---|
62 | */ |
---|
63 | #define CORE_RWLOCK_THREAD_WAITING_FOR_READ 0 |
---|
64 | |
---|
65 | /** |
---|
66 | * This is used to denote that a thread is blocking waiting for |
---|
67 | * write-exclusive access to the RWLock. |
---|
68 | */ |
---|
69 | #define CORE_RWLOCK_THREAD_WAITING_FOR_WRITE 1 |
---|
70 | |
---|
71 | /** |
---|
72 | * @brief Initialize a RWlock. |
---|
73 | * |
---|
74 | * This routine initializes the RWLock based on the parameters passed. |
---|
75 | * |
---|
76 | * @param[in] the_rwlock is the RWLock to initialize |
---|
77 | */ |
---|
78 | void _CORE_RWLock_Initialize( |
---|
79 | CORE_RWLock_Control *the_rwlock |
---|
80 | ); |
---|
81 | |
---|
82 | RTEMS_INLINE_ROUTINE void _CORE_RWLock_Destroy( |
---|
83 | CORE_RWLock_Control *the_rwlock |
---|
84 | ) |
---|
85 | { |
---|
86 | _Thread_queue_Destroy( &the_rwlock->Wait_queue ); |
---|
87 | } |
---|
88 | |
---|
89 | RTEMS_INLINE_ROUTINE void _CORE_RWLock_Acquire_critical( |
---|
90 | CORE_RWLock_Control *the_rwlock, |
---|
91 | ISR_lock_Context *lock_context |
---|
92 | ) |
---|
93 | { |
---|
94 | _Thread_queue_Acquire_critical( &the_rwlock->Wait_queue, lock_context ); |
---|
95 | } |
---|
96 | |
---|
97 | RTEMS_INLINE_ROUTINE void _CORE_RWLock_Release( |
---|
98 | CORE_RWLock_Control *the_rwlock, |
---|
99 | ISR_lock_Context *lock_context |
---|
100 | ) |
---|
101 | { |
---|
102 | _Thread_queue_Release( &the_rwlock->Wait_queue, lock_context ); |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * @brief Obtain RWLock for reading. |
---|
107 | * |
---|
108 | * This routine attempts to obtain the RWLock for read access. |
---|
109 | * |
---|
110 | * @param[in] the_rwlock is the RWLock to wait for |
---|
111 | * @param[in] wait is true if the calling thread is willing to wait |
---|
112 | * @param[in] timeout is the number of ticks the calling thread is willing |
---|
113 | * to wait if @a wait is true. |
---|
114 | * |
---|
115 | * @note Status is returned via the thread control block. |
---|
116 | */ |
---|
117 | |
---|
118 | void _CORE_RWLock_Seize_for_reading( |
---|
119 | CORE_RWLock_Control *the_rwlock, |
---|
120 | Thread_Control *executing, |
---|
121 | bool wait, |
---|
122 | Watchdog_Interval timeout, |
---|
123 | ISR_lock_Context *lock_context |
---|
124 | ); |
---|
125 | |
---|
126 | /** |
---|
127 | * @brief Obtain RWLock for writing. |
---|
128 | * |
---|
129 | * This routine attempts to obtain the RWLock for write exclusive access. |
---|
130 | * |
---|
131 | * @param[in] the_rwlock is the RWLock to wait for |
---|
132 | * @param[in] wait is true if the calling thread is willing to wait |
---|
133 | * @param[in] timeout is the number of ticks the calling thread is willing |
---|
134 | * to wait if @a wait is true. |
---|
135 | * |
---|
136 | * @note Status is returned via the thread control block. |
---|
137 | */ |
---|
138 | void _CORE_RWLock_Seize_for_writing( |
---|
139 | CORE_RWLock_Control *the_rwlock, |
---|
140 | Thread_Control *executing, |
---|
141 | bool wait, |
---|
142 | Watchdog_Interval timeout, |
---|
143 | ISR_lock_Context *lock_context |
---|
144 | ); |
---|
145 | |
---|
146 | /** |
---|
147 | * @brief Release the RWLock. |
---|
148 | * |
---|
149 | * This routine manually releases @a the_rwlock. All of the threads waiting |
---|
150 | * for the RWLock will be readied. |
---|
151 | * |
---|
152 | * @param[in] the_rwlock is the RWLock to surrender |
---|
153 | * |
---|
154 | * @retval Status is returned to indicate successful or failure. |
---|
155 | */ |
---|
156 | CORE_RWLock_Status _CORE_RWLock_Surrender( |
---|
157 | CORE_RWLock_Control *the_rwlock, |
---|
158 | ISR_lock_Context *lock_context |
---|
159 | ); |
---|
160 | |
---|
161 | /** @} */ |
---|
162 | |
---|
163 | #ifdef __cplusplus |
---|
164 | } |
---|
165 | #endif |
---|
166 | |
---|
167 | #endif |
---|
168 | /* end of include file */ |
---|