18 #ifndef _RTEMS_POSIX_MUTEXIMPL_H 19 #define _RTEMS_POSIX_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 );
82 executing = _Thread_Executing;
83 _Thread_queue_Queue_acquire_critical(
84 &the_mutex->Recursive.Mutex.Queue.Queue,
85 &executing->Potpourri_stats,
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 );
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;
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;
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 );
319 &the_mutex->Priority_ceiling,
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) 347 != _POSIX_Mutex_Get_scheduler( the_mutex )
349 _POSIX_Mutex_Release( the_mutex, queue_context );
350 return STATUS_NOT_DEFINED;
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;
409 &the_mutex->Priority_ceiling,
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 );
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:431
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:1632
RTEMS_INLINE_ROUTINE Per_CPU_Control * _Thread_queue_Dispatch_disable(Thread_queue_Context *queue_context)
Disables dispatching in a critical section.
Definition: threadqimpl.h:429
POSIX_Mutex_Protocol
Supported POSIX mutex protocols.
Definition: muteximpl.h:60
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:70
Thread queue context for the thread queue methods.
Definition: threadq.h:198
The priority node to build up a priority aggregation.
Definition: priority.h:98
RTEMS_INLINE_ROUTINE void _Thread_Resource_count_decrement(Thread_Control *the_thread)
Decrements the thread's resource count.
Definition: threadimpl.h:1329
Definition: muteximpl.h:32
POSIX Threads Private Support.
Priority_Control priority
The priority value of this node.
Definition: priority.h:110
Thread_queue_First_operation first
Thread queue first operation.
Definition: threadq.h:545
Structures for the implementation of mutexes.
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:1842
Thread queue operations.
Definition: threadq.h:517
Thread_queue_Heads * heads
Lock to protect this thread queue.
Definition: threadq.h:426
Thread queue heads.
Definition: threadq.h:360
RTEMS_INLINE_ROUTINE void _Thread_Resource_count_increment(Thread_Control *the_thread)
Increments the thread's resource count.
Definition: threadimpl.h:1313
Per CPU Core Structure.
Definition: percpu.h:347
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:1903
uint32_t ISR_Level
Definition: isrlevel.h:41
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:72
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:203
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_ISR_level(Thread_queue_Context *queue_context, ISR_Level level)
Sets the thread queue context ISR level.
Definition: threadqimpl.h:411
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:660
const Scheduler_Control _Scheduler_Table[]
Registered schedulers.
void _Thread_Priority_update(Thread_queue_Context *queue_context)
Updates the priority of all threads in the set.
Definition: threadchangepriority.c:339
void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
Definition: threaddispatch.c:362
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:1692
const pthread_mutexattr_t _POSIX_Mutex_Default_attributes
Definition: mutexinit.c:58
Definition: muteximpl.h:42
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_clear_priority_updates(Thread_queue_Context *queue_context)
Clears the priority update count of the thread queue context.
Definition: threadqimpl.h:338
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_initialize(Thread_queue_Context *queue_context)
Initializes a thread queue context.
Definition: threadqimpl.h:152
RTEMS_INLINE_ROUTINE const Scheduler_Control * _Thread_Scheduler_get_home(const Thread_Control *the_thread)
Gets the home scheduler of the thread.
Definition: threadimpl.h:1393
Scheduler control.
Definition: scheduler.h:269
Scheduler node for per-thread data.
Definition: schedulernode.h:79
Inlined Routines from the Thread Handler.
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
struct Scheduler_Node::@3980 Wait
Thread wait support block.
RTEMS_INLINE_ROUTINE Priority_Control _Priority_Get_priority(const Priority_Aggregation *aggregation)
Gets the priority aggregation's priority.
Definition: priorityimpl.h:270
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:130
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
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:696
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:600
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_release(Thread_queue_Queue *queue, ISR_lock_Context *lock_context)
Releases the thread queue queue and enables interrupts.
Definition: threadqimpl.h:625
RTEMS_INLINE_ROUTINE Scheduler_Node * _Thread_Scheduler_get_home_node(const Thread_Control *the_thread)
Gets the scheduler's home node.
Definition: threadimpl.h:1412
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77