1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSScoreThreadQueue |
---|
5 | * |
---|
6 | * @brief This source file contains static assertions related to the Thread |
---|
7 | * Queue Handler, the definition of ::_Thread_queue_Object_name, and the |
---|
8 | * implementation of _Thread_queue_Acquire(), |
---|
9 | * _Thread_queue_Do_acquire_critical(), _Thread_queue_Initialize(), |
---|
10 | * _Thread_queue_MP_callout_do_nothing(), _Thread_queue_Object_initialize(), |
---|
11 | * _Thread_queue_Queue_get_name_and_id(), _Thread_queue_Release(), and |
---|
12 | * _Thread_queue_Release_critical(). |
---|
13 | */ |
---|
14 | |
---|
15 | /* |
---|
16 | * COPYRIGHT (c) 1989-2014. |
---|
17 | * On-Line Applications Research Corporation (OAR). |
---|
18 | * |
---|
19 | * The license and distribution terms for this file may be |
---|
20 | * found in the file LICENSE in this distribution or at |
---|
21 | * http://www.rtems.org/license/LICENSE. |
---|
22 | */ |
---|
23 | |
---|
24 | #ifdef HAVE_CONFIG_H |
---|
25 | #include "config.h" |
---|
26 | #endif |
---|
27 | |
---|
28 | #include <string.h> |
---|
29 | |
---|
30 | #include <rtems/score/threadqimpl.h> |
---|
31 | #include <rtems/score/rbtreeimpl.h> |
---|
32 | #include <rtems/score/threadimpl.h> |
---|
33 | |
---|
34 | RTEMS_STATIC_ASSERT( |
---|
35 | #if defined(RTEMS_SMP) |
---|
36 | offsetof( Thread_queue_Syslock_queue, Queue.Lock.next_ticket ) |
---|
37 | #else |
---|
38 | offsetof( Thread_queue_Syslock_queue, reserved[ 0 ] ) |
---|
39 | #endif |
---|
40 | == offsetof( struct _Thread_queue_Queue, _Lock._next_ticket ), |
---|
41 | THREAD_QUEUE_SYSLOCK_QUEUE_NEXT_TICKET |
---|
42 | ); |
---|
43 | |
---|
44 | RTEMS_STATIC_ASSERT( |
---|
45 | #if defined(RTEMS_SMP) |
---|
46 | offsetof( Thread_queue_Syslock_queue, Queue.Lock.now_serving ) |
---|
47 | #else |
---|
48 | offsetof( Thread_queue_Syslock_queue, reserved[ 1 ] ) |
---|
49 | #endif |
---|
50 | == offsetof( struct _Thread_queue_Queue, _Lock._now_serving ), |
---|
51 | THREAD_QUEUE_SYSLOCK_QUEUE_NOW_SERVING |
---|
52 | ); |
---|
53 | |
---|
54 | RTEMS_STATIC_ASSERT( |
---|
55 | offsetof( Thread_queue_Syslock_queue, Queue.heads ) |
---|
56 | == offsetof( struct _Thread_queue_Queue, _heads ), |
---|
57 | THREAD_QUEUE_SYSLOCK_QUEUE_HEADS |
---|
58 | ); |
---|
59 | |
---|
60 | RTEMS_STATIC_ASSERT( |
---|
61 | offsetof( Thread_queue_Syslock_queue, Queue.owner ) |
---|
62 | == offsetof( struct _Thread_queue_Queue, _owner ), |
---|
63 | THREAD_QUEUE_SYSLOCK_QUEUE_OWNER |
---|
64 | ); |
---|
65 | |
---|
66 | RTEMS_STATIC_ASSERT( |
---|
67 | offsetof( Thread_queue_Syslock_queue, Queue.name ) |
---|
68 | == offsetof( struct _Thread_queue_Queue, _name ), |
---|
69 | THREAD_QUEUE_SYSLOCK_QUEUE_NAME |
---|
70 | ); |
---|
71 | |
---|
72 | RTEMS_STATIC_ASSERT( |
---|
73 | sizeof( Thread_queue_Syslock_queue ) |
---|
74 | == sizeof( struct _Thread_queue_Queue ), |
---|
75 | THREAD_QUEUE_SYSLOCK_QUEUE_SIZE |
---|
76 | ); |
---|
77 | |
---|
78 | #if defined(RTEMS_SMP) |
---|
79 | void _Thread_queue_Do_acquire_critical( |
---|
80 | Thread_queue_Control *the_thread_queue, |
---|
81 | ISR_lock_Context *lock_context |
---|
82 | ) |
---|
83 | { |
---|
84 | _Thread_queue_Queue_acquire_critical( |
---|
85 | &the_thread_queue->Queue, |
---|
86 | &the_thread_queue->Lock_stats, |
---|
87 | lock_context |
---|
88 | ); |
---|
89 | #if defined(RTEMS_DEBUG) |
---|
90 | the_thread_queue->owner = _SMP_lock_Who_am_I(); |
---|
91 | #endif |
---|
92 | } |
---|
93 | |
---|
94 | void _Thread_queue_Acquire( |
---|
95 | Thread_queue_Control *the_thread_queue, |
---|
96 | Thread_queue_Context *queue_context |
---|
97 | ) |
---|
98 | { |
---|
99 | _ISR_lock_ISR_disable( &queue_context->Lock_context.Lock_context ); |
---|
100 | _Thread_queue_Queue_acquire_critical( |
---|
101 | &the_thread_queue->Queue, |
---|
102 | &the_thread_queue->Lock_stats, |
---|
103 | &queue_context->Lock_context.Lock_context |
---|
104 | ); |
---|
105 | #if defined(RTEMS_DEBUG) |
---|
106 | the_thread_queue->owner = _SMP_lock_Who_am_I(); |
---|
107 | #endif |
---|
108 | } |
---|
109 | |
---|
110 | void _Thread_queue_Do_release_critical( |
---|
111 | Thread_queue_Control *the_thread_queue, |
---|
112 | ISR_lock_Context *lock_context |
---|
113 | ) |
---|
114 | { |
---|
115 | #if defined(RTEMS_DEBUG) |
---|
116 | _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) ); |
---|
117 | the_thread_queue->owner = SMP_LOCK_NO_OWNER; |
---|
118 | #endif |
---|
119 | _Thread_queue_Queue_release_critical( |
---|
120 | &the_thread_queue->Queue, |
---|
121 | lock_context |
---|
122 | ); |
---|
123 | } |
---|
124 | |
---|
125 | void _Thread_queue_Release( |
---|
126 | Thread_queue_Control *the_thread_queue, |
---|
127 | Thread_queue_Context *queue_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 | &queue_context->Lock_context.Lock_context |
---|
137 | ); |
---|
138 | _ISR_lock_ISR_enable( &queue_context->Lock_context.Lock_context ); |
---|
139 | } |
---|
140 | #endif |
---|
141 | |
---|
142 | const char _Thread_queue_Object_name[] = { '\0' }; |
---|
143 | |
---|
144 | void _Thread_queue_Initialize( |
---|
145 | Thread_queue_Control *the_thread_queue, |
---|
146 | const char *name |
---|
147 | ) |
---|
148 | { |
---|
149 | _Thread_queue_Queue_initialize( &the_thread_queue->Queue, name ); |
---|
150 | #if defined(RTEMS_SMP) |
---|
151 | _SMP_lock_Stats_initialize( &the_thread_queue->Lock_stats, "Thread Queue" ); |
---|
152 | #endif |
---|
153 | } |
---|
154 | |
---|
155 | void _Thread_queue_Object_initialize( Thread_queue_Control *the_thread_queue ) |
---|
156 | { |
---|
157 | _Thread_queue_Initialize( the_thread_queue, _Thread_queue_Object_name ); |
---|
158 | } |
---|
159 | |
---|
160 | #if defined(RTEMS_MULTIPROCESSING) |
---|
161 | void _Thread_queue_MP_callout_do_nothing( |
---|
162 | Thread_Control *the_proxy, |
---|
163 | Objects_Id mp_id |
---|
164 | ) |
---|
165 | { |
---|
166 | /* Do nothing */ |
---|
167 | } |
---|
168 | #endif |
---|
169 | |
---|
170 | size_t _Thread_queue_Queue_get_name_and_id( |
---|
171 | const Thread_queue_Queue *queue, |
---|
172 | char *buffer, |
---|
173 | size_t buffer_size, |
---|
174 | Objects_Id *id |
---|
175 | ) |
---|
176 | { |
---|
177 | const char *name; |
---|
178 | |
---|
179 | name = queue->name; |
---|
180 | |
---|
181 | if ( name == _Thread_queue_Object_name ) { |
---|
182 | const Thread_queue_Object *queue_object; |
---|
183 | |
---|
184 | queue_object = THREAD_QUEUE_QUEUE_TO_OBJECT( queue ); |
---|
185 | *id = queue_object->Object.id; |
---|
186 | return _Objects_Name_to_string( |
---|
187 | queue_object->Object.name, |
---|
188 | false, |
---|
189 | buffer, |
---|
190 | buffer_size |
---|
191 | ); |
---|
192 | } else { |
---|
193 | if ( name == NULL ) { |
---|
194 | name = _Thread_queue_Object_name; |
---|
195 | } |
---|
196 | |
---|
197 | *id = 0; |
---|
198 | return strlcpy( buffer, name, buffer_size ); |
---|
199 | } |
---|
200 | } |
---|