...
Files
os.h/os_task.c
Prototype
Code Block |
---|
OS_MSG_QTY OSTaskQFlush (OS_TCB *p_tcb,
OS_ERR *p_err) |
Arguments
p_tcb
is a pointer to the TCB of the task that contains the queue to flush. Specifying a NULL
pointer tells OSTaskQFlush()
to flush the queue of the calling task’s built-in message queue.
...
- Use this function with great care. When flushing a queue, you lose the references to what the queue entries are pointing to, potentially causing 'memory leaks'. The data that the user is pointing to that is referenced by the queue entries should, most likely, be de-allocated (i.e., freed).
Example Usage
Code Block | ||
---|---|---|
| ||
void Task (void *p_arg)
{
OS_ERR err;
OS_MSG_QTY entries;
(void)&p_arg;
while (DEF_ON) {
:
:
entries = OSTaskQFlush((OS_TCB *)0,
&err);
/* Check "err" */
:
:
}
}
|
or, to flush a queue that contains entries, instead you can use OSTaskQPend()
and specify the OS_OPT_PEND_NON_BLOCKING
option.
Code Block | ||
---|---|---|
| ||
void Task (void *p_arg)
{
OS_ERR err;
CPU_TS ts;
OS_MSG_SIZE msg_size;
(void)&p_arg;
:
do {
OSTaskQPend(0,
OS_OPT_PEND_NON_BLOCKING,
&msg_size,
&ts,
&err);
} while (err != OS_ERR_PEND_WOULD_BLOCK);
:
:
} |