static void _Thread_Make_zombie( Thread_Control *the_thread ) { if ( _Thread_Owns_resources( the_thread ) ) { _Terminate( INTERNAL_ERROR_CORE, false, INTERNAL_ERROR_RESOURCE_IN_USE ); } _Objects_Close( _Objects_Get_information_id( the_thread->Object.id ), &the_thread->Object ); _Thread_Set_state( the_thread, STATES_ZOMBIE ); _Thread_queue_Extract_with_proxy( the_thread ); _Thread_Timer_remove( the_thread ); /* * Add the thread to the thread zombie chain before we wake up joining * threads, so that they are able to clean up the thread immediately. This * matters for SMP configurations. */ _Thread_Add_to_zombie_chain( the_thread ); _Thread_Wake_up_joining_threads( the_thread ); }
static void _Thread_Make_zombie( Thread_Control *the_thread ) { ISR_lock_Context lock_context; Thread_Zombie_control *zombies = &_Thread_Zombies; if ( _Thread_Owns_resources( the_thread ) ) { _Terminate( INTERNAL_ERROR_CORE, false, INTERNAL_ERROR_RESOURCE_IN_USE ); } _Objects_Close( _Objects_Get_information_id( the_thread->Object.id ), &the_thread->Object ); _Thread_Set_state( the_thread, STATES_ZOMBIE ); _Thread_queue_Extract_with_proxy( the_thread ); _Watchdog_Remove_ticks( &the_thread->Timer ); _ISR_lock_ISR_disable_and_acquire( &zombies->Lock, &lock_context ); _Chain_Append_unprotected( &zombies->Chain, &the_thread->Object.Node ); _ISR_lock_Release_and_ISR_enable( &zombies->Lock, &lock_context ); }
static void _Thread_Make_zombie( Thread_Control *the_thread ) { #if defined(RTEMS_SCORE_THREAD_ENABLE_RESOURCE_COUNT) if ( _Thread_Owns_resources( the_thread ) ) { _Internal_error( INTERNAL_ERROR_RESOURCE_IN_USE ); } #endif _Objects_Close( _Objects_Get_information_id( the_thread->Object.id ), &the_thread->Object ); _Thread_Set_state( the_thread, STATES_ZOMBIE ); _Thread_queue_Extract_with_proxy( the_thread ); _Thread_Timer_remove( the_thread ); /* * Add the thread to the thread zombie chain before we wake up joining * threads, so that they are able to clean up the thread immediately. This * matters for SMP configurations. */ _Thread_Add_to_zombie_chain( the_thread ); _Thread_Wake_up_joining_threads( the_thread ); }
static bool _POSIX_Threads_Sporadic_budget_TSR_filter( Thread_Control *the_thread, Priority_Control *new_priority, void *arg ) { the_thread->real_priority = *new_priority; /* * If holding a resource, then do not change it. * * If this would make them less important, then do not change it. */ return !_Thread_Owns_resources( the_thread ) && _Thread_Priority_less_than( the_thread->current_priority, *new_priority ); }
static bool _POSIX_Threads_Sporadic_budget_callout_filter( Thread_Control *the_thread, Priority_Control *new_priority, void *arg ) { the_thread->real_priority = *new_priority; /* * If holding a resource, then do not change it. * * Make sure we are actually lowering it. If they have lowered it * to logically lower than sched_ss_low_priority, then we do not want to * change it. */ return !_Thread_Owns_resources( the_thread ) && _Thread_Priority_less_than( *new_priority, the_thread->current_priority ); }
static bool _RTEMS_tasks_Set_priority_filter( Thread_Control *the_thread, Priority_Control *new_priority_p, void *arg ) { RTEMS_tasks_Set_priority_context *context; const Scheduler_Control *scheduler; bool valid; Priority_Control current_priority; Priority_Control new_priority; context = arg; scheduler = _Scheduler_Get_own( the_thread ); current_priority = _Thread_Get_priority( the_thread ); context->scheduler = scheduler; context->old_priority = current_priority; new_priority = _RTEMS_Priority_To_core( scheduler, context->new_priority, &valid ); *new_priority_p = new_priority; if ( !valid ) { context->status = RTEMS_INVALID_PRIORITY; return false; } the_thread->real_priority = new_priority; context->status = STATUS_SUCCESSFUL; return _Thread_Priority_less_than( current_priority, new_priority ) || !_Thread_Owns_resources( the_thread ); }
static void _Mutex_Release_critical( Mutex_Control *mutex, Thread_Control *executing, Thread_queue_Context *queue_context ) { Thread_queue_Heads *heads; bool keep_priority; mutex->Queue.Queue.owner = NULL; --executing->resource_count; /* * Ensure that the owner resource count is visible to all other * processors and that we read the latest priority restore * hint. */ _Atomic_Fence( ATOMIC_ORDER_ACQ_REL ); heads = mutex->Queue.Queue.heads; keep_priority = _Thread_Owns_resources( executing ) || !executing->priority_restore_hint; if ( __predict_true( heads == NULL && keep_priority ) ) { _Mutex_Queue_release( mutex, queue_context ); } else { _Thread_queue_Surrender( &mutex->Queue.Queue, MUTEX_TQ_OPERATIONS, heads, executing, keep_priority, queue_context ); } }
CORE_mutex_Status _CORE_mutex_Surrender( CORE_mutex_Control *the_mutex, #if defined(RTEMS_MULTIPROCESSING) Objects_Id id, CORE_mutex_API_mp_support_callout api_mutex_mp_support, #else Objects_Id id __attribute__((unused)), CORE_mutex_API_mp_support_callout api_mutex_mp_support __attribute__((unused)), #endif ISR_lock_Context *lock_context ) { Thread_Control *the_thread; Thread_Control *holder; holder = the_mutex->holder; /* * The following code allows a thread (or ISR) other than the thread * which acquired the mutex to release that mutex. This is only * allowed when the mutex in quetion is FIFO or simple Priority * discipline. But Priority Ceiling or Priority Inheritance mutexes * must be released by the thread which acquired them. */ if ( the_mutex->Attributes.only_owner_release ) { if ( !_Thread_Is_executing( holder ) ) { _ISR_lock_ISR_enable( lock_context ); return CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE; } } _Thread_queue_Acquire_critical( &the_mutex->Wait_queue, lock_context ); /* XXX already unlocked -- not right status */ if ( !the_mutex->nest_count ) { _Thread_queue_Release( &the_mutex->Wait_queue, lock_context ); return CORE_MUTEX_STATUS_SUCCESSFUL; } the_mutex->nest_count--; if ( the_mutex->nest_count != 0 ) { /* * All error checking is on the locking side, so if the lock was * allowed to acquired multiple times, then we should just deal with * that. The RTEMS_DEBUG is just a validation. */ #if defined(RTEMS_DEBUG) switch ( the_mutex->Attributes.lock_nesting_behavior ) { case CORE_MUTEX_NESTING_ACQUIRES: _Thread_queue_Release( &the_mutex->Wait_queue, lock_context ); return CORE_MUTEX_STATUS_SUCCESSFUL; #if defined(RTEMS_POSIX_API) case CORE_MUTEX_NESTING_IS_ERROR: /* should never occur */ _Thread_queue_Release( &the_mutex->Wait_queue, lock_context ); return CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED; #endif case CORE_MUTEX_NESTING_BLOCKS: /* Currently no API exercises this behavior. */ break; } #else _Thread_queue_Release( &the_mutex->Wait_queue, lock_context ); /* must be CORE_MUTEX_NESTING_ACQUIRES or we wouldn't be here */ return CORE_MUTEX_STATUS_SUCCESSFUL; #endif } /* * Formally release the mutex before possibly transferring it to a * blocked thread. */ if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) || _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) { CORE_mutex_Status pop_status = _CORE_mutex_Pop_priority( the_mutex, holder ); if ( pop_status != CORE_MUTEX_STATUS_SUCCESSFUL ) { _Thread_queue_Release( &the_mutex->Wait_queue, lock_context ); return pop_status; } holder->resource_count--; } the_mutex->holder = NULL; /* * Now we check if another thread was waiting for this mutex. If so, * transfer the mutex to that thread. */ if ( ( the_thread = _Thread_queue_First_locked( &the_mutex->Wait_queue ) ) ) { /* * We must extract the thread now since this will restore its default * thread lock. This is necessary to avoid a deadlock in the * _Thread_Change_priority() below due to a recursive thread queue lock * acquire. */ _Thread_queue_Extract_locked( &the_mutex->Wait_queue, the_thread ); #if defined(RTEMS_MULTIPROCESSING) _Thread_Dispatch_disable(); if ( _Objects_Is_local_id( the_thread->Object.id ) ) #endif { the_mutex->holder = the_thread; the_mutex->nest_count = 1; switch ( the_mutex->Attributes.discipline ) { case CORE_MUTEX_DISCIPLINES_FIFO: case CORE_MUTEX_DISCIPLINES_PRIORITY: break; case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT: _CORE_mutex_Push_priority( the_mutex, the_thread ); the_thread->resource_count++; break; case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING: _CORE_mutex_Push_priority( the_mutex, the_thread ); the_thread->resource_count++; _Thread_Raise_priority( the_thread, the_mutex->Attributes.priority_ceiling ); break; } } _Thread_queue_Unblock_critical( &the_mutex->Wait_queue, the_thread, lock_context ); #if defined(RTEMS_MULTIPROCESSING) if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { the_mutex->holder = NULL; the_mutex->nest_count = 1; ( *api_mutex_mp_support)( the_thread, id ); } _Thread_Dispatch_enable( _Per_CPU_Get() ); #endif } else { _Thread_queue_Release( &the_mutex->Wait_queue, lock_context ); } /* * Whether or not someone is waiting for the mutex, an * inherited priority must be lowered if this is the last * mutex (i.e. resource) this task has. */ if ( !_Thread_Owns_resources( holder ) ) { /* * Ensure that the holder resource count is visible to all other processors * and that we read the latest priority restore hint. */ _Atomic_Fence( ATOMIC_ORDER_ACQ_REL ); if ( holder->priority_restore_hint ) { Per_CPU_Control *cpu_self; cpu_self = _Thread_Dispatch_disable(); _Thread_Restore_priority( holder ); _Thread_Dispatch_enable( cpu_self ); } } return CORE_MUTEX_STATUS_SUCCESSFUL; }