diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2016-02-24 15:45:33 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2016-02-24 15:45:33 +0000 |
commit | 658ce96ddb728ae9128a01928036b012aa5017ee (patch) | |
tree | 8192a9fd98d91abb7bd87c0578c276ebc50c83c1 /os | |
parent | 8faa787ebe7a161a1947afd0d37525cd99d6b141 (diff) | |
download | ChibiOS-658ce96ddb728ae9128a01928036b012aa5017ee.tar.gz ChibiOS-658ce96ddb728ae9128a01928036b012aa5017ee.tar.bz2 ChibiOS-658ce96ddb728ae9128a01928036b012aa5017ee.zip |
Implemented delete handler.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8943 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r-- | os/common/abstractions/nasa_osal/src/osapi.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/os/common/abstractions/nasa_osal/src/osapi.c b/os/common/abstractions/nasa_osal/src/osapi.c index 9d02cd05e..775dffe26 100644 --- a/os/common/abstractions/nasa_osal/src/osapi.c +++ b/os/common/abstractions/nasa_osal/src/osapi.c @@ -81,6 +81,11 @@ /*===========================================================================*/
/**
+ * @brief Generic function pointer type.
+ */
+typedef void (*funcptr_t)(void);
+
+/**
* @brief Type of OSAL timer.
*/
typedef struct {
@@ -1301,7 +1306,7 @@ int32 OS_TaskCreate(uint32 *task_id, /**
* @brief Installs a deletion handler.
- * @note It is not currently implemented.
+ * @note It is implemented as hooks in chconf.h.
*
* @param[in] function_pointer the handler function
* @return An error code.
@@ -1310,14 +1315,16 @@ int32 OS_TaskCreate(uint32 *task_id, */
int32 OS_TaskInstallDeleteHandler(void *function_pointer) {
- (void)function_pointer;
+ chThdGetSelfX()->osal_delete_handler = function_pointer;
- return OS_ERR_NOT_IMPLEMENTED;
+ return OS_SUCCESS;
}
/**
* @brief Task delete.
- * @note It is not currently implemented.
+ * @note Limitation, it does not actually kill the thread, it just sets a
+ * flag in the thread that has then to terminate volountarly. The
+ * flag can be checked using @p chThdShouldTerminateX().
*
* @param[in] task_id the task id
* @return An error code.
@@ -1335,13 +1342,18 @@ int32 OS_TaskDelete(uint32 task_id) { /* Asking for thread termination.*/
chThdTerminate(tp);
- /* Releasing the thread reference.*/
- chThdRelease(tp);
-
/* Waiting for termination.*/
chThdWait(tp);
- return OS_ERR_NOT_IMPLEMENTED;
+ /* Calling the delete handler, if defined.*/
+ if (tp->osal_delete_handler != NULL) {
+ ((funcptr_t)(tp->osal_delete_handler))();
+ }
+
+ /* Releasing the thread reference.*/
+ chThdRelease(tp);
+
+ return OS_SUCCESS;
}
/**
|