18 #ifndef _RTEMS_POSIX_MUTEXIMPL_H 19 #define _RTEMS_POSIX_MUTEXIMPL_H 25 #include <rtems/score/muteximpl.h> 39 #define POSIX_MUTEX_PROTOCOL_MASK 0x3UL 41 #define POSIX_MUTEX_RECURSIVE 0x4UL 43 #define POSIX_MUTEX_FLAGS_MASK 0x7UL 45 #define POSIX_MUTEX_MAGIC 0x961c13b8UL 47 #define POSIX_MUTEX_NO_PROTOCOL_TQ_OPERATIONS &_Thread_queue_Operations_FIFO 49 #define POSIX_MUTEX_PRIORITY_INHERIT_TQ_OPERATIONS \ 50 &_Thread_queue_Operations_priority_inherit 52 #define POSIX_MUTEX_PRIORITY_CEILING_TQ_OPERATIONS \ 53 &_Thread_queue_Operations_priority 61 POSIX_MUTEX_NO_PROTOCOL,
62 POSIX_MUTEX_PRIORITY_INHERIT,
63 POSIX_MUTEX_PRIORITY_CEILING
80 _Thread_queue_Context_ISR_disable( queue_context, level );
81 _Thread_queue_Context_set_ISR_level( queue_context, level );
82 executing = _Thread_Executing;
83 _Thread_queue_Queue_acquire_critical(
84 &the_mutex->Recursive.Mutex.Queue.Queue,
85 &executing->Potpourri_stats,
97 _Thread_queue_Queue_release(
98 &the_mutex->Recursive.Mutex.Queue.Queue,
107 return flags & POSIX_MUTEX_PROTOCOL_MASK;
114 return ( flags & POSIX_MUTEX_RECURSIVE ) != 0;
121 return the_mutex->Recursive.Mutex.Queue.Queue.
owner;
128 return _POSIX_Mutex_Get_owner( the_mutex ) !=
NULL;
131 Status_Control _POSIX_Mutex_Seize_slow(
135 const struct timespec *abstime,
144 the_mutex->Recursive.Mutex.Queue.Queue.
owner = owner;
152 return _POSIX_Mutex_Get_owner( the_mutex ) == the_thread;
155 static Status_Control _POSIX_Mutex_Lock_nested(
161 if ( _POSIX_Mutex_Is_recursive( flags ) ) {
162 ++the_mutex->Recursive.nest_level;
163 return STATUS_SUCCESSFUL;
165 return STATUS_NESTING_NOT_ALLOWED;
174 const struct timespec *abstime,
180 owner = _POSIX_Mutex_Get_owner( the_mutex );
182 if ( owner ==
NULL ) {
183 _POSIX_Mutex_Set_owner( the_mutex, executing );
184 _Thread_Resource_count_increment( executing );
185 _POSIX_Mutex_Release( the_mutex, queue_context );
186 return STATUS_SUCCESSFUL;
189 if ( owner == executing ) {
190 Status_Control status;
192 status = _POSIX_Mutex_Lock_nested( the_mutex, flags );
193 _POSIX_Mutex_Release( the_mutex, queue_context );
197 return _POSIX_Mutex_Seize_slow(
213 unsigned int nest_level;
216 if ( !_POSIX_Mutex_Is_owner( the_mutex, executing ) ) {
217 _POSIX_Mutex_Release( the_mutex, queue_context );
218 return STATUS_NOT_OWNER;
221 nest_level = the_mutex->Recursive.nest_level;
223 if ( nest_level > 0 ) {
224 the_mutex->Recursive.nest_level = nest_level - 1;
225 _POSIX_Mutex_Release( the_mutex, queue_context );
226 return STATUS_SUCCESSFUL;
229 _Thread_Resource_count_decrement( executing );
230 _POSIX_Mutex_Set_owner( the_mutex,
NULL );
232 heads = the_mutex->Recursive.Mutex.Queue.Queue.
heads;
234 if ( heads ==
NULL ) {
235 _POSIX_Mutex_Release( the_mutex, queue_context );
236 return STATUS_SUCCESSFUL;
240 &the_mutex->Recursive.Mutex.Queue.Queue,
246 return STATUS_SUCCESSFUL;
253 #if defined(RTEMS_SMP) 254 return the_mutex->scheduler;
268 owner = _POSIX_Mutex_Get_owner( the_mutex );
270 if ( owner !=
NULL ) {
274 &the_mutex->Priority_ceiling,
281 the_mutex->Priority_ceiling.
priority = priority_ceiling;
289 return the_mutex->Priority_ceiling.
priority;
304 scheduler_node = _Thread_Scheduler_get_home_node( owner );
307 _Priority_Get_priority( &scheduler_node->
Wait.Priority )
308 < the_mutex->Priority_ceiling.
priority 311 _POSIX_Mutex_Release( the_mutex, queue_context );
312 return STATUS_MUTEX_CEILING_VIOLATED;
315 _POSIX_Mutex_Set_owner( the_mutex, owner );
316 _Thread_Resource_count_increment( owner );
319 &the_mutex->Priority_ceiling,
324 cpu_self = _Thread_queue_Dispatch_disable( queue_context );
325 _POSIX_Mutex_Release( the_mutex, queue_context );
328 return STATUS_SUCCESSFUL;
335 const struct timespec *abstime,
341 owner = _POSIX_Mutex_Get_owner( the_mutex );
343 if ( owner ==
NULL ) {
344 #if defined(RTEMS_SMP) 346 _Thread_Scheduler_get_home( executing )
347 != _POSIX_Mutex_Get_scheduler( the_mutex )
349 _POSIX_Mutex_Release( the_mutex, queue_context );
350 return STATUS_NOT_DEFINED;
354 _Thread_queue_Context_clear_priority_updates( queue_context );
355 return _POSIX_Mutex_Ceiling_set_owner(
362 if ( owner == executing ) {
363 Status_Control status;
365 status = _POSIX_Mutex_Lock_nested( the_mutex, flags );
366 _POSIX_Mutex_Release( the_mutex, queue_context );
370 return _POSIX_Mutex_Seize_slow(
372 POSIX_MUTEX_PRIORITY_CEILING_TQ_OPERATIONS,
385 unsigned int nest_level;
390 if ( !_POSIX_Mutex_Is_owner( the_mutex, executing ) ) {
391 _POSIX_Mutex_Release( the_mutex, queue_context );
392 return STATUS_NOT_OWNER;
395 nest_level = the_mutex->Recursive.nest_level;
397 if ( nest_level > 0 ) {
398 the_mutex->Recursive.nest_level = nest_level - 1;
399 _POSIX_Mutex_Release( the_mutex, queue_context );
400 return STATUS_SUCCESSFUL;
403 _Thread_Resource_count_decrement( executing );
405 _Thread_queue_Context_clear_priority_updates( queue_context );
409 &the_mutex->Priority_ceiling,
414 cpu_self = _Thread_queue_Dispatch_disable( queue_context );
416 heads = the_mutex->Recursive.Mutex.Queue.Queue.
heads;
418 if ( heads !=
NULL ) {
422 operations = POSIX_MUTEX_PRIORITY_CEILING_TQ_OPERATIONS;
423 new_owner = ( *operations->
first )( heads );
424 _POSIX_Mutex_Set_owner( the_mutex, new_owner );
425 _Thread_Resource_count_increment( new_owner );
428 &the_mutex->Priority_ceiling,
432 &the_mutex->Recursive.Mutex.Queue.Queue,
438 _POSIX_Mutex_Set_owner( the_mutex,
NULL );
439 _POSIX_Mutex_Release( the_mutex, queue_context );
444 return STATUS_SUCCESSFUL;
447 #define POSIX_MUTEX_ABSTIME_TRY_LOCK ((uintptr_t) 1) 449 int _POSIX_Mutex_Lock_support(
450 pthread_mutex_t *
mutex,
451 const struct timespec *abstime,
456 pthread_mutex_t *mutex
464 #define POSIX_MUTEX_VALIDATE_OBJECT( the_mutex, flags ) \ 466 if ( ( the_mutex ) == NULL ) { \ 469 flags = ( the_mutex )->flags; \ 471 ( ( (uintptr_t) ( the_mutex ) ^ POSIX_MUTEX_MAGIC ) \ 472 & ~POSIX_MUTEX_FLAGS_MASK ) \ 473 != ( flags & ~POSIX_MUTEX_FLAGS_MASK ) \ 475 if ( !_POSIX_Mutex_Auto_initialization( the_mutex ) ) { \ Thread_Control * owner
The thread queue owner.
Definition: threadq.h:426
POSIX_Mutex_Protocol
Supported POSIX mutex protocols.
Definition: muteximpl.h:60
RTEMS_INLINE_ROUTINE void _Thread_Priority_change(Thread_Control *the_thread, Priority_Node *priority_node, Priority_Control new_priority, bool prepend_it, Thread_queue_Context *queue_context)
Changes the thread priority value of the specified thread priority node in the corresponding thread p...
Definition: threadimpl.h:499
void _Thread_Priority_update(Thread_queue_Context *queue_context)
Adds a priority node to the corresponding thread priority aggregation.
Definition: threadchangepriority.c:339
Thread queue context for the thread queue methods.
Definition: threadq.h:193
The priority node to build up a priority aggregation.
Definition: priority.h:94
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:277
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
Definition: muteximpl.h:32
POSIX Threads Private Support.
Priority_Control priority
The priority value of this node.
Definition: priority.h:106
Thread_queue_First_operation first
Thread queue first operation.
Definition: threadq.h:540
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_initialize(Thread_queue_Context *queue_context)
Initializes a thread queue context.
Definition: threadqimpl.h:108
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:659
Thread queue operations.
Definition: threadq.h:512
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:66
Thread_queue_Heads * heads
Lock to protect this thread queue.
Definition: threadq.h:421
Thread queue heads.
Definition: threadq.h:355
void _Thread_Priority_remove(Thread_Control *the_thread, Priority_Node *priority_node, Thread_queue_Context *queue_context)
Removes the specified thread priority node from the corresponding thread priority aggregation...
Definition: threadchangepriority.c:292
RTEMS_INLINE_ROUTINE void _Thread_Wait_acquire_default_critical(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Acquires the thread wait default lock inside a critical section (interrupts disabled).
Definition: threadimpl.h:1160
uint32_t ISR_Level
Definition: isrlevel.h:38
Per CPU Core Structure.
Definition: percpu.h:290
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.
Definition: threadqenqueue.c:599
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:198
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:67
struct Scheduler_Node::@3976 Wait
Thread wait support block.
const pthread_mutexattr_t _POSIX_Mutex_Default_attributes
Definition: mutexinit.c:57
Definition: muteximpl.h:28
Scheduler control.
Definition: scheduler.h:266
Scheduler node for per-thread data.
Definition: schedulernode.h:65
const Scheduler_Control _Scheduler_Table[]
Registered schedulers.
Inlined Routines from the Thread Handler.
RTEMS_INLINE_ROUTINE void _Thread_Wait_release(Thread_Control *the_thread, Thread_queue_Context *queue_context)
Releases the thread wait lock and restores the previous interrupt status.
Definition: threadimpl.h:1413
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:125
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
Definition: threaddispatch.c:353
RTEMS_INLINE_ROUTINE void _Thread_Wait_acquire(Thread_Control *the_thread, Thread_queue_Context *queue_context)
Acquires the thread wait default lock and disables interrupts.
Definition: threadimpl.h:1352
RTEMS_INLINE_ROUTINE void _Thread_Wait_release_default_critical(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Releases the thread wait default lock inside a critical section (interrupts disabled).
Definition: threadimpl.h:1220
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77