diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2016-02-26 10:28:00 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2016-02-26 10:28:00 +0000 |
commit | a6eed37d26ba0ca617e8e1f3b3eca31449a26fdb (patch) | |
tree | 12c26c9f611a6194e640b9283d28c261fa2c67b1 /os/common/abstractions/nasa_osal/src/osapi.c | |
parent | e628eeb8528f8d23d47ca5bf04ab0ee4fe3238ca (diff) | |
download | ChibiOS-a6eed37d26ba0ca617e8e1f3b3eca31449a26fdb.tar.gz ChibiOS-a6eed37d26ba0ca617e8e1f3b3eca31449a26fdb.tar.bz2 ChibiOS-a6eed37d26ba0ca617e8e1f3b3eca31449a26fdb.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8950 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/common/abstractions/nasa_osal/src/osapi.c')
-rw-r--r-- | os/common/abstractions/nasa_osal/src/osapi.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/os/common/abstractions/nasa_osal/src/osapi.c b/os/common/abstractions/nasa_osal/src/osapi.c index a367c339b..0a805a99a 100644 --- a/os/common/abstractions/nasa_osal/src/osapi.c +++ b/os/common/abstractions/nasa_osal/src/osapi.c @@ -1311,7 +1311,8 @@ int32 OS_TaskCreate(uint32 *task_id, /* Checking if this working area is already in use by some thread, the
error code is not very appropriate but this case seems to not be
coveded by the specification.*/
- if ((tp = chRegFindThreadByWorkingArea((stkalign_t *)stack_pointer)) != NULL) {
+ tp = chRegFindThreadByWorkingArea((stkalign_t *)stack_pointer);
+ if (tp != NULL) {
/* Releasing the thread reference.*/
chThdRelease(tp);
return OS_ERR_NO_FREE_IDS;
@@ -1339,8 +1340,10 @@ int32 OS_TaskCreate(uint32 *task_id, NULL
};
- /* Creating the task.*/
+ /* Creating the task and detaching it, other APIs will have to gain a
+ reference using the registry API.*/
tp = chThdCreate(&td);
+ chThdRelease(tp);
/* Storing the task id.*/
*task_id = (uint32)tp;
@@ -1377,8 +1380,9 @@ int32 OS_TaskInstallDeleteHandler(void *function_pointer) { */
int32 OS_TaskDelete(uint32 task_id) {
thread_t *tp = (thread_t *)task_id;
+ funcptr_t fp;
- /* Check for thread validity.*/
+ /* Check for thread validity, getting a reference.*/
if (chRegFindThreadByPointer(tp) == NULL) {
return OS_ERR_INVALID_ID;
}
@@ -1386,17 +1390,17 @@ int32 OS_TaskDelete(uint32 task_id) { /* Asking for thread termination.*/
chThdTerminate(tp);
- /* Waiting for termination.*/
+ /* Getting the delete handler while the thread is still referenced.*/
+ fp = (funcptr_t)tp->osal_delete_handler;
+
+ /* Waiting for termination, releasing the reference.*/
chThdWait(tp);
/* Calling the delete handler, if defined.*/
- if (tp->osal_delete_handler != NULL) {
- ((funcptr_t)(tp->osal_delete_handler))();
+ if (fp != NULL) {
+ fp();
}
- /* Releasing the thread reference.*/
- chThdRelease(tp);
-
return OS_SUCCESS;
}
|