1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSScoreBarrier |
---|
7 | * |
---|
8 | * @brief This header file provides interfaces of the |
---|
9 | * @ref RTEMSScoreBarrier which are only used by the implementation. |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * COPYRIGHT (c) 1989-2006. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * Redistribution and use in source and binary forms, with or without |
---|
17 | * modification, are permitted provided that the following conditions |
---|
18 | * are met: |
---|
19 | * 1. Redistributions of source code must retain the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer. |
---|
21 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer in the |
---|
23 | * documentation and/or other materials provided with the distribution. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
35 | * POSSIBILITY OF SUCH DAMAGE. |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef _RTEMS_SCORE_COREBARRIERIMPL_H |
---|
39 | #define _RTEMS_SCORE_COREBARRIERIMPL_H |
---|
40 | |
---|
41 | #include <rtems/score/corebarrier.h> |
---|
42 | #include <rtems/score/status.h> |
---|
43 | #include <rtems/score/threadqimpl.h> |
---|
44 | |
---|
45 | #ifdef __cplusplus |
---|
46 | extern "C" { |
---|
47 | #endif |
---|
48 | |
---|
49 | /** |
---|
50 | * @addtogroup RTEMSScoreBarrier |
---|
51 | * |
---|
52 | * @{ |
---|
53 | */ |
---|
54 | |
---|
55 | /** |
---|
56 | * @brief This maximum thread count constant indicates that the barrier is a |
---|
57 | * manual release barrier. |
---|
58 | */ |
---|
59 | #define CORE_BARRIER_MANUAL_RELEASE_MAXIMUM_COUNT 0 |
---|
60 | |
---|
61 | /** |
---|
62 | * @brief These thread queue operations are used for core barriers. |
---|
63 | * |
---|
64 | * They are a specialization of ::_Thread_queue_Operations_FIFO. The only |
---|
65 | * difference is that the extract operation decrements |
---|
66 | * CORE_barrier_Control::number_of_waiting_threads. |
---|
67 | */ |
---|
68 | extern const Thread_queue_Operations _CORE_barrier_Thread_queue_operations; |
---|
69 | |
---|
70 | /** |
---|
71 | * @brief Initializes the core barrier. |
---|
72 | * |
---|
73 | * @param[out] the_barrier is the barrier to initialize. |
---|
74 | * |
---|
75 | * @param maximum_count is the number of threads which must arrive at the |
---|
76 | * barrier to trip the automatic release or |
---|
77 | * ::CORE_BARRIER_MANUAL_RELEASE_MAXIMUM_COUNT to indicate a manual release |
---|
78 | * barrier. |
---|
79 | */ |
---|
80 | void _CORE_barrier_Initialize( |
---|
81 | CORE_barrier_Control *the_barrier, |
---|
82 | uint32_t maximum_count |
---|
83 | ); |
---|
84 | |
---|
85 | /** |
---|
86 | * @brief Destroys the core barrier. |
---|
87 | * |
---|
88 | * This routine destroys the barrier. |
---|
89 | * |
---|
90 | * @param[out] the_barrier The barrier to destroy. |
---|
91 | */ |
---|
92 | RTEMS_INLINE_ROUTINE void _CORE_barrier_Destroy( |
---|
93 | CORE_barrier_Control *the_barrier |
---|
94 | ) |
---|
95 | { |
---|
96 | _Thread_queue_Destroy( &the_barrier->Wait_queue ); |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief Acquires critical core barrier. |
---|
101 | * |
---|
102 | * @param[in, out] the_barrier The barrier to acquire. |
---|
103 | * @param queue_context The thread queue context. |
---|
104 | */ |
---|
105 | RTEMS_INLINE_ROUTINE void _CORE_barrier_Acquire_critical( |
---|
106 | CORE_barrier_Control *the_barrier, |
---|
107 | Thread_queue_Context *queue_context |
---|
108 | ) |
---|
109 | { |
---|
110 | _Thread_queue_Acquire_critical( &the_barrier->Wait_queue, queue_context ); |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * @brief Releases core barrier. |
---|
115 | * |
---|
116 | * @param[in, out] the_barrier The barrier to release. |
---|
117 | * @param queue_context The thread queue context. |
---|
118 | */ |
---|
119 | RTEMS_INLINE_ROUTINE void _CORE_barrier_Release( |
---|
120 | CORE_barrier_Control *the_barrier, |
---|
121 | Thread_queue_Context *queue_context |
---|
122 | ) |
---|
123 | { |
---|
124 | _Thread_queue_Release( &the_barrier->Wait_queue, queue_context ); |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * @brief Waits for the barrier. |
---|
129 | * |
---|
130 | * This routine waits for the barrier to be released. If the barrier |
---|
131 | * is set to automatic and this is the appropriate thread, then it returns |
---|
132 | * immediately. Otherwise, the calling thread is blocked until the barrier |
---|
133 | * is released. |
---|
134 | * |
---|
135 | * @param[in, out] the_barrier The barrier to wait for. |
---|
136 | * @param[in, out] executing The currently executing thread. |
---|
137 | * @param wait This parameter is true if the calling thread is willing to wait. |
---|
138 | * @param queue_context The thread queue context. |
---|
139 | * |
---|
140 | * @return The method status. |
---|
141 | */ |
---|
142 | Status_Control _CORE_barrier_Seize( |
---|
143 | CORE_barrier_Control *the_barrier, |
---|
144 | Thread_Control *executing, |
---|
145 | bool wait, |
---|
146 | Thread_queue_Context *queue_context |
---|
147 | ); |
---|
148 | |
---|
149 | /** |
---|
150 | * @brief Manually releases the barrier. |
---|
151 | * |
---|
152 | * This routine manually releases the barrier. All of the threads waiting |
---|
153 | * for the barrier will be readied. |
---|
154 | * |
---|
155 | * @param[in, out] the_barrier The barrier to surrender. |
---|
156 | * @param[out] queue_context The thread queue context. |
---|
157 | * |
---|
158 | * @return The number of unblocked threads. |
---|
159 | */ |
---|
160 | RTEMS_INLINE_ROUTINE uint32_t _CORE_barrier_Surrender( |
---|
161 | CORE_barrier_Control *the_barrier, |
---|
162 | Thread_queue_Context *queue_context |
---|
163 | ) |
---|
164 | { |
---|
165 | return _Thread_queue_Flush_critical( |
---|
166 | &the_barrier->Wait_queue.Queue, |
---|
167 | &_CORE_barrier_Thread_queue_operations, |
---|
168 | _Thread_queue_Flush_default_filter, |
---|
169 | queue_context |
---|
170 | ); |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * @brief Flushes the barrier using _CORE_barrier_Do_flush(). |
---|
175 | * |
---|
176 | * @param[in, out] the_barrier The barrier to flush. |
---|
177 | * @param queue_context The thread queue context. |
---|
178 | */ |
---|
179 | RTEMS_INLINE_ROUTINE void _CORE_barrier_Flush( |
---|
180 | CORE_barrier_Control *the_barrier, |
---|
181 | Thread_queue_Context *queue_context |
---|
182 | ) |
---|
183 | { |
---|
184 | _Thread_queue_Flush_critical( |
---|
185 | &the_barrier->Wait_queue.Queue, |
---|
186 | &_CORE_barrier_Thread_queue_operations, |
---|
187 | _Thread_queue_Flush_status_object_was_deleted, |
---|
188 | queue_context |
---|
189 | ); |
---|
190 | } |
---|
191 | |
---|
192 | /** @} */ |
---|
193 | |
---|
194 | #ifdef __cplusplus |
---|
195 | } |
---|
196 | #endif |
---|
197 | |
---|
198 | #endif |
---|
199 | /* end of include file */ |
---|