RTEMS
threadq.c
Go to the documentation of this file.
1 
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 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <string.h>
22 
24 #include <rtems/score/rbtreeimpl.h>
25 #include <rtems/score/threadimpl.h>
26 
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 
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 
48  offsetof( Thread_queue_Syslock_queue, Queue.heads )
49  == offsetof( struct _Thread_queue_Queue, _heads ),
50  THREAD_QUEUE_SYSLOCK_QUEUE_HEADS
51 );
52 
54  offsetof( Thread_queue_Syslock_queue, Queue.owner )
55  == offsetof( struct _Thread_queue_Queue, _owner ),
56  THREAD_QUEUE_SYSLOCK_QUEUE_OWNER
57 );
58 
60  offsetof( Thread_queue_Syslock_queue, Queue.name )
61  == offsetof( struct _Thread_queue_Queue, _name ),
62  THREAD_QUEUE_SYSLOCK_QUEUE_NAME
63 );
64 
67  == sizeof( struct _Thread_queue_Queue ),
68  THREAD_QUEUE_SYSLOCK_QUEUE_SIZE
69 );
70 
71 #if defined(RTEMS_SMP)
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 
88  Thread_queue_Control *the_thread_queue,
89  Thread_queue_Context *queue_context
90 )
91 {
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 
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
113  &the_thread_queue->Queue,
114  lock_context
115  );
116 }
117 
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
128  &the_thread_queue->Queue,
129  &queue_context->Lock_context.Lock_context
130  );
132 }
133 #endif
134 
135 const char _Thread_queue_Object_name[] = { '\0' };
136 
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 
149 {
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 
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;
180  queue_object->Object.name,
181  false,
182  buffer,
183  buffer_size
184  );
185  } else {
186  if ( name == NULL ) {
188  }
189 
190  *id = 0;
191  return strlcpy( buffer, name, buffer_size );
192  }
193 }
void _Thread_queue_Initialize(Thread_queue_Control *the_thread_queue, const char *name)
Initializes the thread queue control to the given name.
Definition: threadq.c:137
Thread queue context for the thread queue methods.
Definition: threadq.h:198
void _Thread_queue_Acquire(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Acquires the thread queue control in a critical section.
Definition: threadq.c:87
size_t _Objects_Name_to_string(Objects_Name name, bool is_string, char *buffer, size_t buffer_size)
Converts the specified object name to a text representation.
static __inline__ void _Thread_queue_Queue_initialize(Thread_queue_Queue *queue, const char *name)
Initializes the thread queue queue with the given name.
Definition: threadqimpl.h:547
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:416
static __inline__ void _Thread_queue_Queue_release_critical(Thread_queue_Queue *queue, ISR_lock_Context *lock_context)
Releases the thread queue queue in a critical section.
Definition: threadqimpl.h:603
void _Thread_queue_Object_initialize(Thread_queue_Control *the_thread_queue)
Initializes a thread queue embedded in an object with identifier.
Definition: threadq.c:148
size_t _Thread_queue_Queue_get_name_and_id(const Thread_queue_Queue *queue, char *buffer, size_t buffer_size, Objects_Id *id)
Copies the thread queue name to the specified buffer.
Definition: threadq.c:163
void _Thread_queue_Do_acquire_critical(Thread_queue_Control *the_thread_queue, ISR_lock_Context *lock_context)
Acquires the thread queue control in a critical section.
Definition: threadq.c:72
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:583
Thread queue with a layout compatible to struct _Thread_queue_Queue defined in Newlib <sys/lock...
Definition: threadqimpl.h:54
const char * name
The thread queue name.
Definition: threadq.h:436
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:203
Constants and Structures Associated with the Manipulation of Objects.
#define RTEMS_STATIC_ASSERT(_cond, _msg)
Asserts at compile time that the specified condition is satisfied.
Definition: basedefs.h:838
Inlined Routines Associated with Red-Black Trees.
void _Thread_queue_Do_release_critical(Thread_queue_Control *the_thread_queue, ISR_lock_Context *lock_context)
Checks if the thread queue control is the owner of the lock.
Definition: threadq.c:103
const char _Thread_queue_Object_name[]
The special thread queue name to indicated that the thread queue is embedded in an object with identi...
Definition: threadq.c:135
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:392
Inlined Routines from the Thread Handler.
uint32_t Objects_Id
Definition: object.h:80
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Objects_Name name
Definition: objectdata.h:45
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:130
void _Thread_queue_Release(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Releases the thread queue control and enables interrupts.
Definition: threadq.c:118
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
Helper structure to ensure that all objects containing a thread queue have the right layout...
Definition: threadqimpl.h:1445
Objects_Id id
Definition: objectdata.h:43