void _Thread_Reset_timeslice( void ) { ISR_Level level; Thread_Control *executing; Chain_Control *ready; executing = _Thread_Executing; ready = executing->ready; _ISR_Disable( level ); if ( _Chain_Has_only_one_node( ready ) ) { _ISR_Enable( level ); return; } _Chain_Extract_unprotected( &executing->Object.Node ); _Chain_Append_unprotected( ready, &executing->Object.Node ); _ISR_Flash( level ); if ( _Thread_Is_heir( executing ) ) _Thread_Heir = (Thread_Control *) ready->first; _Context_Switch_necessary = true; _ISR_Enable( level ); }
void _Thread_Set_transient( Thread_Control *the_thread ) { ISR_Level level; uint32_t old_state; Chain_Control *ready; ready = the_thread->ready; _ISR_Disable( level ); old_state = the_thread->current_state; the_thread->current_state = _States_Set( STATES_TRANSIENT, old_state ); if ( _States_Is_ready( old_state ) ) { if ( _Chain_Has_only_one_node( ready ) ) { _Chain_Initialize_empty( ready ); _Priority_Remove_from_bit_map( &the_thread->Priority_map ); } else _Chain_Extract_unprotected( &the_thread->Object.Node ); } _ISR_Enable( level ); }
void _Scheduler_priority_Yield(void) { Scheduler_priority_Per_thread *sched_info; ISR_Level level; Thread_Control *executing; Chain_Control *ready; executing = _Thread_Executing; sched_info = (Scheduler_priority_Per_thread *) executing->scheduler_info; ready = sched_info->ready_chain; _ISR_Disable( level ); if ( !_Chain_Has_only_one_node( ready ) ) { _Chain_Extract_unprotected( &executing->Object.Node ); _Chain_Append_unprotected( ready, &executing->Object.Node ); _ISR_Flash( level ); if ( _Thread_Is_heir( executing ) ) _Thread_Heir = (Thread_Control *) _Chain_First( ready ); _Thread_Dispatch_necessary = true; } else if ( !_Thread_Is_heir( executing ) ) _Thread_Dispatch_necessary = true; _ISR_Enable( level ); }
static void _Thread_queue_Priority_inherit_enqueue( Thread_queue_Queue *queue, Thread_Control *the_thread, Thread_queue_Path *path ) { Thread_queue_Heads *heads; Thread_Control *owner; Priority_Control priority; heads = _Thread_queue_Queue_enqueue( queue, the_thread, _Thread_queue_Priority_do_initialize, _Thread_queue_Priority_do_enqueue ); owner = queue->owner; #if defined(RTEMS_SMP) if ( _Chain_Has_only_one_node( &heads->Heads.Fifo ) ) { priority = the_thread->current_priority; } else { priority = _Scheduler_Map_priority( _Scheduler_Get_own( the_thread ), PRIORITY_PSEUDO_ISR ); } #else (void) heads; priority = the_thread->current_priority; #endif if ( priority < owner->current_priority ) { path->update_priority = owner; owner->priority_restore_hint = true; _Atomic_Fence( ATOMIC_ORDER_ACQ_REL ); _Scheduler_Thread_set_priority( owner, priority, false ); ( *owner->Wait.operations->priority_change )( owner->Wait.queue, owner, priority ); } else { path->update_priority = NULL; } }
void _Thread_queue_Boost_priority( Thread_queue_Queue *queue, Thread_Control *the_thread ) { Thread_queue_Heads *heads = queue->heads; if ( heads != NULL && ( !_Chain_Has_only_one_node( &heads->Heads.Fifo ) || _RBTree_Is_empty( &_Thread_queue_Priority_queue( heads, the_thread )->Queue ) ) ) { _Thread_Raise_priority( the_thread, PRIORITY_PSEUDO_ISR ); } }
void _Thread_Suspend( Thread_Control *the_thread ) { ISR_Level level; Chain_Control *ready; ready = the_thread->ready; _ISR_Disable( level ); #if defined(RTEMS_ITRON_API) the_thread->suspend_count++; #endif if ( !_States_Is_ready( the_thread->current_state ) ) { the_thread->current_state = _States_Set( STATES_SUSPENDED, the_thread->current_state ); _ISR_Enable( level ); return; } the_thread->current_state = STATES_SUSPENDED; if ( _Chain_Has_only_one_node( ready ) ) { _Chain_Initialize_empty( ready ); _Priority_Remove_from_bit_map( &the_thread->Priority_map ); } else _Chain_Extract_unprotected( &the_thread->Object.Node ); _ISR_Flash( level ); if ( _Thread_Is_heir( the_thread ) ) _Thread_Calculate_heir(); if ( _Thread_Is_executing( the_thread ) ) _Context_Switch_necessary = true; _ISR_Enable( level ); }
static void _Thread_queue_Boost_priority( Thread_queue_Heads *heads, Thread_Control *the_thread ) { #if defined(RTEMS_SMP) if ( !_Chain_Has_only_one_node( &heads->Heads.Fifo ) ) { const Scheduler_Control *scheduler; Priority_Control boost_priority; the_thread->priority_restore_hint = true; _Atomic_Fence( ATOMIC_ORDER_ACQ_REL ); scheduler = _Scheduler_Get_own( the_thread ); boost_priority = _Scheduler_Map_priority( scheduler, PRIORITY_PSEUDO_ISR ); _Scheduler_Thread_set_priority( the_thread, boost_priority, false ); } #else (void) heads; (void) the_thread; #endif }
void _Thread_Set_state( Thread_Control *the_thread, States_Control state ) { ISR_Level level; Chain_Control *ready; ready = the_thread->ready; _ISR_Disable( level ); if ( !_States_Is_ready( the_thread->current_state ) ) { the_thread->current_state = _States_Set( state, the_thread->current_state ); _ISR_Enable( level ); return; } the_thread->current_state = state; if ( _Chain_Has_only_one_node( ready ) ) { _Chain_Initialize_empty( ready ); _Priority_Remove_from_bit_map( &the_thread->Priority_map ); } else _Chain_Extract_unprotected( &the_thread->Object.Node ); _ISR_Flash( level ); if ( _Thread_Is_heir( the_thread ) ) _Thread_Calculate_heir(); if ( _Thread_Is_executing( the_thread ) ) _Context_Switch_necessary = TRUE; _ISR_Enable( level ); }
Thread_Control *_Thread_queue_Dequeue_priority( Thread_queue_Control *the_thread_queue ) { uint32_t index; ISR_Level level; Thread_Control *the_thread = NULL; /* just to remove warnings */ Thread_Control *new_first_thread; Chain_Node *head; Chain_Node *tail; Chain_Node *new_first_node; Chain_Node *new_second_node; Chain_Node *last_node; Chain_Node *next_node; Chain_Node *previous_node; _ISR_Disable( level ); for( index=0 ; index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ; index++ ) { if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) { the_thread = (Thread_Control *) _Chain_First( &the_thread_queue->Queues.Priority[ index ] ); goto dequeue; } } /* * We did not find a thread to unblock. */ _ISR_Enable( level ); return NULL; dequeue: the_thread->Wait.queue = NULL; new_first_node = _Chain_First( &the_thread->Wait.Block2n ); new_first_thread = (Thread_Control *) new_first_node; next_node = the_thread->Object.Node.next; previous_node = the_thread->Object.Node.previous; if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) { last_node = _Chain_Last( &the_thread->Wait.Block2n ); new_second_node = new_first_node->next; previous_node->next = new_first_node; next_node->previous = new_first_node; new_first_node->next = next_node; new_first_node->previous = previous_node; if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) { /* > two threads on 2-n */ head = _Chain_Head( &new_first_thread->Wait.Block2n ); tail = _Chain_Tail( &new_first_thread->Wait.Block2n ); new_second_node->previous = head; head->next = new_second_node; tail->previous = last_node; last_node->next = tail; } } else { previous_node->next = next_node; next_node->previous = previous_node; } if ( !_Watchdog_Is_active( &the_thread->Timer ) ) { _ISR_Enable( level ); _Thread_Unblock( the_thread ); } else { _Watchdog_Deactivate( &the_thread->Timer ); _ISR_Enable( level ); (void) _Watchdog_Remove( &the_thread->Timer ); _Thread_Unblock( the_thread ); } #if defined(RTEMS_MULTIPROCESSING) if ( !_Objects_Is_local_id( the_thread->Object.id ) ) _Thread_MP_Free_proxy( the_thread ); #endif return( the_thread ); }