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