38#ifndef _RTEMS_SCORE_THREADQIMPL_H
39#define _RTEMS_SCORE_THREADQIMPL_H
50#if defined(RTEMS_DEBUG)
64#define THREAD_QUEUE_LINK_OF_PATH_NODE( node ) \
65 RTEMS_CONTAINER_OF( node, Thread_queue_Link, Path_node );
72#if !defined(RTEMS_SMP)
79 unsigned int reserved[2];
95 Thread_Control *the_thread,
110 Thread_Control *the_thread,
127 Thread_Control *the_thread,
144 Thread_Control *the_thread,
169static inline void _Thread_queue_Context_initialize(
173#if defined(RTEMS_DEBUG)
174 memset( queue_context, 0x7f,
sizeof( *queue_context ) );
175#if defined(RTEMS_SMP)
176 _Chain_Initialize_node( &queue_context->
Lock_context.Wait.Gate.Node );
181 (void) queue_context;
195_Thread_queue_Context_set_thread_state(
212_Thread_queue_Context_set_timeout_ticks(
217 queue_context->Timeout.ticks = ticks;
233_Thread_queue_Context_set_timeout_argument(
239 queue_context->Timeout.arg = arg;
252_Thread_queue_Context_set_enqueue_callout(
268_Thread_queue_Context_set_enqueue_do_nothing_extra(
285_Thread_queue_Context_set_enqueue_timeout_ticks(
290 queue_context->Timeout.ticks = ticks;
308_Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(
310 const struct timespec *timeout,
314 queue_context->Timeout.arg = timeout;
334_Thread_queue_Context_set_enqueue_timeout_realtime_timespec(
336 const struct timespec *timeout,
340 queue_context->Timeout.arg = timeout;
359static inline void _Thread_queue_Context_set_deadlock_callout(
373static inline void _Thread_queue_Context_clear_priority_updates(
377 queue_context->Priority.update_count = 0;
388static inline size_t _Thread_queue_Context_get_priority_updates(
392 return queue_context->Priority.update_count;
402static inline void _Thread_queue_Context_restore_priority_updates(
407 queue_context->Priority.update_count = update_count;
418static inline void _Thread_queue_Context_add_priority_update(
420 Thread_Control *the_thread
425 n = queue_context->Priority.update_count;
428 queue_context->Priority.update_count = n + 1;
429 queue_context->Priority.update[ n ] = the_thread;
432#define _Thread_queue_Context_ISR_disable( queue_context, level ) \
434 _ISR_Local_disable( level ); \
435 _ISR_lock_ISR_disable_profile( \
436 &( queue_context )->Lock_context.Lock_context \
446static inline void _Thread_queue_Context_set_ISR_level(
451 _ISR_lock_Context_set_level(
468 return _Thread_Dispatch_disable_critical(
482#if defined(RTEMS_MULTIPROCESSING)
485 Thread_queue_MP_callout mp_callout
488 queue_context->mp_callout = mp_callout;
491#define _Thread_queue_Context_set_MP_callout( queue_context, mp_callout ) \
493 (void) queue_context; \
497#if defined(RTEMS_SMP)
503static inline void _Thread_queue_Gate_close(
504 Thread_queue_Gate *gate
507 _Atomic_Store_uint( &gate->go_ahead, 0, ATOMIC_ORDER_RELAXED );
516static inline void _Thread_queue_Gate_add(
518 Thread_queue_Gate *gate
521 _Chain_Append_unprotected( chain, &gate->Node );
529static inline void _Thread_queue_Gate_open(
530 Thread_queue_Gate *gate
533 _Atomic_Store_uint( &gate->go_ahead, 1, ATOMIC_ORDER_RELAXED );
543static inline void _Thread_queue_Gate_wait(
544 Thread_queue_Gate *gate
547 while ( _Atomic_Load_uint( &gate->go_ahead, ATOMIC_ORDER_RELAXED ) == 0 ) {
558static inline void _Thread_queue_Heads_initialize(
562#if defined(RTEMS_SMP)
566 _Chain_Initialize_node( &heads->Priority[ i ].Node );
567 _Priority_Initialize_empty( &heads->Priority[ i ].Queue );
572 _Chain_Initialize_empty( &heads->
Free_chain );
573 _Chain_Initialize_node( &heads->
Free_node );
582static inline void _Thread_queue_Queue_initialize(
587#if defined(RTEMS_SMP)
588 _SMP_ticket_lock_Initialize( &queue->Lock );
602static inline void _Thread_queue_Queue_do_acquire_critical(
604#
if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
605 SMP_lock_Stats *lock_stats,
610#if defined(RTEMS_SMP)
611 _SMP_ticket_lock_Acquire(
614 &lock_context->Lock_context.Stats_context
622#if defined(RTEMS_SMP) && defined( RTEMS_PROFILING )
624 _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \
625 _Thread_queue_Queue_do_acquire_critical( queue, lock_stats, lock_context )
628 _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \
629 _Thread_queue_Queue_do_acquire_critical( queue, lock_context )
638static inline void _Thread_queue_Queue_release_critical(
643#if defined(RTEMS_SMP)
644 _SMP_ticket_lock_Release(
646 &lock_context->Lock_context.Stats_context
660static inline void _Thread_queue_Queue_release(
665 _Thread_queue_Queue_release_critical( queue, lock_context );
694#if defined(RTEMS_SMP)
695void _Thread_queue_Do_acquire_critical(
700static inline void _Thread_queue_Do_acquire_critical(
705 (void) the_thread_queue;
716static inline void _Thread_queue_Acquire_critical(
721 _Thread_queue_Do_acquire_critical(
733#if defined(RTEMS_SMP)
734void _Thread_queue_Acquire(
739static inline void _Thread_queue_Acquire(
744 (void) the_thread_queue;
757#if defined(RTEMS_DEBUG)
758static inline bool _Thread_queue_Is_lock_owner(
762#if defined(RTEMS_SMP)
763 return the_thread_queue->owner == _SMP_lock_Who_am_I();
776#if defined(RTEMS_SMP)
777void _Thread_queue_Do_release_critical(
782static inline void _Thread_queue_Do_release_critical(
787 (void) the_thread_queue;
789 _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) );
799static inline void _Thread_queue_Release_critical(
804 _Thread_queue_Do_release_critical(
816#if defined(RTEMS_SMP)
817void _Thread_queue_Release(
822static inline void _Thread_queue_Release(
827 (void) the_thread_queue;
828 _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) );
913 Thread_Control *the_thread,
917#if defined(RTEMS_SMP)
943 Thread_Control *the_thread,
970 Thread_Control *the_thread,
990 Thread_Control *the_thread,
1024 Thread_Control *previous_owner,
1066 Thread_Control *executing,
1072#if defined(RTEMS_SMP)
1093void _Thread_queue_Surrender_sticky(
1096 Thread_Control *previous_owner,
1110static inline bool _Thread_queue_Is_empty(
1114 return queue->
heads == NULL;
1153typedef Thread_Control *( *Thread_queue_Flush_filter )(
1154 Thread_Control *the_thread,
1169 Thread_Control *the_thread,
1186 Thread_Control *the_thread,
1203 Thread_Control *the_thread,
1248#if defined(RTEMS_SMP) && defined(RTEMS_DEBUG) && defined(RTEMS_PROFILING)
1249 #define THREAD_QUEUE_INITIALIZER( _name ) \
1251 .Lock_stats = SMP_LOCK_STATS_INITIALIZER( _name ), \
1252 .owner = SMP_LOCK_NO_OWNER, \
1254 .Lock = SMP_TICKET_LOCK_INITIALIZER, \
1260#elif defined(RTEMS_SMP) && defined(RTEMS_DEBUG)
1261 #define THREAD_QUEUE_INITIALIZER( _name ) \
1263 .owner = SMP_LOCK_NO_OWNER, \
1265 .Lock = SMP_TICKET_LOCK_INITIALIZER, \
1271#elif defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
1272 #define THREAD_QUEUE_INITIALIZER( _name ) \
1274 .Lock_stats = SMP_LOCK_STATS_INITIALIZER( _name ), \
1276 .Lock = SMP_TICKET_LOCK_INITIALIZER, \
1282#elif defined(RTEMS_SMP)
1283 #define THREAD_QUEUE_INITIALIZER( _name ) \
1286 .Lock = SMP_TICKET_LOCK_INITIALIZER, \
1293 #define THREAD_QUEUE_INITIALIZER( _name ) \
1308static inline void _Thread_queue_Destroy(
1312#if defined(RTEMS_SMP)
1313 _SMP_ticket_lock_Destroy( &the_thread_queue->
Queue.Lock );
1314 _SMP_lock_Stats_destroy( &the_thread_queue->Lock_stats );
1318#if defined(RTEMS_MULTIPROCESSING)
1325void _Thread_queue_MP_callout_do_nothing(
1326 Thread_Control *the_proxy,
1330bool _Thread_queue_MP_set_callout(
1331 Thread_Control *the_thread,
1341void _Thread_queue_Unblock_proxy(
1343 Thread_Control *the_thread
1362#if defined(RTEMS_SMP)
1385 Thread_Control *the_thread,
1397void _Thread_queue_Path_release(
1413#define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member, msg ) \
1414 RTEMS_STATIC_ASSERT( \
1415 offsetof( object_type, wait_queue_member ) \
1416 == offsetof( Thread_queue_Object, Wait_queue ) \
1417 && RTEMS_HAVE_MEMBER_SAME_TYPE( \
1419 wait_queue_member, \
1420 Thread_queue_Object, \
1426#define THREAD_QUEUE_QUEUE_TO_OBJECT( queue ) \
1427 RTEMS_CONTAINER_OF( \
1429 Thread_queue_Object, \
This header file provides interfaces of the Chain Handler which are only used by the implementation.
This header file provides interfaces of the SMP Support which are used by the implementation and the ...
#define RTEMS_ARRAY_SIZE(_array)
Gets the element count of the array.
Definition basedefs.h:244
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition assert.h:96
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition isrlock.h:385
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition isrlock.h:364
#define _ISR_Get_level()
Return current interrupt level.
Definition isrlevel.h:147
uint32_t ISR_Level
Definition isrlevel.h:60
uint32_t Objects_Id
Definition object.h:101
#define _Scheduler_Count
This constant contains the count of configured schedulers.
Definition scheduler.h:395
const Scheduler_Control _Scheduler_Table[]
This table contains the configured schedulers.
uint32_t States_Control
Definition states.h:65
Status_Control
Status codes.
Definition status.h:111
const Thread_queue_Operations _Thread_queue_Operations_priority
The FIFO thread queue operations are used when a thread is enqueued on a thread queue and provide pri...
Definition threadqops.c:1517
void _Thread_queue_Add_timeout_realtime_timespec(Thread_queue_Queue *queue, Thread_Control *the_thread, Per_CPU_Control *cpu_self, Thread_queue_Context *queue_context)
Adds a monotonic timespec to the thread and sets the watchdog header to realtime.
Definition threadqtimeout.c:147
#define _Thread_queue_Context_set_MP_callout(queue_context, mp_callout)
Sets the MP callout in the thread queue context.
Definition threadqimpl.h:491
Thread_queue_Deadlock_status
This is a status code to indicate if a deadlock was detected or not.
Definition threadqimpl.h:1350
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:691
const Thread_queue_Operations _Thread_queue_Operations_FIFO
The FIFO thread queue operations are used when a thread is enqueued on a thread queue and provide FIF...
Definition threadqops.c:1509
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:407
void _Thread_queue_Add_timeout_monotonic_timespec(Thread_queue_Queue *queue, Thread_Control *the_thread, Per_CPU_Control *cpu_self, Thread_queue_Context *queue_context)
Adds a monotonic timespec to the thread and sets the watchdog header to monotonic.
Definition threadqtimeout.c:127
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:90
void _Thread_queue_Resume(Thread_queue_Queue *queue, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Resumes the extracted or surrendered thread.
Definition threadqenqueue.c:663
void _Thread_queue_Deadlock_fatal(Thread_Control *the_thread)
Results in an INTERNAL_ERROR_THREAD_QUEUE_DEADLOCK fatal error.
Definition threadqenqueue.c:401
void _Thread_queue_Enqueue_do_nothing_extra(Thread_queue_Queue *queue, Thread_Control *the_thread, Per_CPU_Control *cpu_self, Thread_queue_Context *queue_context)
Does nothing.
Definition threadqenqueue.c:386
const Thread_queue_Operations _Thread_queue_Operations_priority_inherit
The FIFO thread queue operations are used when a thread is enqueued on a thread queue and provide pri...
Definition threadqops.c:1525
const Thread_queue_Operations _Thread_queue_Operations_default
The default thread queue operations are used when a thread is not enqueued on a thread queue.
Definition threadqops.c:1500
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:649
Status_Control _Thread_queue_Surrender_priority_ceiling(Thread_queue_Queue *queue, Thread_Control *executing, Priority_Node *ceiling_priority, 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:760
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:157
void _Thread_queue_Surrender_no_priority(Thread_queue_Queue *queue, Thread_queue_Heads *heads, 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:739
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:60
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 threadqgetnameandid.c:46
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:86
void _Thread_queue_Deadlock_status(Thread_Control *the_thread)
Sets the thread wait return code to STATUS_DEADLOCK.
Definition threadqenqueue.c:396
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:44
struct _Thread_queue_Heads Thread_queue_Heads
Thread queue heads.
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:1153
void _Thread_queue_Extract(Thread_Control *the_thread)
Extracts thread from thread queue.
Definition threadqextract.c:47
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:49
void _Thread_queue_Object_initialize(Thread_queue_Control *the_thread_queue)
Initializes a thread queue embedded in an object with identifier.
Definition threadq.c:170
void _Thread_queue_Add_timeout_ticks(Thread_queue_Queue *queue, Thread_Control *the_thread, Per_CPU_Control *cpu_self, Thread_queue_Context *queue_context)
Adds timeout ticks of the queue to the thread.
Definition threadqtimeout.c:47
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:159
void(*) Thread_queue_Deadlock_callout(Thread_Control *the_thread)
Thread queue deadlock callout.
Definition threadq.h:104
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:73
@ THREAD_QUEUE_DEADLOCK_DETECTED
The operation detected a deadlock.
Definition threadqimpl.h:1359
@ THREAD_QUEUE_NO_DEADLOCK
The operation did not detect a deadlock.
Definition threadqimpl.h:1354
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
Definition watchdogticks.h:59
This header file provides interfaces of the Priority Handler which are only used by the implementatio...
This header file provides interfaces of the Scheduler Handler which are used by the implementation an...
This header file provides the interfaces of the Operation Status Support.
This header file provides interfaces of the Thread Handler which are used by the implementation and t...
Local ISR lock context for acquire and release pairs.
Definition isrlock.h:94
Definition objectdata.h:61
Per CPU Core Structure.
Definition percpu.h:384
The priority node to build up a priority aggregation.
Definition priority.h:112
Thread queue context for the thread queue methods.
Definition threadq.h:216
Thread_queue_Enqueue_callout enqueue_callout
The enqueue callout for _Thread_queue_Enqueue().
Definition threadq.h:240
Thread_queue_Deadlock_callout deadlock_callout
Invoked in case of a detected deadlock.
Definition threadq.h:329
bool timeout_absolute
If this member is true, the timeout shall be absolute, otherwise it shall be relative to the current ...
Definition threadq.h:263
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition threadq.h:221
States_Control thread_state
The thread state for _Thread_queue_Enqueue().
Definition threadq.h:226
Thread_queue_Queue Queue
The actual thread queue.
Definition threadq.h:640
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition threadq.h:148
Helper structure to ensure that all objects containing a thread queue have the right layout.
Definition threadqimpl.h:1408
The thread queue operations are used to manage the threads of a thread queue.
Definition threadq.h:554
const char * name
The thread queue name.
Definition threadq.h:461
Thread_queue_Heads * heads
The thread queue heads.
Definition threadq.h:451
Thread_Control * owner
The thread queue owner.
Definition threadq.h:456
Thread queue with a layout compatible to struct _Thread_queue_Queue defined in Newlib <sys/lock....
Definition threadqimpl.h:71
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:417
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:411
This header file provides the interfaces of the Thread Handler related to thread dispatching.
This header file provides interfaces of the Thread Queue Handler which are used by the implementation...
This union represents a chain control block.
Definition chain.h:96