rtems_status_code rtems_task_resume( rtems_id id ) { Thread_Control *the_thread; Objects_Locations location; States_Control previous_state; the_thread = _Thread_Get( id, &location ); switch ( location ) { case OBJECTS_LOCAL: previous_state = _Thread_Clear_state( the_thread, STATES_SUSPENDED ); _Objects_Put( &the_thread->Object ); return _States_Is_suspended( previous_state ) ? RTEMS_SUCCESSFUL : RTEMS_INCORRECT_STATE; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: return _RTEMS_tasks_MP_Send_request_packet( RTEMS_TASKS_MP_RESUME_REQUEST, id, 0, /* Not used */ 0, /* Not used */ 0 /* Not used */ ); #endif case OBJECTS_ERROR: break; } return RTEMS_INVALID_ID; }
static void thread_resume( Thread_Control *thread ) { #if defined( PREVENT_SMP_ASSERT_FAILURES ) _Thread_Disable_dispatch(); #endif _Thread_Clear_state( thread, STATES_SUSPENDED ); #if defined( PREVENT_SMP_ASSERT_FAILURES ) _Thread_Unnest_dispatch(); #endif }
static void _Thread_Request_life_change( Thread_Control *the_thread, Thread_Control *executing, Priority_Control priority, Thread_Life_state additional_life_state ) { Thread_Life_state previous_life_state; Per_CPU_Control *cpu; ISR_Level level; const Scheduler_Control *scheduler; cpu = _Thread_Action_ISR_disable_and_acquire( the_thread, &level ); previous_life_state = the_thread->Life.state; the_thread->Life.state = previous_life_state | additional_life_state; _Thread_Action_release_and_ISR_enable( cpu, level ); scheduler = _Scheduler_Get( the_thread ); if ( the_thread == executing ) { executing->real_priority = priority; _Scheduler_Set_priority_if_higher( scheduler, the_thread, priority ); _Thread_Start_life_change_for_executing( executing ); } else if ( previous_life_state == THREAD_LIFE_NORMAL ) { _Thread_Start_life_change( the_thread, scheduler, priority ); } else { _Thread_Clear_state( the_thread, STATES_SUSPENDED ); if ( _Thread_Is_life_terminating( additional_life_state ) ) { the_thread->real_priority = _Scheduler_Highest_priority_of_two( scheduler, the_thread->real_priority, priority ); _Scheduler_Change_priority_if_higher( scheduler, the_thread, priority, false ); } } }
void complete_test( void ) { uint32_t index; rtems_id task_id; ISR_lock_Context lock_context; Thread_queue_Context queue_context; benchmark_timer_initialize(); thread_resume( Middle_tcb ); thread_resume_time = benchmark_timer_read(); _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE ); benchmark_timer_initialize(); _Thread_Unblock( Middle_tcb ); thread_unblock_time = benchmark_timer_read(); _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE ); benchmark_timer_initialize(); _Thread_Clear_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE ); thread_ready_time = benchmark_timer_read(); benchmark_timer_initialize(); for ( index=1 ; index <= OPERATION_COUNT ; index++ ) (void) benchmark_timer_empty_function(); overhead = benchmark_timer_read(); task_id = Middle_tcb->Object.id; benchmark_timer_initialize(); for ( index=1 ; index <= OPERATION_COUNT ; index++ ) { (void) _Thread_Get( task_id, &lock_context ); _ISR_lock_ISR_enable( &lock_context ); } thread_get_time = benchmark_timer_read(); benchmark_timer_initialize(); for ( index=1 ; index <= OPERATION_COUNT ; index++ ) { (void) _Semaphore_Get( Semaphore_id, &queue_context ); _ISR_lock_ISR_enable( &queue_context.Lock_context ); } semaphore_get_time = benchmark_timer_read(); benchmark_timer_initialize(); for ( index=1 ; index <= OPERATION_COUNT ; index++ ) { (void) _Thread_Get( 0x3, &lock_context ); _ISR_lock_ISR_enable( &lock_context ); } thread_get_invalid_time = benchmark_timer_read(); /* * This is the running task and we have tricked RTEMS out enough where * we need to set some internal tracking information to match this. */ set_thread_heir( _Thread_Get_executing() ); set_thread_dispatch_necessary( false ); /* * Now dump all the times */ put_time( "rtems interrupt: _ISR_Local_disable", isr_disable_time, 1, 0, 0 ); put_time( "rtems interrupt: _ISR_Local_flash", isr_flash_time, 1, 0, 0 ); put_time( "rtems interrupt: _ISR_Local_enable", isr_enable_time, 1, 0, 0 ); put_time( "rtems internal: _Thread_Dispatch_disable", thread_disable_dispatch_time, 1, 0, 0 ); put_time( "rtems internal: _Thread_Dispatch_enable", thread_enable_dispatch_time, 1, 0, 0 ); put_time( "rtems internal: _Thread_Set_state", thread_set_state_time, 1, 0, 0 ); put_time( "rtems internal: _Thread_Dispatch NO FP", thread_dispatch_no_fp_time, 1, 0, 0 ); put_time( "rtems internal: context switch: no floating point contexts", context_switch_no_fp_time, 1, 0, 0 ); put_time( "rtems internal: context switch: self", context_switch_self_time, 1, 0, 0 ); put_time( "rtems internal: context switch to another task", context_switch_another_task_time, 1, 0, 0 ); #if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1) put_time( "rtems internal: fp context switch restore 1st FP task", context_switch_restore_1st_fp_time, 1, 0, 0 ); put_time( "rtems internal: fp context switch save idle and restore initialized", context_switch_save_idle_restore_initted_time, 1, 0, 0 ); put_time( "rtems internal: fp context switch save idle, restore idle", context_switch_save_restore_idle_time, 1, 0, 0 ); put_time( "rtems internal: fp context switch save initialized, restore initialized", context_switch_save_restore_initted_time, 1, 0, 0 ); #else puts( "rtems internal: fp context switch restore 1st FP task - NA\n" "rtems internal: fp context switch save idle restore initialized - NA\n" "rtems internal: fp context switch save idle restore idle - NA\n" "rtems internal: fp context switch save initialized\n" " restore initialized - NA" ); #endif put_time( "rtems internal: _Thread_Resume", thread_resume_time, 1, 0, 0 ); put_time( "rtems internal: _Thread_Unblock", thread_unblock_time, 1, 0, 0 ); put_time( "rtems internal: _Thread_Ready", thread_ready_time, 1, 0, 0 ); put_time( "rtems internal: _Thread_Get", thread_get_time, OPERATION_COUNT, 0, 0 ); put_time( "rtems internal: _Semaphore_Get", semaphore_get_time, OPERATION_COUNT, 0, 0 ); put_time( "rtems internal: _Thread_Get: invalid id", thread_get_invalid_time, OPERATION_COUNT, 0, 0 ); TEST_END(); rtems_test_exit( 0 ); }
static void thread_resume( Thread_Control *thread ) { _Thread_Clear_state( thread, STATES_SUSPENDED ); }
int pthread_join( pthread_t thread, void **value_ptr ) { register Thread_Control *the_thread; POSIX_API_Control *api; Objects_Locations location; void *return_pointer; on_EINTR: the_thread = _Thread_Get( thread, &location ); switch ( location ) { case OBJECTS_LOCAL: api = the_thread->API_Extensions[ THREAD_API_POSIX ]; if ( api->detachstate == PTHREAD_CREATE_DETACHED ) { _Thread_Enable_dispatch(); return EINVAL; } if ( _Thread_Is_executing( the_thread ) ) { _Thread_Enable_dispatch(); return EDEADLK; } /* * Put ourself on the threads join list */ if ( the_thread->current_state == (STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT) ) { return_pointer = the_thread->Wait.return_argument; _Thread_Clear_state( the_thread, (STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT) ); } else { _Thread_Executing->Wait.return_argument = &return_pointer; _Thread_queue_Enter_critical_section( &api->Join_List ); _Thread_queue_Enqueue( &api->Join_List, WATCHDOG_NO_TIMEOUT ); } _Thread_Enable_dispatch(); if ( _Thread_Executing->Wait.return_code == EINTR ) goto on_EINTR; if ( value_ptr ) *value_ptr = return_pointer; return 0; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: #endif case OBJECTS_ERROR: break; } return ESRCH; }
rtems_status_code rtems_rate_monotonic_period( rtems_id id, rtems_interval length ) { Rate_monotonic_Control *the_period; Objects_Locations location; rtems_status_code return_value; rtems_rate_monotonic_period_states local_state; ISR_Level level; the_period = _Rate_monotonic_Get( id, &location ); switch ( location ) { case OBJECTS_LOCAL: if ( !_Thread_Is_executing( the_period->owner ) ) { _Thread_Enable_dispatch(); return RTEMS_NOT_OWNER_OF_RESOURCE; } if ( length == RTEMS_PERIOD_STATUS ) { switch ( the_period->state ) { case RATE_MONOTONIC_INACTIVE: return_value = RTEMS_NOT_DEFINED; break; case RATE_MONOTONIC_EXPIRED: case RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING: return_value = RTEMS_TIMEOUT; break; case RATE_MONOTONIC_ACTIVE: default: /* unreached -- only to remove warnings */ return_value = RTEMS_SUCCESSFUL; break; } _Thread_Enable_dispatch(); return( return_value ); } _ISR_Disable( level ); if ( the_period->state == RATE_MONOTONIC_INACTIVE ) { _ISR_Enable( level ); the_period->next_length = length; /* * Baseline statistics information for the beginning of a period. */ _Rate_monotonic_Initiate_statistics( the_period ); the_period->state = RATE_MONOTONIC_ACTIVE; _Watchdog_Initialize( &the_period->Timer, _Rate_monotonic_Timeout, id, NULL ); _Watchdog_Insert_ticks( &the_period->Timer, length ); _Thread_Enable_dispatch(); return RTEMS_SUCCESSFUL; } if ( the_period->state == RATE_MONOTONIC_ACTIVE ) { /* * Update statistics from the concluding period. */ _Rate_monotonic_Update_statistics( the_period ); /* * This tells the _Rate_monotonic_Timeout that this task is * in the process of blocking on the period and that we * may be changing the length of the next period. */ the_period->state = RATE_MONOTONIC_OWNER_IS_BLOCKING; the_period->next_length = length; _ISR_Enable( level ); _Thread_Executing->Wait.id = the_period->Object.id; _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD ); /* * Did the watchdog timer expire while we were actually blocking * on it? */ _ISR_Disable( level ); local_state = the_period->state; the_period->state = RATE_MONOTONIC_ACTIVE; _ISR_Enable( level ); /* * If it did, then we want to unblock ourself and continue as * if nothing happen. The period was reset in the timeout routine. */ if ( local_state == RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING ) _Thread_Clear_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD ); _Thread_Enable_dispatch(); return RTEMS_SUCCESSFUL; } if ( the_period->state == RATE_MONOTONIC_EXPIRED ) { /* * Update statistics from the concluding period */ _Rate_monotonic_Update_statistics( the_period ); _ISR_Enable( level ); the_period->state = RATE_MONOTONIC_ACTIVE; the_period->next_length = length; _Watchdog_Insert_ticks( &the_period->Timer, length ); _Scheduler_Release_job(the_period->owner, the_period->next_length); _Thread_Enable_dispatch(); return RTEMS_TIMEOUT; } /* * These should never happen so just return invalid Id. * - RATE_MONOTONIC_OWNER_IS_BLOCKING: * - RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING: */ #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: /* should never return this */ #endif case OBJECTS_ERROR: break; } return RTEMS_INVALID_ID; }
void _Thread_Life_action_handler( Thread_Control *executing, Thread_Action *action, Per_CPU_Control *cpu, ISR_Level level ) { Thread_Life_state previous_life_state; (void) action; previous_life_state = executing->Life.state; executing->Life.state = THREAD_LIFE_PROTECTED; _Thread_Action_release_and_ISR_enable( cpu, level ); if ( _Thread_Is_life_terminating( previous_life_state ) ) { _User_extensions_Thread_terminate( executing ); } else { _Assert( _Thread_Is_life_restarting( previous_life_state ) ); _User_extensions_Thread_restart( executing ); } _Thread_Disable_dispatch(); if ( _Thread_Is_life_terminating( previous_life_state ) ) { _Thread_Make_zombie( executing ); if ( executing->Life.terminator != NULL ) { _Thread_Clear_state( executing->Life.terminator, STATES_WAITING_FOR_TERMINATION ); } _Thread_Enable_dispatch(); _Assert_Not_reached(); } else { _Assert( _Thread_Is_life_restarting( previous_life_state ) ); if ( _Thread_Is_life_terminating( executing->Life.state ) ) { /* Someone deleted us in the mean-time */ _Thread_Start_life_change_for_executing( executing ); } else { _Assert( executing->Timer.state == WATCHDOG_INACTIVE ); _Assert( executing->current_state == STATES_READY || executing->current_state == STATES_SUSPENDED ); executing->Life.state = THREAD_LIFE_NORMAL; _Thread_Load_environment( executing ); _Thread_Restart_self( executing ); _Assert_Not_reached(); } } }