21 #ifndef _RTEMS_SCORE_THREADQIMPL_H 22 #define _RTEMS_SCORE_THREADQIMPL_H 29 #include <rtems/score/status.h> 33 #if defined(RTEMS_DEBUG) 47 #define THREAD_QUEUE_LINK_OF_PATH_NODE( node ) \ 48 RTEMS_CONTAINER_OF( node, Thread_queue_Link, Path_node ); 55 #if !defined(RTEMS_SMP) 62 unsigned int reserved[2];
156 #if defined(RTEMS_DEBUG) 157 memset( queue_context, 0x7f,
sizeof( *queue_context ) );
158 #if defined(RTEMS_SMP) 164 (void) queue_context;
283 const struct timespec *abstime
303 const struct timespec *abstime
397 #define _Thread_queue_Context_ISR_disable( queue_context, level ) \ 399 _ISR_Local_disable( level ); \ 400 _ISR_lock_ISR_disable_profile( \ 401 &( queue_context )->Lock_context.Lock_context \ 447 #if defined(RTEMS_MULTIPROCESSING) 450 Thread_queue_MP_callout mp_callout
453 queue_context->mp_callout = mp_callout;
456 #define _Thread_queue_Context_set_MP_callout( queue_context, mp_callout ) \ 458 (void) queue_context; \ 462 #if defined(RTEMS_SMP) 472 _Atomic_Store_uint( &gate->go_ahead, 0, ATOMIC_ORDER_RELAXED );
498 _Atomic_Store_uint( &gate->go_ahead, 1, ATOMIC_ORDER_RELAXED );
512 while ( _Atomic_Load_uint( &gate->go_ahead, ATOMIC_ORDER_RELAXED ) == 0 ) {
527 #if defined(RTEMS_SMP) 552 #if defined(RTEMS_SMP) 569 #
if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
570 SMP_lock_Stats *lock_stats,
575 #if defined(RTEMS_SMP) 579 &lock_context->Lock_context.Stats_context
587 #if defined(RTEMS_SMP) && defined( RTEMS_PROFILING ) 589 _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \ 590 _Thread_queue_Queue_do_acquire_critical( queue, lock_stats, lock_context ) 593 _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \ 594 _Thread_queue_Queue_do_acquire_critical( queue, lock_context ) 608 #if defined(RTEMS_SMP) 611 &lock_context->Lock_context.Stats_context
659 #if defined(RTEMS_SMP) 670 (void) the_thread_queue;
698 #if defined(RTEMS_SMP) 709 (void) the_thread_queue;
722 #if defined(RTEMS_DEBUG) 727 #if defined(RTEMS_SMP) 728 return the_thread_queue->owner == _SMP_lock_Who_am_I();
741 #if defined(RTEMS_SMP) 752 (void) the_thread_queue;
754 _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) );
781 #if defined(RTEMS_SMP) 792 (void) the_thread_queue;
793 _Assert( _Thread_queue_Is_lock_owner( the_thread_queue ) );
809 #
if defined(RTEMS_MULTIPROCESSING)
811 Thread_queue_MP_callout mp_callout
826 #if defined(RTEMS_MULTIPROCESSING) 827 #define _Thread_queue_Dequeue( \ 832 _Thread_queue_Do_dequeue( \ 838 #define _Thread_queue_Dequeue( \ 843 _Thread_queue_Do_dequeue( \ 933 #if defined(RTEMS_SMP) 1114 #if defined(RTEMS_SMP) 1156 return queue->
heads == NULL;
1180 if ( heads != NULL ) {
1181 return ( *operations->
first )( heads );
1318 #if defined(RTEMS_SMP) && defined(RTEMS_DEBUG) && defined(RTEMS_PROFILING) 1319 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1321 .Lock_stats = SMP_LOCK_STATS_INITIALIZER( _name ), \ 1322 .owner = SMP_LOCK_NO_OWNER, \ 1324 .Lock = SMP_TICKET_LOCK_INITIALIZER, \ 1330 #elif defined(RTEMS_SMP) && defined(RTEMS_DEBUG) 1331 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1333 .owner = SMP_LOCK_NO_OWNER, \ 1335 .Lock = SMP_TICKET_LOCK_INITIALIZER, \ 1341 #elif defined(RTEMS_SMP) && defined(RTEMS_PROFILING) 1342 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1344 .Lock_stats = SMP_LOCK_STATS_INITIALIZER( _name ), \ 1346 .Lock = SMP_TICKET_LOCK_INITIALIZER, \ 1352 #elif defined(RTEMS_SMP) 1353 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1356 .Lock = SMP_TICKET_LOCK_INITIALIZER, \ 1363 #define THREAD_QUEUE_INITIALIZER( _name ) \ 1382 #if defined(RTEMS_SMP) 1384 _SMP_lock_Stats_destroy( &the_thread_queue->Lock_stats );
1394 #if defined(RTEMS_MULTIPROCESSING) 1395 void _Thread_queue_MP_callout_do_nothing(
1406 void _Thread_queue_Unblock_proxy(
1422 #if defined(RTEMS_SMP) 1450 #define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member, msg ) \ 1451 RTEMS_STATIC_ASSERT( \ 1452 offsetof( object_type, wait_queue_member ) \ 1453 == offsetof( Thread_queue_Object, Wait_queue ) \ 1454 && RTEMS_HAVE_MEMBER_SAME_TYPE( \ 1456 wait_queue_member, \ 1457 Thread_queue_Object, \ 1463 #define THREAD_QUEUE_QUEUE_TO_OBJECT( queue ) \ 1464 RTEMS_CONTAINER_OF( \ 1466 Thread_queue_Object, \ static __inline__ void _Thread_queue_Acquire_critical(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Acquires the thread queue control in a critical section.
#define _SMP_ticket_lock_Acquire(lock, stats, stats_context)
Acquires an SMP ticket lock.
Watchdog_Interval ticks
The timeout in ticks.
Thread_Control * owner
The thread queue owner.
void(* Thread_queue_Deadlock_callout)(Thread_Control *the_thread)
Thread queue deadlock callout.
static __inline__ 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.
static __inline__ void _ISR_lock_Context_set_level(ISR_lock_Context *context, ISR_Level level)
Sets the ISR level in the ISR lock context.
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
static __inline__ 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. ...
static __inline__ Per_CPU_Control * _Thread_queue_Dispatch_disable(Thread_queue_Context *queue_context)
Disables dispatching in a critical section.
void _Thread_queue_Initialize(Thread_queue_Control *the_thread_queue, const char *name)
Initializes the thread queue control to the given name.
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...
Thread queue context for the thread queue methods.
#define _Thread_queue_Context_set_MP_callout(queue_context, mp_callout)
Sets the MP callout in the thread queue context.
static __inline__ 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.
const struct _Scheduler_Control * scheduler
The scheduler instance of this priority aggregation.
static __inline__ 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.
static __inline__ void _Chain_Initialize_node(Chain_Node *the_node)
Initializes a chain node.
Thread_Control * update[2]
Threads to update the priority via _Thread_Priority_update().
Thread_queue_Enqueue_callout enqueue_callout
The enqueue callout for _Thread_queue_Enqueue().
void _Thread_queue_Acquire(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Acquires the thread queue control in a critical section.
Constants and Structures Related with Thread Dispatch.
static __inline__ void _Thread_queue_Context_set_timeout_argument(Thread_queue_Context *queue_context, const void *arg)
Sets the timeout argument in the thread queue context.
static __inline__ void _Thread_queue_Context_initialize(Thread_queue_Context *queue_context)
Initializes a thread queue context.
Thread_queue_Priority_queue Priority[RTEMS_ZERO_LENGTH_ARRAY]
One priority queue per scheduler instance.
Thread_queue_Deadlock_callout deadlock_callout
Invoked in case of a detected deadlock.
static __inline__ void _Thread_queue_Queue_initialize(Thread_queue_Queue *queue, const char *name)
Initializes the thread queue queue with the given name.
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
static __inline__ void _Thread_queue_Context_set_ISR_level(Thread_queue_Context *queue_context, ISR_Level level)
Sets the thread queue context ISR level.
static __inline__ void _Priority_Initialize_empty(Priority_Aggregation *aggregation)
Initializes the priority aggregation empty.
static __inline__ void _Thread_queue_Context_add_priority_update(Thread_queue_Context *queue_context, Thread_Control *the_thread)
Adds a priority update of the thread to the thread queue context.
static __inline__ 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.
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.
static void _SMP_ticket_lock_Initialize(SMP_ticket_lock_Control *lock)
Initializes the SMP ticket lock.
Thread_queue_First_operation first
Thread queue first operation.
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.
void _Thread_queue_Object_initialize(Thread_queue_Control *the_thread_queue)
Initializes a thread queue embedded in an object with identifier.
Constants and Structures Needed to Declare a Thread Queue.
Chain_Node Node
Node to enqueue this queue in the FIFO chain of the corresponding heads structure.
#define _ISR_Get_level()
Return current interrupt level.
static __inline__ void _Thread_queue_Gate_close(Thread_queue_Gate *gate)
Closes the gate.
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.
static __inline__ 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.
bool _Thread_queue_Path_acquire_critical(Thread_queue_Queue *queue, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Does nothing.
SuperCore SMP Support API.
size_t update_count
Count of threads to update the priority via _Thread_Priority_update().
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.
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.
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.
Thread_Control *(* Thread_queue_Flush_filter)(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Thread queue flush filter function.
Thread_Control * _Thread_queue_Do_dequeue(Thread_queue_Control *the_thread_queue, const Thread_queue_Operations *operations)
Dequeues the first thread waiting on the thread queue and returns it.
Thread_queue_Queue Queue
The actual thread queue.
Thread_queue_Heads * heads
The thread queue heads.
static __inline__ void _Thread_queue_Gate_open(Thread_queue_Gate *gate)
Opens the gate.
static __inline__ 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.
static __inline__ void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Appends a node (unprotected).
static __inline__ Per_CPU_Control * _Thread_Dispatch_disable_critical(const ISR_lock_Context *lock_context)
Disables thread dispatching inside a critical section (interrupts disabled).
struct Thread_queue_Lock_context::@28 Wait
Data to support thread queue enqueue operations.
static __inline__ 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.
Chain_Control Free_chain
A chain with free thread queue heads providing the spare thread queue heads for a thread once it is d...
void _Thread_queue_Deadlock_fatal(Thread_Control *the_thread)
Results in an INTERNAL_ERROR_THREAD_QUEUE_DEADLOCK fatal error.
Priority_Aggregation Queue
The actual thread priority queue.
void _Thread_queue_Deadlock_status(Thread_Control *the_thread)
Sets the thread wait return code to STATUS_DEADLOCK.
#define _SMP_ticket_lock_Release(lock, stats_context)
Releases an SMP ticket lock.
Thread queue with a layout compatible to struct _Thread_queue_Queue defined in Newlib <sys/lock...
Thread_queue_Gate Gate
Gate to synchronize thread wait lock requests.
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.
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.
const char * name
The thread queue name.
struct Thread_queue_Context::@31 Priority
Block to manage thread priority changes due to a thread queue operation.
static __inline__ void _Thread_queue_Gate_wait(Thread_queue_Gate *gate)
Waits on a gate to open.
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.
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
void _Thread_queue_Extract_with_proxy(Thread_Control *the_thread)
Extracts the_thread from the_thread_queue.
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.
static __inline__ void _Thread_queue_Context_restore_priority_updates(Thread_queue_Context *queue_context, size_t update_count)
Sets the priority update count of the thread queue context.
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.
const Scheduler_Control _Scheduler_Table[]
This table contains the configured schedulers.
static __inline__ void _Thread_queue_Heads_initialize(Thread_queue_Heads *heads)
Initializes the thread queue heads.
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.
static __inline__ void _Thread_queue_Context_clear_priority_updates(Thread_queue_Context *queue_context)
Clears the priority update count of the thread queue context.
static __inline__ void _Thread_queue_Queue_release(Thread_queue_Queue *queue, ISR_lock_Context *lock_context)
Releases the thread queue queue and enables interrupts.
SMP_ticket_lock_Control Lock
Lock to protect this thread queue.
void _Thread_queue_Surrender_sticky(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.
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.
States_Control thread_state
The thread state for _Thread_queue_Enqueue().
Priority Handler API Implementation.
static __inline__ void _Chain_Initialize_empty(Chain_Control *the_chain)
Initializes this chain as empty.
static __inline__ void _Thread_queue_Context_set_timeout_ticks(Thread_queue_Context *queue_context, Watchdog_Interval ticks)
Sets the timeout ticks in the thread queue context.
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.
#define RTEMS_ARRAY_SIZE(_array)
Returns the element count of the specified array.
Chain_Node Free_node
A chain node to add these thread queue heads to the free chain of the thread queue heads dedicated to...
const char _Thread_queue_Object_name[]
The special thread queue name to indicated that the thread queue is embedded in an object with identi...
static void _SMP_ticket_lock_Destroy(SMP_ticket_lock_Control *lock)
Destroys the SMP ticket lock.
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.
const size_t _Scheduler_Count
This constant contains the count of configured schedulers.
static __inline__ bool _Thread_queue_Is_empty(const Thread_queue_Queue *queue)
Checks if the thread queue queue is empty.
The thread queue gate is an SMP synchronization means.
static __inline__ void _Thread_queue_Release_critical(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Releases the thread queue control in a critical section.
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
static __inline__ size_t _Thread_queue_Context_save_priority_updates(Thread_queue_Context *queue_context)
Returns the priority update count of the thread queue context.
const void * arg
The timeout argument, e.g. pointer to struct timespec.
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. ...
void _Thread_queue_Extract(Thread_Control *the_thread)
Extracts thread from thread queue.
Local ISR lock context for acquire and release pairs.
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
static __inline__ void _Thread_queue_Destroy(Thread_queue_Control *the_thread_queue)
Destroys the thread queue.
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
void _Thread_queue_Path_release_critical(Thread_queue_Context *queue_context)
Releases the thread queue path in a critical section.
Status_Control _Thread_queue_Enqueue_sticky(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Enqueues the thread on the thread queue and busy waits for dequeue.
void _Thread_queue_Release(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Releases the thread queue control and enables interrupts.
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.
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.
Constants and Structures Associated with the Scheduler.
Constants and Structures Related with the Thread Control Block.
static __inline__ void _Thread_queue_Queue_do_acquire_critical(Thread_queue_Queue *queue, ISR_lock_Context *lock_context)
Acquires the thread queue queue in a critical section.
union Thread_queue_Context::@29 Timeout
Interval to wait.
static __inline__ void _Thread_queue_Gate_add(Chain_Control *chain, Thread_queue_Gate *gate)
Adds the gate to the chain.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Helper structure to ensure that all objects containing a thread queue have the right layout...