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 );
120static inline Thread_Control *_CORE_mutex_Get_owner(
138static inline bool _CORE_mutex_Is_locked(
142 return _CORE_mutex_Get_owner( the_mutex ) != NULL;
160 Thread_Control *executing,
171static inline void _CORE_mutex_Set_owner(
173 Thread_Control *owner
188static inline bool _CORE_mutex_Is_owner(
190 const Thread_Control *the_thread
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;
242 Thread_Control *executing,
248 Thread_Control *owner;
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 );
292 Thread_Control *executing,
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(
344 const Scheduler_Control *scheduler,
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;
362static inline const Scheduler_Control *
363_CORE_ceiling_mutex_Get_scheduler(
367#if defined(RTEMS_SMP)
368 return the_mutex->scheduler;
380static inline void _CORE_ceiling_mutex_Set_priority(
385 Thread_Control *owner;
389 if ( owner != NULL ) {
392 _Thread_queue_Context_initialize( &queue_context );
393 _Thread_queue_Context_clear_priority_updates( &queue_context );
394 _Thread_Wait_acquire_critical( owner, &queue_context );
395 _Thread_Priority_change(
402 _Thread_Wait_release_critical( owner, &queue_context );
435 Thread_Control *owner,
443 _Thread_Wait_acquire_default_critical( owner, &lock_context );
445 scheduler_node = _Thread_Scheduler_get_home_node( owner );
448 _Priority_Get_priority( &scheduler_node->Wait.Priority )
451 _Thread_Wait_release_default_critical( owner, &lock_context );
452 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
453 return STATUS_MUTEX_CEILING_VIOLATED;
457 _Thread_Resource_count_increment( owner );
463 _Thread_Wait_release_default_critical( owner, &lock_context );
465 cpu_self = _Thread_queue_Dispatch_disable( queue_context );
466 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
469 return STATUS_SUCCESSFUL;
489 Thread_Control *executing,
495 Thread_Control *owner;
497 _CORE_mutex_Acquire_critical( &the_mutex->
Recursive.
Mutex, queue_context );
499#if defined(RTEMS_SMP)
501 _Thread_Scheduler_get_home( executing )
502 != _CORE_ceiling_mutex_Get_scheduler( the_mutex )
504 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
505 return STATUS_NOT_DEFINED;
511 if ( owner == NULL ) {
512 _Thread_queue_Context_clear_priority_updates( queue_context );
513 return _CORE_ceiling_mutex_Set_owner(
520 if ( owner == executing ) {
523 status = ( *nested )( &the_mutex->
Recursive );
524 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
530 CORE_MUTEX_TQ_OPERATIONS,
549 Thread_Control *executing,
553 unsigned int nest_level;
555 _CORE_mutex_Acquire_critical( &the_mutex->
Recursive.
Mutex, queue_context );
557 if ( !_CORE_mutex_Is_owner( &the_mutex->
Recursive.
Mutex, executing ) ) {
558 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
559 return STATUS_NOT_OWNER;
564 if ( nest_level > 0 ) {
566 _CORE_mutex_Release( &the_mutex->
Recursive.
Mutex, queue_context );
567 return STATUS_SUCCESSFUL;
575 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:691
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
struct _Thread_queue_Heads Thread_queue_Heads
Thread queue heads.
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
Thread queue context for the thread queue methods.
Definition threadq.h:216
Thread_queue_Queue Queue
The actual thread queue.
Definition threadq.h:640
The thread queue operations are used to manage the threads of a thread queue.
Definition threadq.h:554
Thread_queue_Heads * heads
The thread queue heads.
Definition threadq.h:451
Thread_Control * owner
The thread queue owner.
Definition threadq.h:456
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...