|
Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
|
A LIFO is a typed view of a queue, so the same rule applies as for the FIFO: a user thread needs the underlying k_queue granted to it. More...
Macros | |
| #define | k_lifo_init(lifo) |
| Initialize a LIFO queue. | |
| #define | k_lifo_put(lifo, data) |
| Add an element to a LIFO queue. | |
| #define | k_lifo_alloc_put(lifo, data) |
| Add an element to a LIFO queue. | |
| #define | k_lifo_get(lifo, timeout) |
| Get an element from a LIFO queue. | |
| #define | K_LIFO_DEFINE(name) |
| Statically define and initialize a LIFO queue. | |
A LIFO is a typed view of a queue, so the same rule applies as for the FIFO: a user thread needs the underlying k_queue granted to it.
k_lifo_init(), k_lifo_alloc_put() and k_lifo_get() expand to system calls and are callable from a user thread, while k_lifo_put() expands to k_queue_prepend(), which is supervisor mode only.
|
isr-ok |
#include <zephyr/kernel.h>
Add an element to a LIFO queue.
This routine adds data to the head of lifo, like k_lifo_put(), except that the queue link is taken from a pool instead of from data itself. The link is released automatically once the item has been retrieved, and the first pointer-sized field of data stays available to the caller. The data is not copied.
The link is allocated from the resource pool of the calling thread, or from the system heap when called from ISR context. A thread inherits the resource pool of the thread that creates it, and the main thread starts on the system heap when CONFIG_HEAP_MEM_POOL_SIZE is set, so threads have a pool by default; see k_thread_heap_assign() and k_thread_system_pool_assign(). Only a thread left without a pool fails here, with -ENOMEM, and it does so whether or not CONFIG_HEAP_MEM_POOL_SIZE is set.
If a thread is already waiting in k_lifo_get() on lifo, data is handed to that thread directly, no link is allocated, and this routine cannot fail.
| lifo | Address of the LIFO. |
| data | Address of the data item. |
| 0 | on success |
| -ENOMEM | The resource pool of the calling thread has insufficient RAM |
| #define K_LIFO_DEFINE | ( | name | ) |
#include <zephyr/kernel.h>
Statically define and initialize a LIFO queue.
The LIFO queue can be accessed outside the module where it is defined using:
| name | Name of the fifo. |
|
isr-ok |
#include <zephyr/kernel.h>
Get an element from a LIFO queue.
This routine removes and returns the most recently added data item of lifo.
When the item was added by k_lifo_alloc_put(), the link allocated on its behalf is released here and the caller receives the original data pointer. The queue lock is released before the call returns.
| lifo | Address of the LIFO queue. |
| timeout | Waiting period to obtain a data item, or one of the special values K_NO_WAIT and K_FOREVER. |
| non-NULL | Address of the data item that was removed. |
| NULL | The LIFO was empty and timeout was K_NO_WAIT, or the waiting period expired. |
| #define k_lifo_init | ( | lifo | ) |
#include <zephyr/kernel.h>
Initialize a LIFO queue.
This routine initializes a LIFO queue object, prior to its first use. The LIFO is left empty, with no thread waiting on it.
| lifo | Address of the LIFO queue. |
|
isr-ok |
#include <zephyr/kernel.h>
Add an element to a LIFO queue.
This routine adds data to the head of lifo, so that it is the next item k_lifo_get() returns.
The item is not copied. The LIFO keeps its link in the first pointer-sized field of data, which is why that field is reserved for the kernel and why data must be aligned as required for a pointer. The item must stay valid until it has been retrieved with k_lifo_get(), and the reserved field must not be written to while it is queued. The rest of the item stays available to the caller and may be updated in place.
If a thread is already waiting in k_lifo_get() on lifo, data is handed to that thread directly and never enters the LIFO.
| lifo | Address of the LIFO queue. |
| data | Address of the data item. |