diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-13 10:28:14 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-20 07:49:39 +0200 |
commit | da82656065d09f7b6aa411ba361287afdd787204 (patch) | |
tree | 3a17cae7059c89d111642cb27a1cf55ded61f604 /cpukit/posix/src/cancel.c | |
parent | score: Avoid Giant lock for _Thread_Start() (diff) | |
download | rtems-da82656065d09f7b6aa411ba361287afdd787204.tar.bz2 |
posix: Rework thread cancellation
Add Thread_Life_state::THREAD_LIFE_CHANGE_DEFERRED and rework the POSIX
thread cancellation to use the thread life states.
Update #2555.
Update #2626.
Diffstat (limited to '')
-rw-r--r-- | cpukit/posix/src/cancel.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/cpukit/posix/src/cancel.c b/cpukit/posix/src/cancel.c index f103d6574b..9519c45e52 100644 --- a/cpukit/posix/src/cancel.c +++ b/cpukit/posix/src/cancel.c @@ -9,6 +9,8 @@ * COPYRIGHT (c) 1989-2008. * On-Line Applications Research Corporation (OAR). * + * Copyright (c) 2016 embedded brains GmbH. + * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rtems.org/license/LICENSE. @@ -23,46 +25,43 @@ #include <rtems/score/isr.h> #include <rtems/score/threadimpl.h> -#include <rtems/posix/cancel.h> -#include <rtems/posix/threadsup.h> /* * 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181 */ -int pthread_cancel( - pthread_t thread -) +int pthread_cancel( pthread_t thread ) { - Thread_Control *the_thread; - POSIX_API_Control *thread_support; - Objects_Locations location; + Thread_Control *the_thread; + ISR_lock_Context lock_context; + Thread_Control *executing; + Per_CPU_Control *cpu_self; /* * Don't even think about deleting a resource from an ISR. */ - if ( _ISR_Is_in_progress() ) + if ( _ISR_Is_in_progress() ) { return EPROTO; + } - the_thread = _Thread_Get( thread, &location ); - switch ( location ) { + the_thread = _Thread_Get_interrupt_disable( thread, &lock_context ); - case OBJECTS_LOCAL: - thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ]; + if ( the_thread == NULL ) { + return ESRCH; + } - thread_support->cancelation_requested = 1; + cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); + _ISR_lock_ISR_enable( &lock_context ); - /* This enables dispatch implicitly */ - _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch( the_thread ); - return 0; + executing = _Per_CPU_Get_executing( cpu_self ); -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( the_thread == executing ) { + _Thread_Exit( executing, THREAD_LIFE_TERMINATING, PTHREAD_CANCELED ); + } else { + _Thread_Cancel( the_thread, executing, PTHREAD_CANCELED ); } - return ESRCH; + _Thread_Dispatch_enable( cpu_self ); + return 0; } |