Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

void  OSSemDel (OS_SEM  *p_sem,
                OS_OPT   opt,
                OS_ERR  *p_err)

File

Called from

Code enabled by

os_sem.c

Task only

OS_CFG_SEM_EN and OS_CFG_SEM_DEL_EN

OSSemDel() is used to delete a semaphore. This function should be used with care as multiple tasks may rely on the presence of the semaphore. Generally speaking, before deleting a semaphore, first delete all the tasks that access the semaphore. As a rule, it is highly recommended to not delete kernel objects at run time.

Deleting the semaphore will not de-allocate the object. In other words, storage for the variable will still remain at the same location unless the semaphore is allocated dynamically from the heap. The dynamic allocation of objects has its own set of problems. Specifically, it is not recommended for embedded systems to allocate (and de-allocate) objects from the heap given the high likelihood of fragmentation.

Arguments

p_sem

is a pointer to the semaphore.

opt

specifies one of two options: OS_OPT_DEL_NO_PEND or OS_OPT_DEL_ALWAYS.

OS_OPT_DEL_NO_PEND specifies to delete the semaphore only if no task is waiting on the semaphore. Because no task is “currently” waiting on the semaphore does not mean that a task will not attempt to wait for the semaphore later. How would such a task handle the situation waiting for a semaphore that was deleted? The application code will have to deal with this eventuality.

OS_OPT_DEL_ALWAYS specifies deleting the semaphore, regardless of whether tasks are waiting on the semaphore or not. If there are tasks waiting on the semaphore, these tasks will be made ready-to-run and informed (through an appropriate error code) that the reason the task is readied is that the semaphore it was waiting on was deleted. The same reasoning applies with the other option, how will the tasks handle the fact that the semaphore they want to wait for is no longer available?

p_err

is a pointer to a variable used to hold an error code. The error code may be one of the following:

OS_ERR_NONE

if the call is successful and the semaphore has been deleted.

OS_ERR_DEL_ISR

if OS_CFG_CALLED_FROM_ISR_CHK_EN set to 1 in os_cfg.h: if attempting to delete the semaphore from an ISR.

OS_ERR_OBJ_PTR_NULL

if OS_CFG_ARG_CHK_EN is set to 1 in os_cfg.h: if p_sem is a NULL pointer.

OS_ERR_OBJ_TYPE

if OS_CFG_OBJ_TYPE_CHK_EN is set to 1 in os_cfg.h: if p_sem is not pointing to a semaphore.

OS_ERR_OPT_INVALID

if OS_CFG_ARG_CHK_EN is set to 1 in os_cfg.h: if one of the two options mentioned in the opt argument is not specified.

OS_ERR_TASK_WAITING

if one or more tasks are waiting on the semaphore.

Returned Value

None

Notes/Warnings

Use this call with care because other tasks might expect the presence of the semaphore.

Example

  • No labels