diff options
-rw-r--r-- | cpukit/ChangeLog | 9 | ||||
-rw-r--r-- | cpukit/posix/Makefile.am | 6 | ||||
-rw-r--r-- | cpukit/posix/include/rtems/posix/cancel.h | 17 | ||||
-rw-r--r-- | cpukit/posix/src/cancel.c | 12 | ||||
-rw-r--r-- | cpukit/posix/src/canceleval.c | 37 | ||||
-rw-r--r-- | cpukit/posix/src/setcancelstate.c | 19 | ||||
-rw-r--r-- | cpukit/posix/src/setcanceltype.c | 20 |
7 files changed, 81 insertions, 39 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 039f90527e..69f2e1cfea 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,12 @@ +2009-07-21 Santosh G Vattam <vattam.santosh@gmail.com> + + * posix/Makefile.am, posix/include/rtems/posix/cancel.h, + posix/src/cancel.c, posix/src/setcancelstate.c, + posix/src/setcanceltype.c: Add + _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch method to + avoid duplication of code and ease coverage analysis. + * posix/src/canceleval.c: New file. + 2009-07-20 Joel Sherrill <joel.sherrill@OARcorp.com> * score/src/corebarrierwait.c: Reverse order of tests to increase test diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am index 9bbfb67079..270a6e0b71 100644 --- a/cpukit/posix/Makefile.am +++ b/cpukit/posix/Makefile.am @@ -69,9 +69,9 @@ libposix_a_SOURCES += src/barrierattrdestroy.c src/barrierattrgetpshared.c \ src/pbarriertranslatereturncode.c src/pbarrierwait.c ## CANCEL_C_FILES -libposix_a_SOURCES += src/cancel.c src/cancelrun.c src/cleanuppop.c \ - src/cleanuppush.c src/setcancelstate.c src/setcanceltype.c \ - src/testcancel.c +libposix_a_SOURCES += src/cancel.c src/canceleval.c src/cancelrun.c \ + src/cleanuppop.c src/cleanuppush.c src/setcancelstate.c \ + src/setcanceltype.c src/testcancel.c ## CONDITION_VARIABLE_C_FILES libposix_a_SOURCES += src/cond.c src/condattrdestroy.c \ diff --git a/cpukit/posix/include/rtems/posix/cancel.h b/cpukit/posix/include/rtems/posix/cancel.h index 9f1437667b..228c60c7c4 100644 --- a/cpukit/posix/include/rtems/posix/cancel.h +++ b/cpukit/posix/include/rtems/posix/cancel.h @@ -3,7 +3,7 @@ */ /* - * COPYRIGHT (c) 1989-2007. + * COPYRIGHT (c) 1989-2009. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -16,6 +16,8 @@ #ifndef _RTEMS_POSIX_CANCEL_H #define _RTEMS_POSIX_CANCEL_H +#include <rtems/posix/threadsup.h> + typedef struct { Chain_Node Node; void (*routine)( void * ); @@ -35,5 +37,18 @@ void _POSIX_Threads_cancel_run( Thread_Control *the_thread ); +/* + * _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch + * + * DESCRIPTION: + * + * This routine separates a piece of code that existed as part of + * another routine, but had to be separated to improve coverage. + */ + +void _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch ( + POSIX_API_Control *thread_support +); + #endif /* end of include file */ diff --git a/cpukit/posix/src/cancel.c b/cpukit/posix/src/cancel.c index 56a574e9e4..76049fca8c 100644 --- a/cpukit/posix/src/cancel.c +++ b/cpukit/posix/src/cancel.c @@ -25,8 +25,7 @@ #include <rtems/posix/pthread.h> #include <rtems/posix/threadsup.h> -/*PAGE - * +/* * 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181 */ @@ -37,7 +36,6 @@ int pthread_cancel( Thread_Control *the_thread; POSIX_API_Control *thread_support; Objects_Locations location; - bool cancel = false; /* * Don't even think about deleting a resource from an ISR. @@ -54,13 +52,7 @@ int pthread_cancel( thread_support->cancelation_requested = 1; - if (thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE && - thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS) - cancel = true; - - _Thread_Enable_dispatch(); - if ( cancel ) - _POSIX_Thread_Exit( the_thread, PTHREAD_CANCELED ); + _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch( thread_support ); return 0; #if defined(RTEMS_MULTIPROCESSING) diff --git a/cpukit/posix/src/canceleval.c b/cpukit/posix/src/canceleval.c new file mode 100644 index 0000000000..72932da07f --- /dev/null +++ b/cpukit/posix/src/canceleval.c @@ -0,0 +1,37 @@ +/* + * COPYRIGHT (c) 1989-2009. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <pthread.h> +#include <rtems/system.h> +#include <rtems/score/thread.h> +#include <rtems/posix/cancel.h> +#include <rtems/posix/pthread.h> + +void _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch( + POSIX_API_Control *thread_support +) +{ + bool cancel = false; + + if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE && + thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS && + thread_support->cancelation_requested ) + cancel = true; + + _Thread_Enable_dispatch(); + + if ( cancel ) + _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED ); +} diff --git a/cpukit/posix/src/setcancelstate.c b/cpukit/posix/src/setcancelstate.c index f11d865366..6d5cc30108 100644 --- a/cpukit/posix/src/setcancelstate.c +++ b/cpukit/posix/src/setcancelstate.c @@ -1,5 +1,5 @@ /* - * COPYRIGHT (c) 1989-2008. + * COPYRIGHT (c) 1989-2009. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -20,13 +20,11 @@ #include <rtems/score/chain.h> #include <rtems/score/isr.h> #include <rtems/score/thread.h> -#include <rtems/score/wkspace.h> #include <rtems/posix/cancel.h> #include <rtems/posix/pthread.h> #include <rtems/posix/threadsup.h> -/*PAGE - * +/* * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183 */ @@ -36,7 +34,6 @@ int pthread_setcancelstate( ) { POSIX_API_Control *thread_support; - bool cancel = false; /* * Don't even think about deleting a resource from an ISR. @@ -59,13 +56,11 @@ int pthread_setcancelstate( *oldstate = thread_support->cancelability_state; thread_support->cancelability_state = state; - if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE && - thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS && - thread_support->cancelation_requested ) - cancel = true; + _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch( thread_support ); + + /* + * _Thread_Enable_dispatch is invoked by above call. + */ - _Thread_Enable_dispatch(); - if ( cancel ) - _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED ); return 0; } diff --git a/cpukit/posix/src/setcanceltype.c b/cpukit/posix/src/setcanceltype.c index 403e16b812..628bc38dbc 100644 --- a/cpukit/posix/src/setcanceltype.c +++ b/cpukit/posix/src/setcanceltype.c @@ -1,5 +1,5 @@ /* - * COPYRIGHT (c) 1989-2008. + * COPYRIGHT (c) 1989-2009. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -20,13 +20,11 @@ #include <rtems/score/chain.h> #include <rtems/score/isr.h> #include <rtems/score/thread.h> -#include <rtems/score/wkspace.h> #include <rtems/posix/cancel.h> #include <rtems/posix/pthread.h> #include <rtems/posix/threadsup.h> -/*PAGE - * +/* * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183 */ @@ -36,7 +34,6 @@ int pthread_setcanceltype( ) { POSIX_API_Control *thread_support; - bool cancel = false; /* * Don't even think about deleting a resource from an ISR. @@ -59,13 +56,10 @@ int pthread_setcanceltype( *oldtype = thread_support->cancelability_type; thread_support->cancelability_type = type; - if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE && - thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS && - thread_support->cancelation_requested ) - cancel = true; - _Thread_Enable_dispatch(); - if ( cancel ) - _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED ); - + _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch( thread_support ); + + /* + * _Thread_Enable_dispatch is invoked by above call. + */ return 0; } |