27 #define MUTEX_TQ_OPERATIONS &_Thread_queue_Operations_priority_inherit 31 == offsetof(
struct _Mutex_Control, _Queue ),
42 == offsetof(
struct _Mutex_recursive_Control, _Mutex ),
43 MUTEX_RECURSIVE_CONTROL_MUTEX
48 == offsetof(
struct _Mutex_recursive_Control, _nest_level ),
49 MUTEX_RECURSIVE_CONTROL_NEST_LEVEL
54 ==
sizeof(
struct _Mutex_recursive_Control ),
55 MUTEX_RECURSIVE_CONTROL_SIZE
58 static Mutex_Control *_Mutex_Get(
struct _Mutex_Control *_mutex )
70 executing = _Thread_Executing;
71 _Thread_queue_Queue_acquire_critical(
73 &executing->Potpourri_stats,
80 static void _Mutex_Queue_release(
93 static void _Mutex_Acquire_slow(
118 static void _Mutex_Release_critical(
127 heads = mutex->Queue.Queue.
heads;
128 mutex->Queue.Queue.
owner = NULL;
132 _Mutex_Queue_release( mutex, level, queue_context );
145 void _Mutex_Acquire(
struct _Mutex_Control *_mutex )
153 mutex = _Mutex_Get( _mutex );
155 _Thread_queue_Context_ISR_disable( &queue_context, level );
156 executing = _Mutex_Queue_acquire_critical( mutex, &queue_context );
158 owner = mutex->Queue.Queue.
owner;
161 mutex->Queue.Queue.
owner = executing;
163 _Mutex_Queue_release( mutex, level, &queue_context );
166 _Mutex_Acquire_slow( mutex, owner, executing, level, &queue_context );
170 int _Mutex_Acquire_timed(
171 struct _Mutex_Control *_mutex,
172 const struct timespec *abstime
181 mutex = _Mutex_Get( _mutex );
183 _Thread_queue_Context_ISR_disable( &queue_context, level );
184 executing = _Mutex_Queue_acquire_critical( mutex, &queue_context );
186 owner = mutex->Queue.Queue.
owner;
189 mutex->Queue.Queue.
owner = executing;
191 _Mutex_Queue_release( mutex, level, &queue_context );
199 _Mutex_Acquire_slow( mutex, owner, executing, level, &queue_context );
205 int _Mutex_Try_acquire(
struct _Mutex_Control *_mutex )
214 mutex = _Mutex_Get( _mutex );
216 _Thread_queue_Context_ISR_disable( &queue_context, level );
217 executing = _Mutex_Queue_acquire_critical( mutex, &queue_context );
219 owner = mutex->Queue.Queue.
owner;
222 mutex->Queue.Queue.
owner = executing;
229 _Mutex_Queue_release( mutex, level, &queue_context );
234 void _Mutex_Release(
struct _Mutex_Control *_mutex )
241 mutex = _Mutex_Get( _mutex );
243 _Thread_queue_Context_ISR_disable( &queue_context, level );
244 executing = _Mutex_Queue_acquire_critical( mutex, &queue_context );
248 _Mutex_Release_critical( mutex, executing, level, &queue_context );
252 struct _Mutex_recursive_Control *_mutex
258 void _Mutex_recursive_Acquire(
struct _Mutex_recursive_Control *_mutex )
266 mutex = _Mutex_recursive_Get( _mutex );
268 _Thread_queue_Context_ISR_disable( &queue_context, level );
269 executing = _Mutex_Queue_acquire_critical( &mutex->Mutex, &queue_context );
271 owner = mutex->Mutex.Queue.Queue.
owner;
274 mutex->Mutex.Queue.Queue.
owner = executing;
276 _Mutex_Queue_release( &mutex->Mutex, level, &queue_context );
277 }
else if ( owner == executing ) {
279 _Mutex_Queue_release( &mutex->Mutex, level, &queue_context );
282 _Mutex_Acquire_slow( &mutex->Mutex, owner, executing, level, &queue_context );
286 int _Mutex_recursive_Acquire_timed(
287 struct _Mutex_recursive_Control *_mutex,
288 const struct timespec *abstime
297 mutex = _Mutex_recursive_Get( _mutex );
299 _Thread_queue_Context_ISR_disable( &queue_context, level );
300 executing = _Mutex_Queue_acquire_critical( &mutex->Mutex, &queue_context );
302 owner = mutex->Mutex.Queue.Queue.
owner;
305 mutex->Mutex.Queue.Queue.
owner = executing;
307 _Mutex_Queue_release( &mutex->Mutex, level, &queue_context );
310 }
else if ( owner == executing ) {
312 _Mutex_Queue_release( &mutex->Mutex, level, &queue_context );
320 _Mutex_Acquire_slow( &mutex->Mutex, owner, executing, level, &queue_context );
326 int _Mutex_recursive_Try_acquire(
struct _Mutex_recursive_Control *_mutex )
335 mutex = _Mutex_recursive_Get( _mutex );
337 _Thread_queue_Context_ISR_disable( &queue_context, level );
338 executing = _Mutex_Queue_acquire_critical( &mutex->Mutex, &queue_context );
340 owner = mutex->Mutex.Queue.Queue.
owner;
343 mutex->Mutex.Queue.Queue.
owner = executing;
346 }
else if ( owner == executing ) {
353 _Mutex_Queue_release( &mutex->Mutex, level, &queue_context );
358 void _Mutex_recursive_Release(
struct _Mutex_recursive_Control *_mutex )
364 unsigned int nest_level;
366 mutex = _Mutex_recursive_Get( _mutex );
368 _Thread_queue_Context_ISR_disable( &queue_context, level );
369 executing = _Mutex_Queue_acquire_critical( &mutex->Mutex, &queue_context );
373 nest_level = mutex->nest_level;
376 _Mutex_Release_critical( &mutex->Mutex, executing, level, &queue_context );
378 mutex->nest_level = nest_level - 1;
380 _Mutex_Queue_release( &mutex->Mutex, level, &queue_context );
Thread_Control * owner
The thread queue owner.
#define STATES_WAITING_FOR_MUTEX
Thread queue context for the thread queue methods.
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.
static __inline__ void _Thread_Resource_count_increment(Thread_Control *the_thread)
Increments the thread's resource count.
static __inline__ void _Thread_queue_Context_initialize(Thread_queue_Context *queue_context)
Initializes a thread queue 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 _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.
static __inline__ void _Thread_Resource_count_decrement(Thread_Control *the_thread)
Decrements the thread's resource count.
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.
Information for the Assert Handler.
Thread_queue_Heads * heads
The thread queue heads.
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 _Thread_queue_Context_set_enqueue_do_nothing_extra(Thread_queue_Context *queue_context)
Sets the do nothing enqueue callout in the thread queue context.
void _Thread_queue_Deadlock_fatal(Thread_Control *the_thread)
Results in an INTERNAL_ERROR_THREAD_QUEUE_DEADLOCK fatal error.
Structures for the implementation of mutexes.
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
#define RTEMS_STATIC_ASSERT(_cond, _msg)
Asserts at compile time that the specified condition is satisfied.
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.
Inlined Routines from the Thread Handler.
static __inline__ Status_Control _Thread_Wait_get_status(const Thread_Control *the_thread)
Get the status of the wait return code of the thread.
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
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.
#define RTEMS_PREDICT_TRUE(_exp)
Returns the value of the specified integral expression and tells the compiler that the predicted valu...
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.