summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-02-28 16:15:35 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-02-28 16:15:35 +0000
commit5088d978385ce6d28db1731aab57b23ca1f6e9cc (patch)
tree2e061c7ff3c5287ac53f2945421425209cb2c33e /cpukit/score
parent2008-02-28 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-5088d978385ce6d28db1731aab57b23ca1f6e9cc.tar.bz2
2008-02-28 Joel Sherrill <joel.sherrill@oarcorp.com>
* itron/include/rtems/itron/task.h, itron/src/cre_tsk.c, posix/src/pthreadcreate.c, rtems/src/taskcreate.c, rtems/src/taskdelete.c, rtems/src/timerserver.c, score/src/threadclose.c, score/src/threadcreateidle.c, score/src/threadinitialize.c: Switch task create and delete operations to using API Allocator Mutex. This moves almost all uses of the RTEMS Workspace from dispatching disabled to mutex protected which should improve deterministic behavior. The implementation was carefully done to allow task create and delete extensions to invoke more services. In particular, a task delete extension should be able to do mutex and file operations.
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/src/threadclose.c32
-rw-r--r--cpukit/score/src/threadcreateidle.c11
-rw-r--r--cpukit/score/src/threadinitialize.c12
3 files changed, 48 insertions, 7 deletions
diff --git a/cpukit/score/src/threadclose.c b/cpukit/score/src/threadclose.c
index e506b2666d..f8231a1192 100644
--- a/cpukit/score/src/threadclose.c
+++ b/cpukit/score/src/threadclose.c
@@ -2,7 +2,7 @@
* Thread Handler
*
*
- * COPYRIGHT (c) 1989-1999.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -45,10 +45,30 @@ void _Thread_Close(
Thread_Control *the_thread
)
{
+ /*
+ * We assume the Allocator Mutex is locked when we get here.
+ * This provides sufficient protection to let the user extensions
+ * run but as soon as we get back, we will make the thread
+ * disappear and set a transient state on it. So we temporarily
+ * unnest dispatching.
+ */
+ _Thread_Unnest_dispatch();
+
_User_extensions_Thread_delete( the_thread );
+ _Thread_Disable_dispatch();
+
+ /*
+ * Now we are in a dispatching critical section again and we
+ * can take the thread OUT of the published set. It is invalid
+ * to use this thread's Id after this call.
+ */
_Objects_Close( information, &the_thread->Object );
+ /*
+ * By setting the transient state, the thread will not be considered
+ * for scheduling when we remove any blocking states.
+ */
_Thread_Set_state( the_thread, STATES_TRANSIENT );
if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) {
@@ -56,6 +76,9 @@ void _Thread_Close(
(void) _Watchdog_Remove( &the_thread->Timer );
}
+ /*
+ * The thread might have been FP. So deal with that.
+ */
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
if ( _Thread_Is_allocated_fp( the_thread ) )
@@ -67,11 +90,14 @@ void _Thread_Close(
(void) _Workspace_Free( the_thread->Start.fp_context );
#endif
+ /*
+ * Free the rest of the memory associated with this task
+ * and set the associated pointers to NULL for safety.
+ */
_Thread_Stack_Free( the_thread );
+ the_thread->Start.stack = NULL;
if ( the_thread->extensions )
(void) _Workspace_Free( the_thread->extensions );
-
- the_thread->Start.stack = NULL;
the_thread->extensions = NULL;
}
diff --git a/cpukit/score/src/threadcreateidle.c b/cpukit/score/src/threadcreateidle.c
index 602fc7840b..3eaff869cf 100644
--- a/cpukit/score/src/threadcreateidle.c
+++ b/cpukit/score/src/threadcreateidle.c
@@ -2,7 +2,7 @@
* Thread Handler
*
*
- * COPYRIGHT (c) 1989-1999.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -68,6 +68,13 @@ void _Thread_Create_idle( void )
if ( idle_task_stack_size < STACK_MINIMUM_SIZE )
idle_task_stack_size = STACK_MINIMUM_SIZE;
+ /*
+ * This is only called during initialization and we better be sure
+ * that when _Thread_Initialize unnests dispatch that we do not
+ * do anything stupid.
+ */
+ _Thread_Disable_dispatch();
+
_Thread_Initialize(
&_Thread_Internal_information,
_Thread_Idle,
@@ -82,6 +89,8 @@ void _Thread_Create_idle( void )
(Objects_Name) _Thread_Idle_name
);
+ _Thread_Unnest_dispatch();
+
/*
* WARNING!!! This is necessary to "kick" start the system and
* MUST be done before _Thread_Start is invoked.
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index b2e09727cc..7ef9125a46 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -2,7 +2,7 @@
* Thread Handler
*
*
- * COPYRIGHT (c) 1989-2006.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -61,6 +61,7 @@ boolean _Thread_Initialize(
void *fp_area;
#endif
void *extensions_area;
+ boolean extension_status;
/*
* Initialize the Ada self pointer
@@ -220,10 +221,15 @@ boolean _Thread_Initialize(
_Objects_Open( information, &the_thread->Object, name );
/*
- * Invoke create extensions
+ * We assume the Allocator Mutex is locked and dispatching is
+ * enabled when we get here. We want to be able to run the
+ * user extensions with dispatching enabled. The Allocator
+ * Mutex provides sufficient protection to let the user extensions
+ * run safely.
*/
+ extension_status = _User_extensions_Thread_create( the_thread );
- if ( !_User_extensions_Thread_create( the_thread ) ) {
+ if ( !extension_status ) {
if ( extensions_area )
(void) _Workspace_Free( extensions_area );