19 #ifndef _RTEMS_SCORE_THREADQIMPL_H 20 #define _RTEMS_SCORE_THREADQIMPL_H 24 #include <rtems/score/priorityimpl.h> 27 #include <rtems/score/status.h> 29 #include <rtems/score/threaddispatch.h> 31 #if defined(RTEMS_DEBUG) 44 #define THREAD_QUEUE_LINK_OF_PATH_NODE( node ) \ 45 RTEMS_CONTAINER_OF( node, Thread_queue_Link, Path_node ); 52 #if !defined(RTEMS_SMP) 59 unsigned int reserved[2];
65 void _Thread_queue_Enqueue_do_nothing_extra(
72 void _Thread_queue_Add_timeout_ticks(
79 void _Thread_queue_Add_timeout_monotonic_timespec(
86 void _Thread_queue_Add_timeout_realtime_timespec(
112 #if defined(RTEMS_DEBUG) 113 memset( queue_context, 0x7f,
sizeof( *queue_context ) );
114 #if defined(RTEMS_SMP) 120 (void) queue_context;
205 queue_context->
enqueue_callout = _Thread_queue_Enqueue_do_nothing_extra;
239 const struct timespec *abstime
244 _Thread_queue_Add_timeout_monotonic_timespec;
259 const struct timespec *abstime
263 queue_context->
enqueue_callout = _Thread_queue_Add_timeout_realtime_timespec;
318 _Assert( n < RTEMS_ARRAY_SIZE( queue_context->
Priority.
update ) );
324 #define _Thread_queue_Context_ISR_disable( queue_context, level ) \ 326 _ISR_Local_disable( level ); \ 327 _ISR_lock_ISR_disable_profile( \ 328 &( queue_context )->Lock_context.Lock_context \ 361 #if defined(RTEMS_MULTIPROCESSING) 364 Thread_queue_MP_callout mp_callout
367 queue_context->mp_callout = mp_callout;
370 #define _Thread_queue_Context_set_MP_callout( queue_context, mp_callout ) \ 372 (void) queue_context; \ 376 #if defined(RTEMS_SMP) 378 Thread_queue_Gate *gate
381 _Atomic_Store_uint( &gate->go_ahead, 0, ATOMIC_ORDER_RELAXED );
386 Thread_queue_Gate *gate
393 Thread_queue_Gate *gate
396 _Atomic_Store_uint( &gate->go_ahead, 1, ATOMIC_ORDER_RELAXED );
400 Thread_queue_Gate *gate
403 while ( _Atomic_Load_uint( &gate->go_ahead, ATOMIC_ORDER_RELAXED ) == 0 ) {
413 #if defined(RTEMS_SMP) 432 #if defined(RTEMS_SMP) 433 _SMP_ticket_lock_Initialize( &queue->Lock );
442 #
if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
443 SMP_lock_Stats *lock_stats,
448 #if defined(RTEMS_SMP) 449 _SMP_ticket_lock_Acquire(
452 &lock_context->Lock_context.Stats_context
460 #if defined(RTEMS_SMP) && defined( RTEMS_PROFILING ) 462 _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \ 463 _Thread_queue_Queue_do_acquire_critical( queue, lock_stats, lock_context ) 466 _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \ 467 _Thread_queue_Queue_do_acquire_critical( queue, lock_context ) 475 #if defined(RTEMS_SMP) 476 _SMP_ticket_lock_Release(
478 &lock_context->Lock_context.Stats_context
491 _Thread_queue_Queue_release_critical( queue, lock_context );
514 #if defined(RTEMS_SMP) 515 void _Thread_queue_Do_acquire_critical(
525 (void) the_thread_queue;
535 _Thread_queue_Do_acquire_critical(
541 #if defined(RTEMS_SMP) 542 void _Thread_queue_Acquire(
552 (void) the_thread_queue;
557 #if defined(RTEMS_DEBUG) 562 #if defined(RTEMS_SMP) 563 return the_thread_queue->owner == _SMP_lock_Who_am_I();
570 #if defined(RTEMS_SMP) 571 void _Thread_queue_Do_release_critical(
581 (void) the_thread_queue;
583 _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) );
592 _Thread_queue_Do_release_critical(
598 #if defined(RTEMS_SMP) 599 void _Thread_queue_Release(
609 (void) the_thread_queue;
610 _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) );
618 #
if defined(RTEMS_MULTIPROCESSING)
620 Thread_queue_MP_callout mp_callout
635 #if defined(RTEMS_MULTIPROCESSING) 636 #define _Thread_queue_Dequeue( \ 641 _Thread_queue_Do_dequeue( \ 647 #define _Thread_queue_Dequeue( \ 652 _Thread_queue_Do_dequeue( \ 742 #if defined(RTEMS_SMP) 765 Status_Control _Thread_queue_Enqueue_sticky(
920 #if defined(RTEMS_SMP) 941 void _Thread_queue_Surrender_sticky(
978 if ( heads !=
NULL ) {
979 return ( *operations->
first )( heads );
1105 void _Thread_queue_Initialize(
1110 #if defined(RTEMS_SMP) && defined(RTEMS_DEBUG) && defined(RTEMS_PROFILING) 1111 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1113 .Lock_stats = SMP_LOCK_STATS_INITIALIZER( _name ), \ 1114 .owner = SMP_LOCK_NO_OWNER, \ 1116 .Lock = SMP_TICKET_LOCK_INITIALIZER, \ 1122 #elif defined(RTEMS_SMP) && defined(RTEMS_DEBUG) 1123 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1125 .owner = SMP_LOCK_NO_OWNER, \ 1127 .Lock = SMP_TICKET_LOCK_INITIALIZER, \ 1133 #elif defined(RTEMS_SMP) && defined(RTEMS_PROFILING) 1134 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1136 .Lock_stats = SMP_LOCK_STATS_INITIALIZER( _name ), \ 1138 .Lock = SMP_TICKET_LOCK_INITIALIZER, \ 1144 #elif defined(RTEMS_SMP) 1145 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1148 .Lock = SMP_TICKET_LOCK_INITIALIZER, \ 1155 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1169 #if defined(RTEMS_SMP) 1170 _SMP_ticket_lock_Destroy( &the_thread_queue->
Queue.Lock );
1171 _SMP_lock_Stats_destroy( &the_thread_queue->Lock_stats );
1175 #if defined(RTEMS_MULTIPROCESSING) 1176 void _Thread_queue_MP_callout_do_nothing(
1181 void _Thread_queue_Unblock_proxy(
1187 #if defined(RTEMS_SMP) 1188 bool _Thread_queue_Path_acquire_critical(
1194 void _Thread_queue_Path_release_critical(
1210 #define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member, msg ) \ 1211 RTEMS_STATIC_ASSERT( \ 1212 offsetof( object_type, wait_queue_member ) \ 1213 == offsetof( Thread_queue_Object, Wait_queue ) \ 1214 && RTEMS_HAVE_MEMBER_SAME_TYPE( \ 1216 wait_queue_member, \ 1217 Thread_queue_Object, \ 1223 #define THREAD_QUEUE_QUEUE_TO_OBJECT( queue ) \ 1224 RTEMS_CONTAINER_OF( \ 1226 Thread_queue_Object, \ Watchdog_Interval ticks
The timeout in ticks.
Definition: threadq.h:227
Thread_Control * owner
The thread queue owner.
Definition: threadq.h:426
RTEMS_INLINE_ROUTINE void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Append a node (unprotected).
Definition: chainimpl.h:679
SuperCore SMP Support API.
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
union Thread_queue_Context::@3980 Timeout
Interval to wait.
Definition: objectdata.h:39
RTEMS_INLINE_ROUTINE Thread_Control * _Thread_queue_First_locked(Thread_queue_Control *the_thread_queue, const Thread_queue_Operations *operations)
Returns the first thread on the thread queue if it exists, otherwise NULL.
Definition: threadqimpl.h:971
Thread queue context for the thread queue methods.
Definition: threadq.h:193
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
Thread_Control * update[2]
Threads to update the priority via _Thread_Priority_update().
Definition: threadq.h:288
void _Thread_queue_Extract(Thread_Control *the_thread)
Extracts thread from thread queue.
Definition: threadqenqueue.c:623
Thread_queue_Enqueue_callout enqueue_callout
The enqueue callout for _Thread_queue_Enqueue().
Definition: threadq.h:216
Thread_Control *(* Thread_queue_Flush_filter)(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Thread queue flush filter function.
Definition: threadqimpl.h:1021
Thread_queue_Deadlock_callout deadlock_callout
Invoked in case of a detected deadlock.
Definition: threadq.h:299
Thread_Control * _Thread_queue_Flush_default_filter(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Default thread queue flush filter function.
Definition: threadqflush.c:25
Thread_Control * _Thread_queue_Flush_status_object_was_deleted(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Status object was deleted thread queue flush filter function.
Definition: threadqflush.c:36
Definition: threadq.h:547
void _Thread_queue_Enqueue(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Blocks the thread and places it on the thread queue.
Definition: threadqenqueue.c:379
Thread_Control * _Thread_queue_First(Thread_queue_Control *the_thread_queue, const Thread_queue_Operations *operations)
Returns the first thread on the thread queue if it exists, otherwise NULL.
Definition: threadqfirst.c:23
#define _ISR_Get_level()
Return current interrupt level.
Definition: isrlevel.h:125
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_timeout_ticks(Thread_queue_Context *queue_context, Watchdog_Interval ticks)
Sets the timeout ticks in the thread queue context.
Definition: threadqimpl.h:151
Thread_queue_First_operation first
Thread queue first operation.
Definition: threadq.h:540
void(* Thread_queue_Deadlock_callout)(Thread_Control *the_thread)
Thread queue deadlock callout.
Definition: threadq.h:81
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_enqueue_callout(Thread_queue_Context *queue_context, Thread_queue_Enqueue_callout enqueue_callout)
Sets the enqueue callout in the thread queue context.
Definition: threadqimpl.h:185
Thread_queue_Priority_queue Priority
This is the set of threads for priority discipline waiting.
Definition: threadq.h:373
RTEMS_INLINE_ROUTINE void _Chain_Initialize_empty(Chain_Control *the_chain)
Initialize this chain as empty.
Definition: chainimpl.h:504
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_timeout_argument(Thread_queue_Context *queue_context, const void *arg)
Sets the timeout argument in the thread queue context.
Definition: threadqimpl.h:168
Constants and Structures Needed to Declare a Thread Queue.
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_deadlock_callout(Thread_queue_Context *queue_context, Thread_queue_Deadlock_callout deadlock_callout)
Sets the deadlock callout in the thread queue context.
Definition: threadqimpl.h:280
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_initialize(Thread_queue_Context *queue_context)
Initializes a thread queue context.
Definition: threadqimpl.h:108
Definition: threadq.h:397
void _Thread_queue_Surrender(Thread_queue_Queue *queue, Thread_queue_Heads *heads, Thread_Control *previous_owner, Thread_queue_Context *queue_context, const Thread_queue_Operations *operations)
Surrenders the thread queue previously owned by the thread to the first enqueued thread.
Definition: threadqenqueue.c:659
Thread queue operations.
Definition: threadq.h:512
size_t update_count
Count of threads to update the priority via _Thread_Priority_update().
Definition: threadq.h:279
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_enqueue_do_nothing_extra(Thread_queue_Context *queue_context)
Sets the do nothing enqueue callout in the thread queue context.
Definition: threadqimpl.h:201
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:578
Thread_queue_Heads * heads
Lock to protect this thread queue.
Definition: threadq.h:421
Thread queue heads.
Definition: threadq.h:355
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
Chain_Control Free_chain
A chain with free thread queue heads providing the spare thread queue heads for a thread once it is d...
Definition: threadq.h:381
Priority_Aggregation Queue
The actual thread priority queue.
Definition: threadq.h:333
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:383
uint32_t ISR_Level
Definition: isrlevel.h:38
Thread queue with a layout compatible to struct _Thread_queue_Queue defined in Newlib <sys/lock...
Definition: threadqimpl.h:51
size_t _Thread_queue_Flush_critical(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_queue_Flush_filter filter, Thread_queue_Context *queue_context)
Unblocks all threads enqueued on the thread queue.
Definition: threadqflush.c:62
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:404
Per CPU Core Structure.
Definition: percpu.h:290
struct Thread_queue_Context::@3981 Priority
Block to manage thread priority changes due to a thread queue operation.
const char * name
The thread queue name.
Definition: threadq.h:431
void _Thread_queue_Extract_critical(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Extracts the thread from the thread queue and unblocks it.
Definition: threadqenqueue.c:599
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:198
void(* Thread_queue_Enqueue_callout)(Thread_queue_Queue *queue, Thread_Control *the_thread, struct Per_CPU_Control *cpu_self, Thread_queue_Context *queue_context)
Thread queue enqueue callout.
Definition: threadq.h:67
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(Thread_queue_Context *queue_context, const struct timespec *abstime)
Sets the enqueue callout to add an absolute monotonic timeout in timespec format. ...
Definition: threadqimpl.h:237
bool _Thread_queue_Extract_locked(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Extracts the thread from the thread queue, restores the default wait operations and restores the defa...
Definition: threadqenqueue.c:564
RTEMS_INLINE_ROUTINE void _Chain_Initialize_node(Chain_Node *the_node)
Initializes a chain node.
Definition: chainimpl.h:119
Thread_Control * _Thread_queue_Flush_status_unavailable(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Status unavailable thread queue flush filter function.
Definition: threadqflush.c:49
void _Thread_queue_Deadlock_fatal(Thread_Control *the_thread)
Results in an INTERNAL_ERROR_THREAD_QUEUE_DEADLOCK fatal error.
Definition: threadqenqueue.c:374
uint32_t States_Control
Definition: states.h:41
States_Control thread_state
The thread state for _Thread_queue_Enqueue().
Definition: threadq.h:203
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
Definition: watchdogticks.h:36
RTEMS_INLINE_ROUTINE void _ISR_lock_Context_set_level(ISR_lock_Context *context, ISR_Level level)
Sets the ISR level in the ISR lock context.
Definition: isrlock.h:159
Chain_Node Free_node
A chain node to add these thread queue heads to the free chain of the thread queue heads dedicated to...
Definition: threadq.h:387
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
const Scheduler_Control _Scheduler_Table[]
Registered schedulers.
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_thread_state(Thread_queue_Context *queue_context, States_Control thread_state)
Sets the thread state for the thread to enqueue in the thread queue context.
Definition: threadqimpl.h:134
const void * arg
The timeout argument, e.g. pointer to struct timespec.
Definition: threadq.h:232
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_enqueue_timeout_ticks(Thread_queue_Context *queue_context, Watchdog_Interval ticks)
Sets the enqueue callout to add a relative monotonic timeout in ticks.
Definition: threadqimpl.h:218
RTEMS_INLINE_ROUTINE Per_CPU_Control * _Thread_Dispatch_disable_critical(const ISR_lock_Context *lock_context)
Disables thread dispatching inside a critical section (interrupts disabled).
Definition: threaddispatch.h:175
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:125
#define _Thread_queue_Context_set_MP_callout(queue_context, mp_callout)
Sets the MP callout in the thread queue context.
Definition: threadqimpl.h:370
void _Thread_queue_Unblock_critical(bool unblock, Thread_queue_Queue *queue, Thread_Control *the_thread, ISR_lock_Context *lock_context)
Unblocks the thread which was on the thread queue before.
Definition: threadqenqueue.c:578
uint32_t Objects_Id
Definition: object.h:75
void _Thread_queue_Extract_with_proxy(Thread_Control *the_thread)
Extracts the_thread from the_thread_queue.
Definition: threadqextractwithproxy.c:30
void _Thread_queue_Deadlock_status(Thread_Control *the_thread)
Sets the thread wait return code to STATUS_DEADLOCK.
Definition: threadqenqueue.c:369
Constants and Structures Associated with the Scheduler.
Constants and Structures Related with the Thread Control Block.
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_enqueue_timeout_realtime_timespec(Thread_queue_Context *queue_context, const struct timespec *abstime)
Sets the enqueue callout to add an absolute realtime timeout in timespec format.
Definition: threadqimpl.h:257
Helper structure to ensure that all objects containing a thread queue have the right layout...
Definition: threadqimpl.h:1205
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
#define _Scheduler_Count
Count of registered schedulers.
Definition: scheduler.h:314