aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/STM32/NASA-OSAL-STM32F407-DISCOVERY/chconf.h4
-rw-r--r--os/common/abstractions/nasa_osal/src/osapi.c28
2 files changed, 23 insertions, 9 deletions
diff --git a/demos/STM32/NASA-OSAL-STM32F407-DISCOVERY/chconf.h b/demos/STM32/NASA-OSAL-STM32F407-DISCOVERY/chconf.h
index 2ddded71e..731b07adb 100644
--- a/demos/STM32/NASA-OSAL-STM32F407-DISCOVERY/chconf.h
+++ b/demos/STM32/NASA-OSAL-STM32F407-DISCOVERY/chconf.h
@@ -420,7 +420,8 @@
* @details User fields added to the end of the @p thread_t structure.
*/
#define CH_CFG_THREAD_EXTRA_FIELDS \
- /* Add threads custom fields here.*/
+ /* Add threads custom fields here.*/ \
+ void *osal_delete_handler;
/**
* @brief Threads initialization hook.
@@ -431,6 +432,7 @@
*/
#define CH_CFG_THREAD_INIT_HOOK(tp) { \
/* Add threads initialization code here.*/ \
+ tp->osal_delete_handler = NULL; \
}
/**
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;
}
/**