1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSScoreThreadQueue |
---|
7 | * |
---|
8 | * @brief This source file contains static assertions related to the Thread |
---|
9 | * Queue Handler, the definition of ::_Thread_queue_Object_name, and the |
---|
10 | * implementation of _Thread_queue_Acquire(), |
---|
11 | * _Thread_queue_Do_acquire_critical(), _Thread_queue_Initialize(), |
---|
12 | * _Thread_queue_MP_callout_do_nothing(), _Thread_queue_Object_initialize(), |
---|
13 | * _Thread_queue_Queue_get_name_and_id(), _Thread_queue_Release(), and |
---|
14 | * _Thread_queue_Release_critical(). |
---|
15 | */ |
---|
16 | |
---|
17 | /* |
---|
18 | * COPYRIGHT (c) 1989-2014. |
---|
19 | * On-Line Applications Research Corporation (OAR). |
---|
20 | * |
---|
21 | * Redistribution and use in source and binary forms, with or without |
---|
22 | * modification, are permitted provided that the following conditions |
---|
23 | * are met: |
---|
24 | * 1. Redistributions of source code must retain the above copyright |
---|
25 | * notice, this list of conditions and the following disclaimer. |
---|
26 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
27 | * notice, this list of conditions and the following disclaimer in the |
---|
28 | * documentation and/or other materials provided with the distribution. |
---|
29 | * |
---|
30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
31 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
34 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
35 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
36 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
37 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
38 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
39 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
40 | * POSSIBILITY OF SUCH DAMAGE. |
---|
41 | */ |
---|
42 | |
---|
43 | #ifdef HAVE_CONFIG_H |
---|
44 | #include "config.h" |
---|
45 | #endif |
---|
46 | |
---|
47 | #include <rtems/score/threadqimpl.h> |
---|
48 | |
---|
49 | RTEMS_STATIC_ASSERT( |
---|
50 | #if defined(RTEMS_SMP) |
---|
51 | offsetof( Thread_queue_Syslock_queue, Queue.Lock.next_ticket ) |
---|
52 | #else |
---|
53 | offsetof( Thread_queue_Syslock_queue, reserved[ 0 ] ) |
---|
54 | #endif |
---|
55 | == offsetof( struct _Thread_queue_Queue, _Lock._next_ticket ), |
---|
56 | THREAD_QUEUE_SYSLOCK_QUEUE_NEXT_TICKET |
---|
57 | ); |
---|
58 | |
---|
59 | RTEMS_STATIC_ASSERT( |
---|
60 | #if defined(RTEMS_SMP) |
---|
61 | offsetof( Thread_queue_Syslock_queue, Queue.Lock.now_serving ) |
---|
62 | #else |
---|
63 | offsetof( Thread_queue_Syslock_queue, reserved[ 1 ] ) |
---|
64 | #endif |
---|
65 | == offsetof( struct _Thread_queue_Queue, _Lock._now_serving ), |
---|
66 | THREAD_QUEUE_SYSLOCK_QUEUE_NOW_SERVING |
---|
67 | ); |
---|
68 | |
---|
69 | RTEMS_STATIC_ASSERT( |
---|
70 | offsetof( Thread_queue_Syslock_queue, Queue.heads ) |
---|
71 | == offsetof( struct _Thread_queue_Queue, _heads ), |
---|
72 | THREAD_QUEUE_SYSLOCK_QUEUE_HEADS |
---|
73 | ); |
---|
74 | |
---|
75 | RTEMS_STATIC_ASSERT( |
---|
76 | offsetof( Thread_queue_Syslock_queue, Queue.owner ) |
---|
77 | == offsetof( struct _Thread_queue_Queue, _owner ), |
---|
78 | THREAD_QUEUE_SYSLOCK_QUEUE_OWNER |
---|
79 | ); |
---|
80 | |
---|
81 | RTEMS_STATIC_ASSERT( |
---|
82 | offsetof( Thread_queue_Syslock_queue, Queue.name ) |
---|
83 | == offsetof( struct _Thread_queue_Queue, _name ), |
---|
84 | THREAD_QUEUE_SYSLOCK_QUEUE_NAME |
---|
85 | ); |
---|
86 | |
---|
87 | RTEMS_STATIC_ASSERT( |
---|
88 | sizeof( Thread_queue_Syslock_queue ) |
---|
89 | == sizeof( struct _Thread_queue_Queue ), |
---|
90 | THREAD_QUEUE_SYSLOCK_QUEUE_SIZE |
---|
91 | ); |
---|
92 | |
---|
93 | #if defined(RTEMS_SMP) |
---|
94 | void _Thread_queue_Do_acquire_critical( |
---|
95 | Thread_queue_Control *the_thread_queue, |
---|
96 | ISR_lock_Context *lock_context |
---|
97 | ) |
---|
98 | { |
---|
99 | _Thread_queue_Queue_acquire_critical( |
---|
100 | &the_thread_queue->Queue, |
---|
101 | &the_thread_queue->Lock_stats, |
---|
102 | lock_context |
---|
103 | ); |
---|
104 | #if defined(RTEMS_DEBUG) |
---|
105 | the_thread_queue->owner = _SMP_lock_Who_am_I(); |
---|
106 | #endif |
---|
107 | } |
---|
108 | |
---|
109 | void _Thread_queue_Acquire( |
---|
110 | Thread_queue_Control *the_thread_queue, |
---|
111 | Thread_queue_Context *queue_context |
---|
112 | ) |
---|
113 | { |
---|
114 | _ISR_lock_ISR_disable( &queue_context->Lock_context.Lock_context ); |
---|
115 | _Thread_queue_Queue_acquire_critical( |
---|
116 | &the_thread_queue->Queue, |
---|
117 | &the_thread_queue->Lock_stats, |
---|
118 | &queue_context->Lock_context.Lock_context |
---|
119 | ); |
---|
120 | #if defined(RTEMS_DEBUG) |
---|
121 | the_thread_queue->owner = _SMP_lock_Who_am_I(); |
---|
122 | #endif |
---|
123 | } |
---|
124 | |
---|
125 | void _Thread_queue_Do_release_critical( |
---|
126 | Thread_queue_Control *the_thread_queue, |
---|
127 | ISR_lock_Context *lock_context |
---|
128 | ) |
---|
129 | { |
---|
130 | #if defined(RTEMS_DEBUG) |
---|
131 | _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) ); |
---|
132 | the_thread_queue->owner = SMP_LOCK_NO_OWNER; |
---|
133 | #endif |
---|
134 | _Thread_queue_Queue_release_critical( |
---|
135 | &the_thread_queue->Queue, |
---|
136 | lock_context |
---|
137 | ); |
---|
138 | } |
---|
139 | |
---|
140 | void _Thread_queue_Release( |
---|
141 | Thread_queue_Control *the_thread_queue, |
---|
142 | Thread_queue_Context *queue_context |
---|
143 | ) |
---|
144 | { |
---|
145 | #if defined(RTEMS_DEBUG) |
---|
146 | _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) ); |
---|
147 | the_thread_queue->owner = SMP_LOCK_NO_OWNER; |
---|
148 | #endif |
---|
149 | _Thread_queue_Queue_release_critical( |
---|
150 | &the_thread_queue->Queue, |
---|
151 | &queue_context->Lock_context.Lock_context |
---|
152 | ); |
---|
153 | _ISR_lock_ISR_enable( &queue_context->Lock_context.Lock_context ); |
---|
154 | } |
---|
155 | #endif |
---|
156 | |
---|
157 | const char _Thread_queue_Object_name[] = { '\0' }; |
---|
158 | |
---|
159 | void _Thread_queue_Initialize( |
---|
160 | Thread_queue_Control *the_thread_queue, |
---|
161 | const char *name |
---|
162 | ) |
---|
163 | { |
---|
164 | _Thread_queue_Queue_initialize( &the_thread_queue->Queue, name ); |
---|
165 | #if defined(RTEMS_SMP) |
---|
166 | _SMP_lock_Stats_initialize( &the_thread_queue->Lock_stats, "Thread Queue" ); |
---|
167 | #endif |
---|
168 | } |
---|
169 | |
---|
170 | void _Thread_queue_Object_initialize( Thread_queue_Control *the_thread_queue ) |
---|
171 | { |
---|
172 | _Thread_queue_Initialize( the_thread_queue, _Thread_queue_Object_name ); |
---|
173 | } |
---|
174 | |
---|
175 | #if defined(RTEMS_MULTIPROCESSING) |
---|
176 | void _Thread_queue_MP_callout_do_nothing( |
---|
177 | Thread_Control *the_proxy, |
---|
178 | Objects_Id mp_id |
---|
179 | ) |
---|
180 | { |
---|
181 | /* Do nothing */ |
---|
182 | (void) the_proxy; |
---|
183 | (void) mp_id; |
---|
184 | } |
---|
185 | #endif |
---|