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];
185static inline void _Thread_queue_Context_initialize(
189#if defined(RTEMS_DEBUG)
190 memset( queue_context, 0x7f,
sizeof( *queue_context ) );
191#if defined(RTEMS_SMP)
192 _Chain_Initialize_node( &queue_context->
Lock_context.Wait.Gate.Node );
197 (void) queue_context;
211_Thread_queue_Context_set_thread_state(
228_Thread_queue_Context_set_timeout_ticks(
249_Thread_queue_Context_set_timeout_argument(
268_Thread_queue_Context_set_enqueue_callout(
284_Thread_queue_Context_set_enqueue_do_nothing_extra(
301_Thread_queue_Context_set_enqueue_timeout_ticks(
324_Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(
326 const struct timespec *timeout,
350_Thread_queue_Context_set_enqueue_timeout_realtime_timespec(
352 const struct timespec *timeout,
376static inline void _Thread_queue_Context_set_enqueue_timeout_by_clock_id_timespec(
378 const struct timespec *timeout,
403static inline void _Thread_queue_Context_set_deadlock_callout(
417static inline void _Thread_queue_Context_clear_priority_updates(
432static inline size_t _Thread_queue_Context_get_priority_updates(
446static inline void _Thread_queue_Context_restore_priority_updates(
462static inline void _Thread_queue_Context_add_priority_update(
476#define _Thread_queue_Context_ISR_disable( queue_context, level ) \
478 _ISR_Local_disable( level ); \
479 _ISR_lock_ISR_disable_profile( \
480 &( queue_context )->Lock_context.Lock_context \
490static inline void _Thread_queue_Context_set_ISR_level(
495 _ISR_lock_Context_set_level(
512 return _Thread_Dispatch_disable_critical(
526#if defined(RTEMS_MULTIPROCESSING)
529 Thread_queue_MP_callout mp_callout
532 queue_context->mp_callout = mp_callout;
535#define _Thread_queue_Context_set_MP_callout( queue_context, mp_callout ) \
537 (void) queue_context; \
541#if defined(RTEMS_SMP)
547static inline void _Thread_queue_Gate_close(
548 Thread_queue_Gate *gate
551 _Atomic_Store_uint( &gate->go_ahead, 0, ATOMIC_ORDER_RELAXED );
560static inline void _Thread_queue_Gate_add(
562 Thread_queue_Gate *gate
565 _Chain_Append_unprotected( chain, &gate->Node );
573static inline void _Thread_queue_Gate_open(
574 Thread_queue_Gate *gate
577 _Atomic_Store_uint( &gate->go_ahead, 1, ATOMIC_ORDER_RELAXED );
587static inline void _Thread_queue_Gate_wait(
588 Thread_queue_Gate *gate
591 while ( _Atomic_Load_uint( &gate->go_ahead, ATOMIC_ORDER_RELAXED ) == 0 ) {
602static inline void _Thread_queue_Heads_initialize(
606#if defined(RTEMS_SMP)
610 _Chain_Initialize_node( &heads->
Priority[ i ].Node );
616 _Chain_Initialize_empty( &heads->
Free_chain );
617 _Chain_Initialize_node( &heads->
Free_node );
626static inline void _Thread_queue_Queue_initialize(
631#if defined(RTEMS_SMP)
632 _SMP_ticket_lock_Initialize( &queue->Lock );
646static inline void _Thread_queue_Queue_do_acquire_critical(
648#
if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
649 SMP_lock_Stats *lock_stats,
654#if defined(RTEMS_SMP)
657 _SMP_ticket_lock_Acquire(
660 &lock_context->Lock_context.Stats_context
668#if defined(RTEMS_SMP) && defined( RTEMS_PROFILING )
670 _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \
671 _Thread_queue_Queue_do_acquire_critical( queue, lock_stats, lock_context )
674 _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \
675 _Thread_queue_Queue_do_acquire_critical( queue, lock_context )
684static inline void _Thread_queue_Queue_release_critical(
689#if defined(RTEMS_SMP)
692 _SMP_ticket_lock_Release(
694 &lock_context->Lock_context.Stats_context
708static inline void _Thread_queue_Queue_release(
713 _Thread_queue_Queue_release_critical( queue, lock_context );
742#if defined(RTEMS_SMP)
743void _Thread_queue_Do_acquire_critical(
748static inline void _Thread_queue_Do_acquire_critical(
753 (void) the_thread_queue;
764static inline void _Thread_queue_Acquire_critical(
769 _Thread_queue_Do_acquire_critical(
781#if defined(RTEMS_SMP)
782void _Thread_queue_Acquire(
787static inline void _Thread_queue_Acquire(
792 (void) the_thread_queue;
805#if defined(RTEMS_DEBUG)
806static inline bool _Thread_queue_Is_lock_owner(
810#if defined(RTEMS_SMP)
811 return the_thread_queue->owner == _SMP_lock_Who_am_I();
813 (void) the_thread_queue;
825#if defined(RTEMS_SMP)
826void _Thread_queue_Do_release_critical(
831static inline void _Thread_queue_Do_release_critical(
836 (void) the_thread_queue;
838 _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) );
848static inline void _Thread_queue_Release_critical(
853 _Thread_queue_Do_release_critical(
865#if defined(RTEMS_SMP)
866void _Thread_queue_Release(
871static inline void _Thread_queue_Release(
876 (void) the_thread_queue;
877 _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) );
966#if defined(RTEMS_SMP)
1121#if defined(RTEMS_SMP)
1142void _Thread_queue_Surrender_sticky(
1159static inline bool _Thread_queue_Is_empty(
1163 return queue->
heads == NULL;
1297#if defined(RTEMS_SMP) && defined(RTEMS_DEBUG) && defined(RTEMS_PROFILING)
1298 #define THREAD_QUEUE_INITIALIZER( _name ) \
1300 .Lock_stats = SMP_LOCK_STATS_INITIALIZER( _name ), \
1301 .owner = SMP_LOCK_NO_OWNER, \
1303 .Lock = SMP_TICKET_LOCK_INITIALIZER, \
1309#elif defined(RTEMS_SMP) && defined(RTEMS_DEBUG)
1310 #define THREAD_QUEUE_INITIALIZER( _name ) \
1312 .owner = SMP_LOCK_NO_OWNER, \
1314 .Lock = SMP_TICKET_LOCK_INITIALIZER, \
1320#elif defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
1321 #define THREAD_QUEUE_INITIALIZER( _name ) \
1323 .Lock_stats = SMP_LOCK_STATS_INITIALIZER( _name ), \
1325 .Lock = SMP_TICKET_LOCK_INITIALIZER, \
1331#elif defined(RTEMS_SMP)
1332 #define THREAD_QUEUE_INITIALIZER( _name ) \
1335 .Lock = SMP_TICKET_LOCK_INITIALIZER, \
1342 #define THREAD_QUEUE_INITIALIZER( _name ) \
1357static inline void _Thread_queue_Destroy(
1361#if defined(RTEMS_SMP)
1362 _SMP_ticket_lock_Destroy( &the_thread_queue->
Queue.Lock );
1363 _SMP_lock_Stats_destroy( &the_thread_queue->Lock_stats );
1365 (void) the_thread_queue;
1369#if defined(RTEMS_MULTIPROCESSING)
1376void _Thread_queue_MP_callout_do_nothing(
1381bool _Thread_queue_MP_set_callout(
1392void _Thread_queue_Unblock_proxy(
1413#if defined(RTEMS_SMP)
1448void _Thread_queue_Path_release(
1464#define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member, msg ) \
1465 RTEMS_STATIC_ASSERT( \
1466 offsetof( object_type, wait_queue_member ) \
1467 == offsetof( Thread_queue_Object, Wait_queue ) \
1468 && RTEMS_HAVE_MEMBER_SAME_TYPE( \
1470 wait_queue_member, \
1471 Thread_queue_Object, \
1477#define THREAD_QUEUE_QUEUE_TO_OBJECT( queue ) \
1478 RTEMS_CONTAINER_OF( \
1480 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:1551
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:150
#define _Thread_queue_Context_set_MP_callout(queue_context, mp_callout)
Sets the MP callout in the thread queue context.
Definition: threadqimpl.h:535
Thread_queue_Deadlock_status
This is a status code to indicate if a deadlock was detected or not.
Definition: threadqimpl.h:1401
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:1202
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:698
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:1543
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:414
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:130
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:670
void _Thread_queue_Deadlock_fatal(Thread_Control *the_thread)
Results in an INTERNAL_ERROR_THREAD_QUEUE_DEADLOCK fatal error.
Definition: threadqenqueue.c:408
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:388
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:1559
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:1534
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:91
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:656
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:767
void(* Thread_queue_Deadlock_callout)(Thread_Control *the_thread)
Thread queue deadlock callout.
Definition: threadq.h:105
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:746
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
void _Thread_queue_Add_timeout_by_clock_id_timespec(Thread_queue_Queue *queue, Thread_Control *the_thread, Per_CPU_Control *cpu_self, Thread_queue_Context *queue_context)
Adds a timeout to the thread queue context and sets the enqueue callout to add a timeout based on the...
Definition: threadqtimeout.c:170
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:403
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
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:48
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
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:1410
@ THREAD_QUEUE_NO_DEADLOCK
The operation did not detect a deadlock.
Definition: threadqimpl.h:1405
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:217
Thread_queue_Enqueue_callout enqueue_callout
The enqueue callout for _Thread_queue_Enqueue().
Definition: threadq.h:241
clockid_t clock_id
The clock identifier used for timeout operations.
Definition: threadq.h:272
Thread_queue_Deadlock_callout deadlock_callout
Invoked in case of a detected deadlock.
Definition: threadq.h:338
struct Thread_queue_Context::@4371 Priority
Block to manage thread priority changes due to a thread queue operation.
const void * arg
The timeout argument, e.g. pointer to struct timespec.
Definition: threadq.h:257
size_t update_count
Count of threads to update the priority via _Thread_Priority_update().
Definition: threadq.h:318
bool timeout_absolute
If this member is true, the timeout shall be absolute, otherwise it shall be relative to the current ...
Definition: threadq.h:264
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:222
union Thread_queue_Context::@4370 Timeout
Interval to wait.
Watchdog_Interval ticks
The timeout in ticks.
Definition: threadq.h:252
States_Control thread_state
The thread state for _Thread_queue_Enqueue().
Definition: threadq.h:227
Thread_Control * update[2]
Threads to update the priority via _Thread_Priority_update().
Definition: threadq.h:327
Definition: threadq.h:618
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:649
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:149
Helper structure to ensure that all objects containing a thread queue have the right layout.
Definition: threadqimpl.h:1459
The thread queue operations are used to manage the threads of a thread queue.
Definition: threadq.h:563
Priority_Aggregation Queue
The actual thread priority queue.
Definition: threadq.h:372
Definition: threadq.h:436
const char * name
The thread queue name.
Definition: threadq.h:470
Thread_queue_Heads * heads
The thread queue heads.
Definition: threadq.h:460
Thread_Control * owner
The thread queue owner.
Definition: threadq.h:465
Thread queue with a layout compatible to struct _Thread_queue_Queue defined in Newlib <sys/lock....
Definition: threadqimpl.h:71
Thread queue heads.
Definition: threadq.h:394
Thread_queue_Priority_queue Priority
This is the set of threads for priority discipline waiting.
Definition: threadq.h:412
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:426
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:420
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