RTEMS 6.1-rc7
Loading...
Searching...
No Matches
coresemimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
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_CORESEMIMPL_H
39#define _RTEMS_SCORE_CORESEMIMPL_H
40
41#include <rtems/score/coresem.h>
47#include <rtems/score/status.h>
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
72 CORE_semaphore_Control *the_semaphore,
73 uint32_t initial_value
74);
75
84static inline void _CORE_semaphore_Acquire_critical(
85 CORE_semaphore_Control *the_semaphore,
86 Thread_queue_Context *queue_context
87)
88{
89 _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, queue_context );
90}
91
100static inline void _CORE_semaphore_Release(
101 CORE_semaphore_Control *the_semaphore,
102 Thread_queue_Context *queue_context
103)
104{
105 _Thread_queue_Release( &the_semaphore->Wait_queue, queue_context );
106}
107
117static inline void _CORE_semaphore_Destroy(
118 CORE_semaphore_Control *the_semaphore,
119 const Thread_queue_Operations *operations,
120 Thread_queue_Context *queue_context
121)
122{
124 &the_semaphore->Wait_queue.Queue,
125 operations,
127 queue_context
128 );
129 _Thread_queue_Destroy( &the_semaphore->Wait_queue );
130}
131
148static inline Status_Control _CORE_semaphore_Surrender(
149 CORE_semaphore_Control *the_semaphore,
150 const Thread_queue_Operations *operations,
151 uint32_t maximum_count,
152 Thread_queue_Context *queue_context
153)
154{
155 Status_Control status;
156 Thread_queue_Heads *heads;
157
158 status = STATUS_SUCCESSFUL;
159
160 _CORE_semaphore_Acquire_critical( the_semaphore, queue_context );
161
162 heads = the_semaphore->Wait_queue.Queue.heads;
163
164 if ( heads != NULL ) {
166 &the_semaphore->Wait_queue.Queue,
167 heads,
168 queue_context,
169 operations
170 );
171 } else {
172 if ( the_semaphore->count < maximum_count )
173 the_semaphore->count += 1;
174 else
175 status = STATUS_MAXIMUM_COUNT_EXCEEDED;
176
177 _CORE_semaphore_Release( the_semaphore, queue_context );
178 }
179
180 return status;
181}
182
190static inline uint32_t _CORE_semaphore_Get_count(
191 const CORE_semaphore_Control *the_semaphore
192)
193{
194 return the_semaphore->count;
195}
196
217static inline Status_Control _CORE_semaphore_Seize(
218 CORE_semaphore_Control *the_semaphore,
219 const Thread_queue_Operations *operations,
220 Thread_Control *executing,
221 bool wait,
222 Thread_queue_Context *queue_context
223)
224{
225 _Assert( _ISR_Get_level() != 0 );
226
227 _CORE_semaphore_Acquire_critical( the_semaphore, queue_context );
228 if ( the_semaphore->count != 0 ) {
229 the_semaphore->count -= 1;
230 _CORE_semaphore_Release( the_semaphore, queue_context );
231 return STATUS_SUCCESSFUL;
232 }
233
234 if ( !wait ) {
235 _CORE_semaphore_Release( the_semaphore, queue_context );
236 return STATUS_UNSATISFIED;
237 }
238
239 _Thread_queue_Context_set_thread_state(
240 queue_context,
242 );
244 &the_semaphore->Wait_queue.Queue,
245 operations,
246 executing,
247 queue_context
248 );
249 return _Thread_Wait_get_status( executing );
250}
251
254#ifdef __cplusplus
255}
256#endif
257
258#endif
259/* end of include file */
This header file provides interfaces of the Semaphore Handler which are used by the implementation an...
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
#define _ISR_Get_level()
Return current interrupt level.
Definition: isrlevel.h:147
void _CORE_semaphore_Initialize(CORE_semaphore_Control *the_semaphore, uint32_t initial_value)
Initializes the semaphore based on the parameters passed.
Definition: coresem.c:44
#define STATES_WAITING_FOR_SEMAPHORE
Definition: statesimpl.h:68
Status_Control
Status codes.
Definition: status.h:111
void _Thread_queue_Enqueue(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Blocks the thread and places it on the thread queue.
Definition: threadqenqueue.c:407
void _Thread_queue_Surrender_no_priority(Thread_queue_Queue *queue, Thread_queue_Heads *heads, Thread_queue_Context *queue_context, const Thread_queue_Operations *operations)
Surrenders the thread queue previously owned by the thread to the first enqueued thread.
Definition: threadqenqueue.c:739
Thread_Control * _Thread_queue_Flush_status_object_was_deleted(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Status object was deleted thread queue flush filter function.
Definition: threadqflush.c:60
size_t _Thread_queue_Flush_critical(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_queue_Flush_filter filter, Thread_queue_Context *queue_context)
Unblocks all threads enqueued on the thread queue.
Definition: threadqflush.c:86
This header file provides interfaces of the Object Handler which are only used by the implementation.
This header file provides the interfaces of the Operation Status Support.
This header file provides interfaces of the Thread States which are only used by the implementation.
Definition: coresem.h:64
Thread_queue_Control Wait_queue
Definition: coresem.h:68
uint32_t count
Definition: coresem.h:71
Thread queue context for the thread queue methods.
Definition: threadq.h:216
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:640
The thread queue operations are used to manage the threads of a thread queue.
Definition: threadq.h:554
Thread_queue_Heads * heads
The thread queue heads.
Definition: threadq.h:451
Definition: thread.h:837
Thread queue heads.
Definition: threadq.h:385
This header file provides the interfaces of the Thread Handler related to thread dispatching.
This header file provides interfaces of the Thread Handler which are only used by the implementation.
This header file provides interfaces of the Thread Queue Handler which are only used by the implement...