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