...
Files
os.h/os_q.c
Prototype
Code Block |
---|
OS_MSG_QTY OSQFlush (OS_Q *p_q,
OS_ERR *p_err) |
Arguments
p_q
is a pointer to the message queue.
...
- Queues must be created before they are used.
- 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 | ||
---|---|---|
| ||
OS_Q CommQ;
void Task (void *p_arg)
{
OS_ERR err;
OS_MSG_QTY entries;
(void)&p_arg;
while (DEF_ON) {
:
:
entries = OSQFlush(&CommQ,
&err);
/* Check "err" */
:
:
}
} |
or, to flush a queue that contains entries, instead you can use OSQPend()
and specify the OS_OPT_PEND_NON_BLOCKING
option.
Code Block | ||
---|---|---|
| ||
OS_Q CommQ;
void Task (void *p_arg)
{
OS_ERR err;
CPU_TS ts;
OS_MSG_SIZE msg_size;
(void)&p_arg;
:
do {
OSQPend(&CommQ,
0,
OS_OPT_PEND_NON_BLOCKING,
&msg_size,
&ts,
&err);
} while (err != OS_ERR_PEND_WOULD_BLOCK);
:
:
} |