38#ifndef _RTEMS_SCORE_COREMUTEXIMPL_H
39#define _RTEMS_SCORE_COREMUTEXIMPL_H
58#define CORE_MUTEX_TQ_OPERATIONS &_Thread_queue_Operations_priority
60#define CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS \
61 &_Thread_queue_Operations_priority_inherit
68static inline void _CORE_mutex_Initialize(
82 _Thread_queue_Destroy( &the_mutex->
Wait_queue );
91static inline void _CORE_mutex_Acquire_critical(
96 _Thread_queue_Acquire_critical( &the_mutex->
Wait_queue, queue_context );
105static inline void _CORE_mutex_Release(
110 _Thread_queue_Release( &the_mutex->
Wait_queue, queue_context );
138static inline bool _CORE_mutex_Is_locked(
142 return _CORE_mutex_Get_owner( the_mutex ) != NULL;
171static inline void _CORE_mutex_Set_owner(
188static inline bool _CORE_mutex_Is_owner(
193 return _CORE_mutex_Get_owner( the_mutex ) == the_thread;
201static inline void _CORE_recursive_mutex_Initialize(
205 _CORE_mutex_Initialize( &the_mutex->
Mutex );
221 return STATUS_SUCCESSFUL;
250 _CORE_mutex_Acquire_critical( &the_mutex->
Mutex, queue_context );
252 owner = _CORE_mutex_Get_owner( &the_mutex->
Mutex );
254 if ( owner == NULL ) {
255 _CORE_mutex_Set_owner( &the_mutex->
Mutex, executing );
256 _Thread_Resource_count_increment( executing );
257 _CORE_mutex_Release( &the_mutex->
Mutex, queue_context );
258 return STATUS_SUCCESSFUL;
261 if ( owner == executing ) {
264 status = ( *nested )( the_mutex );
265 _CORE_mutex_Release( &the_mutex->
Mutex, queue_context );
296 unsigned int nest_level;
299 _CORE_mutex_Acquire_critical( &the_mutex->
Mutex, queue_context );
301 if ( !_CORE_mutex_Is_owner( &the_mutex->
Mutex, executing ) ) {
302 _CORE_mutex_Release( &the_mutex->
Mutex, queue_context );
303 return STATUS_NOT_OWNER;
308 if ( nest_level > 0 ) {
310 _CORE_mutex_Release( &the_mutex->
Mutex, queue_context );
311 return STATUS_SUCCESSFUL;
314 _Thread_Resource_count_decrement( executing );
315 _CORE_mutex_Set_owner( &the_mutex->
Mutex, NULL );
319 if ( heads == NULL ) {
320 _CORE_mutex_Release( &the_mutex->
Mutex, queue_context );
321 return STATUS_SUCCESSFUL;
331 return STATUS_SUCCESSFUL;
342static inline void _CORE_ceiling_mutex_Initialize(
348 _CORE_recursive_mutex_Initialize( &the_mutex->
Recursive );
349 _Priority_Node_initialize( &the_mutex->
Priority_ceiling, priority_ceiling );
350#if defined(RTEMS_SMP)
351 the_mutex->scheduler = scheduler;
365_CORE_ceiling_mutex_Get_scheduler(
369#if defined(RTEMS_SMP)
370 return the_mutex->scheduler;
383static inline void _CORE_ceiling_mutex_Set_priority(
392 if ( owner != NULL ) {
395 _Thread_queue_Context_initialize( &queue_context );
396 _Thread_queue_Context_clear_priority_updates( &queue_context );
397 _Thread_Wait_acquire_critical( owner, &queue_context );
398 _Thread_Priority_change(
405 _Thread_Wait_release_critical( owner, &queue_context );
446 _Thread_Wait_acquire_default_critical( owner, &lock_context );
448 scheduler_node = _Thread_Scheduler_get_home_node( owner );
451 _Priority_Get_priority( &scheduler_node->
Wait.Priority )
454 _Thread_Wait_release_default_critical( owner, &lock_context );
455 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
456 return STATUS_MUTEX_CEILING_VIOLATED;
460 _Thread_Resource_count_increment( owner );
466 _Thread_Wait_release_default_critical( owner, &lock_context );
468 cpu_self = _Thread_queue_Dispatch_disable( queue_context );
469 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
472 return STATUS_SUCCESSFUL;
500 _CORE_mutex_Acquire_critical( &the_mutex->
Recursive.
Mutex, queue_context );
502#if defined(RTEMS_SMP)
504 _Thread_Scheduler_get_home( executing )
505 != _CORE_ceiling_mutex_Get_scheduler( the_mutex )
507 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
508 return STATUS_NOT_DEFINED;
514 if ( owner == NULL ) {
515 _Thread_queue_Context_clear_priority_updates( queue_context );
516 return _CORE_ceiling_mutex_Set_owner(
523 if ( owner == executing ) {
526 status = ( *nested )( &the_mutex->
Recursive );
527 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
533 CORE_MUTEX_TQ_OPERATIONS,
556 unsigned int nest_level;
558 _CORE_mutex_Acquire_critical( &the_mutex->
Recursive.
Mutex, queue_context );
560 if ( !_CORE_mutex_Is_owner( &the_mutex->
Recursive.
Mutex, executing ) ) {
561 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
562 return STATUS_NOT_OWNER;
567 if ( nest_level > 0 ) {
569 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
570 return STATUS_SUCCESSFUL;
578 CORE_MUTEX_TQ_OPERATIONS
This header file provides interfaces of the Chain Handler which are only used by the implementation.
This header file provides interfaces of the Mutex Handler which are used by the implementation and th...
Status_Control _CORE_mutex_Seize_slow(CORE_mutex_Control *the_mutex, const Thread_queue_Operations *operations, Thread_Control *executing, bool wait, Thread_queue_Context *queue_context)
Seize the mutex slowly.
Definition: coremutexseize.c:47
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:91
@ PRIORITY_GROUP_LAST
Priority group last option requests that the priority node is inserted as the last node into its prio...
Definition: priorityimpl.h:73
const Scheduler_Control _Scheduler_Table[]
This table contains the configured schedulers.
Status_Control
Status codes.
Definition: status.h:111
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
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_Object_initialize(Thread_queue_Control *the_thread_queue)
Initializes a thread queue embedded in an object with identifier.
Definition: threadq.c:170
void _Thread_Priority_update(Thread_queue_Context *queue_context)
Updates the priority of all threads in the set.
Definition: threadchangepriority.c:396
void _Thread_Priority_add(Thread_Control *the_thread, Priority_Node *priority_node, Thread_queue_Context *queue_context)
Adds the specified thread priority node to the corresponding thread priority aggregation.
Definition: threadchangepriority.c:332
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
This header file provides interfaces of the Scheduler Handler which are only used by the implementati...
This header file provides the interfaces of the Operation Status Support.
The recursive mutex control with priority ceiling protocol support.
Definition: coremutex.h:101
Priority_Node Priority_ceiling
The priority ceiling node for the mutex owner.
Definition: coremutex.h:110
CORE_recursive_mutex_Control Recursive
The plain recursive mutex.
Definition: coremutex.h:105
Control block used to manage each mutex.
Definition: coremutex.h:74
Thread_queue_Control Wait_queue
The thread queue of this mutex.
Definition: coremutex.h:80
The recursive mutex control.
Definition: coremutex.h:86
unsigned int nest_level
The nest level in case of a recursive seize.
Definition: coremutex.h:95
CORE_mutex_Control Mutex
The plain non-recursive mutex.
Definition: coremutex.h:90
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:94
Per CPU Core Structure.
Definition: percpu.h:384
Priority_Control priority
The priority value of this node.
Definition: priority.h:124
Scheduler node for per-thread data.
Definition: schedulernode.h:94
struct Scheduler_Node::@4366 Wait
Thread wait support block.
Thread queue context for the thread queue methods.
Definition: threadq.h:217
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:649
The thread queue operations are used to manage the threads of a thread queue.
Definition: threadq.h:563
Thread_queue_Heads * heads
The thread queue heads.
Definition: threadq.h:460
Thread_Control * owner
The thread queue owner.
Definition: threadq.h:465
Scheduler control.
Definition: scheduler.h:337
Thread queue heads.
Definition: threadq.h:394
This header file provides interfaces of the Thread Handler which are only used by the implementation.
This header file provides interfaces of the Thread Queue Handler which are only used by the implement...