summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems
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/rtems
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/rtems')
-rw-r--r--cpukit/rtems/src/taskcreate.c16
-rw-r--r--cpukit/rtems/src/taskdelete.c6
-rw-r--r--cpukit/rtems/src/timerserver.c55
3 files changed, 46 insertions, 31 deletions
diff --git a/cpukit/rtems/src/taskcreate.c b/cpukit/rtems/src/taskcreate.c
index 99e6628c92..38d924ad39 100644
--- a/cpukit/rtems/src/taskcreate.c
+++ b/cpukit/rtems/src/taskcreate.c
@@ -2,7 +2,7 @@
* RTEMS Task Manager
*
*
- * COPYRIGHT (c) 1989-1999.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -31,6 +31,7 @@
#include <rtems/score/wkspace.h>
#include <rtems/score/apiext.h>
#include <rtems/score/sysstate.h>
+#include <rtems/score/apimutex.h>
/*PAGE
*
@@ -133,10 +134,9 @@ rtems_status_code rtems_task_create(
*/
/*
- * Disable dispatch for protection
+ * Lock the allocator mutex for protection
*/
-
- _Thread_Disable_dispatch();
+ _RTEMS_Lock_allocator();
/*
* Allocate the thread control block and -- if the task is global --
@@ -151,7 +151,7 @@ rtems_status_code rtems_task_create(
the_thread = _RTEMS_tasks_Allocate();
if ( !the_thread ) {
- _Thread_Enable_dispatch();
+ _RTEMS_Unlock_allocator();
return RTEMS_TOO_MANY;
}
@@ -161,7 +161,7 @@ rtems_status_code rtems_task_create(
if ( _Objects_MP_Is_null_global_object( the_global_object ) ) {
_RTEMS_tasks_Free( the_thread );
- _Thread_Enable_dispatch();
+ _RTEMS_Unlock_allocator();
return RTEMS_TOO_MANY;
}
}
@@ -193,7 +193,7 @@ rtems_status_code rtems_task_create(
_Objects_MP_Free_global_object( the_global_object );
#endif
_RTEMS_tasks_Free( the_thread );
- _Thread_Enable_dispatch();
+ _RTEMS_Unlock_allocator();
return RTEMS_UNSATISFIED;
}
@@ -224,6 +224,6 @@ rtems_status_code rtems_task_create(
}
#endif
- _Thread_Enable_dispatch();
+ _RTEMS_Unlock_allocator();
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/taskdelete.c b/cpukit/rtems/src/taskdelete.c
index 890596866b..c7b1edb60c 100644
--- a/cpukit/rtems/src/taskdelete.c
+++ b/cpukit/rtems/src/taskdelete.c
@@ -31,6 +31,7 @@
#include <rtems/score/wkspace.h>
#include <rtems/score/apiext.h>
#include <rtems/score/sysstate.h>
+#include <rtems/score/apimutex.h>
/*PAGE
*
@@ -58,6 +59,8 @@ rtems_status_code rtems_task_delete(
Objects_Locations location;
Objects_Information *the_information;
+ _RTEMS_Lock_allocator();
+
the_thread = _Thread_Get( id, &location );
switch ( location ) {
@@ -89,11 +92,13 @@ rtems_status_code rtems_task_delete(
}
#endif
+ _RTEMS_Unlock_allocator();
_Thread_Enable_dispatch();
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE:
+ _RTEMS_Unlock_allocator();
_Thread_Dispatch();
return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
#endif
@@ -102,5 +107,6 @@ rtems_status_code rtems_task_delete(
break;
}
+ _RTEMS_Unlock_allocator();
return RTEMS_INVALID_ID;
}
diff --git a/cpukit/rtems/src/timerserver.c b/cpukit/rtems/src/timerserver.c
index ff1fc97099..00a91e8937 100644
--- a/cpukit/rtems/src/timerserver.c
+++ b/cpukit/rtems/src/timerserver.c
@@ -147,6 +147,8 @@ rtems_status_code rtems_timer_initiate_server(
rtems_id id;
rtems_status_code status;
rtems_task_priority _priority;
+ static boolean initialized = FALSE;
+ boolean tmpInitialized;
/*
* Make sure the requested priority is valid. The if is
@@ -162,15 +164,16 @@ rtems_status_code rtems_timer_initiate_server(
}
/*
- * Just to make sure the test versus create/start operation are atomic.
+ * Just to make sure this is only called once.
*/
_Thread_Disable_dispatch();
+ tmpInitialized = initialized;
+ initialized = TRUE;
+ _Thread_Enable_dispatch();
- if ( _Timer_Server ) {
- _Thread_Enable_dispatch();
+ if ( tmpInitialized )
return RTEMS_INCORRECT_STATE;
- }
/*
* Create the Timer Server with the name the name of "TIME". The attribute
@@ -198,26 +201,14 @@ rtems_status_code rtems_timer_initiate_server(
&id /* get the id back */
);
if (status) {
- _Thread_Enable_dispatch();
+ initialized = FALSE;
return status;
}
- status = rtems_task_start(
- id, /* the id from create */
- (rtems_task_entry) _Timer_Server_body, /* the timer server entry point */
- 0 /* there is no argument */
- );
- if (status) {
- /*
- * One would expect a call to rtems_task_delete() here to clean up
- * but there is actually no way (in normal circumstances) that the
- * start can fail. The id and starting address are known to be
- * be good. If this service fails, something is weirdly wrong on the
- * target such as a stray write in an ISR or incorrect memory layout.
- */
- _Thread_Enable_dispatch();
- return status;
- }
+ /*
+ * Do all the data structure initialization before starting the
+ * Timer Server so we do not have to have a critical section.
+ */
/*
* We work with the TCB pointer, not the ID, so we need to convert
@@ -246,9 +237,27 @@ rtems_status_code rtems_timer_initiate_server(
_Watchdog_Initialize( &_Timer_Server->Timer, _Thread_Delay_ended, id, NULL );
_Watchdog_Initialize( &_Timer_Seconds_timer, _Thread_Delay_ended, id, NULL );
+ /*
+ * Start the timer server
+ */
- _Thread_Enable_dispatch();
- return RTEMS_SUCCESSFUL;
+ status = rtems_task_start(
+ id, /* the id from create */
+ (rtems_task_entry) _Timer_Server_body, /* the timer server entry point */
+ 0 /* there is no argument */
+ );
+ if (status) {
+ /*
+ * One would expect a call to rtems_task_delete() here to clean up
+ * but there is actually no way (in normal circumstances) that the
+ * start can fail. The id and starting address are known to be
+ * be good. If this service fails, something is weirdly wrong on the
+ * target such as a stray write in an ISR or incorrect memory layout.
+ */
+ initialized = FALSE;
+ }
+
+ return status;
}
/*PAGE