summaryrefslogtreecommitdiffstats
path: root/cpukit/posix
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-05-22 20:38:03 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-05-22 20:38:03 +0000
commit345fc11da9dcad5faa23f9888c8f3a0260e8ad45 (patch)
tree561c791f8d6342c00391dea6c1dd47f08ac82612 /cpukit/posix
parent2008-05-22 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-345fc11da9dcad5faa23f9888c8f3a0260e8ad45.tar.bz2
2008-05-22 Joel Sherrill <joel.sherrill@oarcorp.com>
* itron/include/rtems/itron/task.h, itron/src/del_tsk.c, itron/src/exd_tsk.c, itron/src/task.c, posix/include/rtems/posix/threadsup.h, posix/src/cancel.c, posix/src/cancelrun.c, posix/src/pthread.c, posix/src/pthreadexit.c, posix/src/setcancelstate.c, posix/src/setcanceltype.c, posix/src/testcancel.c, rtems/src/taskdelete.c, score/inline/rtems/score/object.inl, score/src/objectclose.c, score/src/threadclose.c: Make all task delete/exit/cancel routines follow the same critical section pattern. Also ensure that POSIX cancelation routines are run at thread exit.
Diffstat (limited to 'cpukit/posix')
-rw-r--r--cpukit/posix/include/rtems/posix/threadsup.h49
-rw-r--r--cpukit/posix/src/cancel.c16
-rw-r--r--cpukit/posix/src/cancelrun.c16
-rw-r--r--cpukit/posix/src/pthread.c7
-rw-r--r--cpukit/posix/src/pthreadexit.c34
-rw-r--r--cpukit/posix/src/setcancelstate.c11
-rw-r--r--cpukit/posix/src/setcanceltype.c9
-rw-r--r--cpukit/posix/src/testcancel.c10
8 files changed, 105 insertions, 47 deletions
diff --git a/cpukit/posix/include/rtems/posix/threadsup.h b/cpukit/posix/include/rtems/posix/threadsup.h
index a9e2b97ee0..e0d5ce9132 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -3,7 +3,7 @@
*/
/*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -20,27 +20,68 @@
#include <rtems/score/coresem.h>
#include <rtems/score/tqdata.h>
+/*!
+ * This defines the POSIX API support structure associated with
+ * each thread in a system with POSIX configured.
+ */
typedef struct {
+ /** This is the POSIX threads attribute set. */
pthread_attr_t Attributes;
+ /** This indicates whether the thread is attached or detached. */
int detachstate;
+ /** This is the set of threads waiting for the thread to exit. */
Thread_queue_Control Join_List;
+ /** This is the thread's current scheduling policy. */
int schedpolicy;
+ /** This is the thread's current set of scheduling parameters. */
struct sched_param schedparam;
+ /**
+ * This is the high priority to execute at when using the sporadic
+ * scheduler.
+ */
int ss_high_priority;
+ /**
+ * This is the timer which controls when the thread executes at
+ * high and low priority when using the sporadic scheduler.
+ */
Watchdog_Control Sporadic_timer;
+ /** This is the set of signals which are currently blocked. */
sigset_t signals_blocked;
+ /** This is the set of signals which are currently pending. */
sigset_t signals_pending;
- /*
- * POSIX Cancelability
- */
+ /*******************************************************************/
+ /*******************************************************************/
+ /*************** POSIX Cancelability ***************/
+ /*******************************************************************/
+ /*******************************************************************/
+
+ /** This is the cancelability state. */
int cancelability_state;
+ /** This is the cancelability type. */
int cancelability_type;
+ /** This indicates if a cancelation has been requested. */
int cancelation_requested;
+ /** This is the set of cancelation handlers. */
Chain_Control Cancellation_Handlers;
} POSIX_API_Control;
+/*!
+ * @brief POSIX Thread Exit Shared Helper
+ *
+ * This method is a helper routine which ensures that all
+ * POSIX thread calls which result in a thread exiting will
+ * do so in the same manner.
+ *
+ * @param[in] the_thread is the thread exiting or being canceled
+ * @param[in] value_ptr is the value to be returned by the thread
+ */
+void _POSIX_Thread_Exit(
+ Thread_Control *the_thread,
+ void *value_ptr
+);
+
#endif
/* end of include file */
diff --git a/cpukit/posix/src/cancel.c b/cpukit/posix/src/cancel.c
index a10dd86735..9a3b18481a 100644
--- a/cpukit/posix/src/cancel.c
+++ b/cpukit/posix/src/cancel.c
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -34,9 +34,10 @@ int pthread_cancel(
pthread_t thread
)
{
- Thread_Control *the_thread;
- POSIX_API_Control *thread_support;
- Objects_Locations location;
+ Thread_Control *the_thread;
+ POSIX_API_Control *thread_support;
+ Objects_Locations location;
+ boolean cancel = FALSE;
/*
* Don't even think about deleting a resource from an ISR.
@@ -54,11 +55,12 @@ int pthread_cancel(
thread_support->cancelation_requested = 1;
if (thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
- thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS) {
- _POSIX_Threads_cancel_run( the_thread );
- }
+ thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS)
+ cancel = TRUE;
_Thread_Enable_dispatch();
+ if ( cancel )
+ _POSIX_Thread_Exit( the_thread, PTHREAD_CANCELED );
return 0;
#if defined(RTEMS_MULTIPROCESSING)
diff --git a/cpukit/posix/src/cancelrun.c b/cpukit/posix/src/cancelrun.c
index fff75ac1e4..8ac96a762d 100644
--- a/cpukit/posix/src/cancelrun.c
+++ b/cpukit/posix/src/cancelrun.c
@@ -25,12 +25,6 @@
#include <rtems/posix/pthread.h>
#include <rtems/posix/threadsup.h>
-/*PAGE
- *
- * _POSIX_Threads_cancel_run
- *
- */
-
void _POSIX_Threads_cancel_run(
Thread_Control *the_thread
)
@@ -57,14 +51,4 @@ void _POSIX_Threads_cancel_run(
_Workspace_Free( handler );
}
-
- /* Now we can delete the thread */
-
- the_thread->Wait.return_argument = PTHREAD_CANCELED;
- _Thread_Close(
- _Objects_Get_information_id( the_thread->Object.id ),
- the_thread
- );
- _POSIX_Threads_Free( the_thread );
-
}
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index 840aabc891..53126e2428 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -218,13 +218,16 @@ User_extensions_routine _POSIX_Threads_Delete_extension(
/*
* Run the POSIX cancellation handlers
*/
+ _POSIX_Threads_cancel_run( deleted );
+ /*
+ * Run all the key destructors
+ */
_POSIX_Keys_Run_destructors( deleted );
/*
* Wakeup all the tasks which joined with this one
*/
-
value_ptr = (void **) deleted->Wait.return_argument;
while ( (the_thread = _Thread_queue_Dequeue( &api->Join_List )) )
diff --git a/cpukit/posix/src/pthreadexit.c b/cpukit/posix/src/pthreadexit.c
index a8781f5c58..f85e736daa 100644
--- a/cpukit/posix/src/pthreadexit.c
+++ b/cpukit/posix/src/pthreadexit.c
@@ -22,29 +22,47 @@
#include <assert.h>
#include <rtems/system.h>
+#include <rtems/score/apimutex.h>
#include <rtems/score/thread.h>
#include <rtems/posix/pthread.h>
-void pthread_exit(
- void *value_ptr
+void _POSIX_Thread_Exit(
+ Thread_Control *the_thread,
+ void *value_ptr
)
{
Objects_Information *the_information;
- the_information = _Objects_Get_information_id( _Thread_Executing->Object.id );
+ the_information = _Objects_Get_information_id( the_thread->Object.id );
/*
- * the_information has to be non-NULL. Otherwise, we couldn't be
+ * The_information has to be non-NULL. Otherwise, we couldn't be
* running in a thread of this API and class.
+ *
+ * NOTE: Lock and unlock in different order so we do not throw a
+ * fatal error when locking the allocator mutex. And after
+ * we unlock, we want to defer the context switch until we
+ * are ready to be switched out. Otherwise, an ISR could
+ * occur and preempt us out while we still hold the
+ * allocator mutex.
*/
- _Thread_Disable_dispatch();
+ _RTEMS_Lock_allocator();
+ _Thread_Disable_dispatch();
- _Thread_Executing->Wait.return_argument = value_ptr;
+ the_thread->Wait.return_argument = value_ptr;
- _Thread_Close( the_information, _Thread_Executing );
+ _Thread_Close( the_information, the_thread );
- _POSIX_Threads_Free( _Thread_Executing );
+ _POSIX_Threads_Free( the_thread );
+ _RTEMS_Unlock_allocator();
_Thread_Enable_dispatch();
}
+
+void pthread_exit(
+ void *value_ptr
+)
+{
+ _POSIX_Thread_Exit( _Thread_Executing, value_ptr );
+}
diff --git a/cpukit/posix/src/setcancelstate.c b/cpukit/posix/src/setcancelstate.c
index 9bb75cb2e7..8df8f55d4b 100644
--- a/cpukit/posix/src/setcancelstate.c
+++ b/cpukit/posix/src/setcancelstate.c
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -35,7 +35,8 @@ int pthread_setcancelstate(
int *oldstate
)
{
- POSIX_API_Control *thread_support;
+ POSIX_API_Control *thread_support;
+ boolean cancel = FALSE;
/*
* Don't even think about deleting a resource from an ISR.
@@ -61,8 +62,10 @@ int pthread_setcancelstate(
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
thread_support->cancelation_requested )
- _POSIX_Threads_cancel_run( _Thread_Executing );
- _Thread_Enable_dispatch();
+ cancel = TRUE;
+ _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 6a8a0c9860..fbd7beadf2 100644
--- a/cpukit/posix/src/setcanceltype.c
+++ b/cpukit/posix/src/setcanceltype.c
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -35,7 +35,8 @@ int pthread_setcanceltype(
int *oldtype
)
{
- POSIX_API_Control *thread_support;
+ POSIX_API_Control *thread_support;
+ boolean cancel = FALSE;
/*
* Don't even think about deleting a resource from an ISR.
@@ -61,8 +62,10 @@ int pthread_setcanceltype(
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
thread_support->cancelation_requested )
- _POSIX_Threads_cancel_run( _Thread_Executing );
+ cancel = TRUE;
_Thread_Enable_dispatch();
+ if ( cancel )
+ _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED );
return 0;
}
diff --git a/cpukit/posix/src/testcancel.c b/cpukit/posix/src/testcancel.c
index 2f60f6545f..2c60b0e72c 100644
--- a/cpukit/posix/src/testcancel.c
+++ b/cpukit/posix/src/testcancel.c
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -32,7 +32,8 @@
void pthread_testcancel( void )
{
- POSIX_API_Control *thread_support;
+ POSIX_API_Control *thread_support;
+ boolean cancel = FALSE;
/*
* Don't even think about deleting a resource from an ISR.
@@ -48,6 +49,9 @@ void pthread_testcancel( void )
_Thread_Disable_dispatch();
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
thread_support->cancelation_requested )
- _POSIX_Threads_cancel_run( _Thread_Executing );
+ cancel = TRUE;
_Thread_Enable_dispatch();
+
+ if ( cancel )
+ _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED );
}