How to use Task Release Service
PXROS-HR API provides these functions for task termination:
PxError_t PxTerminate(PxBool_t release);
PxError_t PxTaskForceTermination(PxTask_t taskId);
PxError_t PxDie(void);
Self-termination
If the self-termination is successfully requested, the following functions for self-termination will never return as the task ends up suspended. The error code is only returned if the error occurs during the termination request.
PxTerminate()
has an option to release resources allocated by the task and then calls PxDie()
.
errRes = PxTerminate(true); // Release resources = true
if (errRes != PXERR_NOERROR)
PxPanic();
PxDie()
ensures the task ID is put to the PxDieSrv Task Release Queue and sends the PXSERVICE_TASK_DIED
event to the Task Release Service, which ensures its termination. PXSERVICE_TASK_DIED
is a system reserved event defined in the "pxdef.h" header file.
errRes = PxDie();
if (errRes != PXERR_NOERROR)
PxPanic();
Forced termination
PXROS-HR API also offers a way how to terminate other tasks. The caller of PxTaskForceTermination(taskId)
must be the direct creator of the task to terminate (parent). The task that is forced to be terminated has no option for how to react to this action.
/* Create the task that will be later directly terminated */
PxTask_t forcedTermination = ForcedTermination_Create(FORCEDTERMINATION_PRIO,
(PxEvents_t) 0,
PXMcTaskdefault,
PXOpoolTaskdefault);
if (PxTaskIdError(forcedTermination) != PXERR_NOERROR)
PxPanic();
...
/* Do the forced termination of the created task */
errRes = PxTaskForceTermination(forcedTermination);
if (errRes != PXERR_NOERROR)
PxPanic();