int pthread_setcancelstate( int state, int *oldstate ) { POSIX_API_Control *thread_support; Thread_Control *executing; /* * Don't even think about deleting a resource from an ISR. * Besides this request is supposed to be for _Thread_Executing * and the ISR context is not a thread. */ if ( _ISR_Is_in_progress() ) return EPROTO; if ( !oldstate ) return EINVAL; if ( state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE ) return EINVAL; _Thread_Disable_dispatch(); executing = _Thread_Executing; thread_support = executing ->API_Extensions[ THREAD_API_POSIX ]; *oldstate = thread_support->cancelability_state; thread_support->cancelability_state = state; _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch( executing ); /* * _Thread_Enable_dispatch is invoked by above call. */ return 0; }
int pthread_cancel( pthread_t thread ) { Thread_Control *the_thread; POSIX_API_Control *thread_support; Objects_Locations location; /* * Don't even think about deleting a resource from an ISR. */ if ( _ISR_Is_in_progress() ) return EPROTO; the_thread = _Thread_Get( thread, &location ); switch ( location ) { case OBJECTS_LOCAL: thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ]; thread_support->cancelation_requested = 1; /* This enables dispatch implicitly */ _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch( the_thread ); return 0; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: #endif case OBJECTS_ERROR: break; } return EINVAL; }