diff --git a/include/kernel.h b/include/kernel.h index 611de311840..651d1915d07 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -1283,19 +1283,12 @@ static inline int k_queue_is_empty(struct k_queue *queue) */ struct k_fifo { - _wait_q_t wait_q; - sys_slist_t data_q; - _POLL_EVENT; - - _OBJECT_TRACING_NEXT_PTR(k_fifo); + struct k_queue _queue; }; #define K_FIFO_INITIALIZER(obj) \ { \ - .wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \ - .data_q = SYS_SLIST_STATIC_INIT(&obj.data_q), \ - _POLL_EVENT_OBJ_INIT \ - _OBJECT_TRACING_INIT \ + ._queue = K_QUEUE_INITIALIZER(obj._queue) \ } /** @@ -1317,7 +1310,8 @@ struct k_fifo { * * @return N/A */ -extern void k_fifo_init(struct k_fifo *fifo); +#define k_fifo_init(fifo) \ + k_queue_init((struct k_queue *) fifo) /** * @brief Add an element to a fifo. @@ -1333,7 +1327,8 @@ extern void k_fifo_init(struct k_fifo *fifo); * * @return N/A */ -extern void k_fifo_put(struct k_fifo *fifo, void *data); +#define k_fifo_put(fifo, data) \ + k_queue_append((struct k_queue *) fifo, data) /** * @brief Atomically add a list of elements to a fifo. @@ -1351,7 +1346,8 @@ extern void k_fifo_put(struct k_fifo *fifo, void *data); * * @return N/A */ -extern void k_fifo_put_list(struct k_fifo *fifo, void *head, void *tail); +#define k_fifo_put_list(fifo, head, tail) \ + k_queue_append_list((struct k_queue *) fifo, head, tail) /** * @brief Atomically add a list of elements to a fifo. @@ -1368,7 +1364,8 @@ extern void k_fifo_put_list(struct k_fifo *fifo, void *head, void *tail); * * @return N/A */ -extern void k_fifo_put_slist(struct k_fifo *fifo, sys_slist_t *list); +#define k_fifo_put_slist(fifo, list) \ + k_queue_merge_slist((struct k_queue *) fifo, list) /** * @brief Get an element from a fifo. @@ -1385,7 +1382,8 @@ extern void k_fifo_put_slist(struct k_fifo *fifo, sys_slist_t *list); * @return Address of the data item if successful; NULL if returned * without waiting, or waiting period timed out. */ -extern void *k_fifo_get(struct k_fifo *fifo, int32_t timeout); +#define k_fifo_get(fifo, timeout) \ + k_queue_get((struct k_queue *) fifo, timeout) /** * @brief Query a fifo to see if it has data available. @@ -1400,10 +1398,8 @@ extern void *k_fifo_get(struct k_fifo *fifo, int32_t timeout); * @return Non-zero if the fifo is empty. * @return 0 if data is available. */ -static inline int k_fifo_is_empty(struct k_fifo *fifo) -{ - return (int)sys_slist_is_empty(&fifo->data_q); -} +#define k_fifo_is_empty(fifo) \ + k_queue_is_empty((struct k_queue *) fifo) /** * @brief Statically define and initialize a fifo. @@ -1416,7 +1412,7 @@ static inline int k_fifo_is_empty(struct k_fifo *fifo) */ #define K_FIFO_DEFINE(name) \ struct k_fifo name \ - __in_section(_k_fifo, static, name) = \ + __in_section(_k_queue, static, name) = \ K_FIFO_INITIALIZER(name) /** @@ -3430,6 +3426,7 @@ struct k_poll_event { struct k_poll_signal *signal; struct k_sem *sem; struct k_fifo *fifo; + struct k_queue *queue; }; }; diff --git a/include/linker/common-ram.ld b/include/linker/common-ram.ld index a2f320bd9b6..365466612cf 100644 --- a/include/linker/common-ram.ld +++ b/include/linker/common-ram.ld @@ -72,13 +72,6 @@ _k_queue_list_end = .; } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) - SECTION_DATA_PROLOGUE(_k_fifo_area, (OPTIONAL),) - { - _k_fifo_list_start = .; - KEEP(*(SORT_BY_NAME("._k_fifo.static.*"))) - _k_fifo_list_end = .; - } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) - SECTION_DATA_PROLOGUE(_k_lifo_area, (OPTIONAL),) { _k_lifo_list_start = .; diff --git a/kernel/Makefile b/kernel/Makefile index 4585cac30cb..fb2aa22e9a5 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -20,7 +20,6 @@ lib-y += $(strip \ mutex.o \ queue.o \ lifo.o \ - fifo.o \ stack.o \ mem_slab.o \ mem_pool.o \ diff --git a/kernel/fifo.c b/kernel/fifo.c deleted file mode 100644 index 49cc08099b9..00000000000 --- a/kernel/fifo.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2010-2016 Wind River Systems, Inc. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * - * @brief dynamic-size FIFO queue object. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern struct k_fifo _k_fifo_list_start[]; -extern struct k_fifo _k_fifo_list_end[]; - -struct k_fifo *_trace_list_k_fifo; - -#ifdef CONFIG_OBJECT_TRACING - -/* - * Complete initialization of statically defined fifos. - */ -static int init_fifo_module(struct device *dev) -{ - ARG_UNUSED(dev); - - struct k_fifo *fifo; - - for (fifo = _k_fifo_list_start; fifo < _k_fifo_list_end; fifo++) { - SYS_TRACING_OBJ_INIT(k_fifo, fifo); - } - return 0; -} - -SYS_INIT(init_fifo_module, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS); - -#endif /* CONFIG_OBJECT_TRACING */ - -void k_fifo_init(struct k_fifo *fifo) -{ - sys_slist_init(&fifo->data_q); - sys_dlist_init(&fifo->wait_q); - - _INIT_OBJ_POLL_EVENT(fifo); - - SYS_TRACING_OBJ_INIT(k_fifo, fifo); -} - -static void prepare_thread_to_run(struct k_thread *thread, void *data) -{ - _abort_thread_timeout(thread); - _ready_thread(thread); - _set_thread_return_value_with_data(thread, 0, data); -} - -/* returns 1 if a reschedule must take place, 0 otherwise */ -static inline int handle_poll_event(struct k_fifo *fifo) -{ -#ifdef CONFIG_POLL - uint32_t state = K_POLL_STATE_FIFO_DATA_AVAILABLE; - - return fifo->poll_event ? - _handle_obj_poll_event(&fifo->poll_event, state) : 0; -#else - return 0; -#endif -} - -void k_fifo_put(struct k_fifo *fifo, void *data) -{ - struct k_thread *first_pending_thread; - unsigned int key; - - key = irq_lock(); - - first_pending_thread = _unpend_first_thread(&fifo->wait_q); - - if (first_pending_thread) { - prepare_thread_to_run(first_pending_thread, data); - if (!_is_in_isr() && _must_switch_threads()) { - (void)_Swap(key); - return; - } - } else { - sys_slist_append(&fifo->data_q, data); - if (handle_poll_event(fifo)) { - (void)_Swap(key); - return; - } - } - - irq_unlock(key); -} - -void k_fifo_put_list(struct k_fifo *fifo, void *head, void *tail) -{ - __ASSERT(head && tail, "invalid head or tail"); - - struct k_thread *first_thread, *thread; - unsigned int key; - - key = irq_lock(); - - first_thread = _peek_first_pending_thread(&fifo->wait_q); - while (head && ((thread = _unpend_first_thread(&fifo->wait_q)))) { - prepare_thread_to_run(thread, head); - head = *(void **)head; - } - - if (head) { - sys_slist_append_list(&fifo->data_q, head, tail); - } - - if (first_thread) { - if (!_is_in_isr() && _must_switch_threads()) { - (void)_Swap(key); - return; - } - } else { - if (handle_poll_event(fifo)) { - (void)_Swap(key); - return; - } - } - - irq_unlock(key); -} - -void k_fifo_put_slist(struct k_fifo *fifo, sys_slist_t *list) -{ - __ASSERT(!sys_slist_is_empty(list), "list must not be empty"); - - /* - * note: this works as long as: - * - the slist implementation keeps the next pointer as the first - * field of the node object type - * - list->tail->next = NULL. - */ - return k_fifo_put_list(fifo, list->head, list->tail); -} - -void *k_fifo_get(struct k_fifo *fifo, int32_t timeout) -{ - unsigned int key; - void *data; - - key = irq_lock(); - - if (likely(!sys_slist_is_empty(&fifo->data_q))) { - data = sys_slist_get_not_empty(&fifo->data_q); - irq_unlock(key); - return data; - } - - if (timeout == K_NO_WAIT) { - irq_unlock(key); - return NULL; - } - - _pend_current_thread(&fifo->wait_q, timeout); - - return _Swap(key) ? NULL : _current->base.swap_data; -} diff --git a/kernel/poll.c b/kernel/poll.c index 47df903387c..5386cc6c408 100644 --- a/kernel/poll.c +++ b/kernel/poll.c @@ -67,8 +67,8 @@ static inline int is_condition_met(struct k_poll_event *event, uint32_t *state) return 1; } break; - case K_POLL_TYPE_FIFO_DATA_AVAILABLE: - if (!k_fifo_is_empty(event->fifo)) { + case K_POLL_TYPE_DATA_AVAILABLE: + if (!k_queue_is_empty(event->queue)) { *state = K_POLL_STATE_FIFO_DATA_AVAILABLE; return 1; } @@ -100,15 +100,15 @@ static inline int register_event(struct k_poll_event *event) } event->sem->poll_event = event; break; - case K_POLL_TYPE_FIFO_DATA_AVAILABLE: - __ASSERT(event->fifo, "invalid fifo\n"); - if (event->fifo->poll_event) { + case K_POLL_TYPE_DATA_AVAILABLE: + __ASSERT(event->queue, "invalid queue\n"); + if (event->queue->poll_event) { return -EADDRINUSE; } - event->fifo->poll_event = event; + event->queue->poll_event = event; break; case K_POLL_TYPE_SIGNAL: - __ASSERT(event->fifo, "invalid poll signal\n"); + __ASSERT(event->queue, "invalid poll signal\n"); if (event->signal->poll_event) { return -EADDRINUSE; } @@ -135,9 +135,9 @@ static inline void clear_event_registration(struct k_poll_event *event) __ASSERT(event->sem, "invalid semaphore\n"); event->sem->poll_event = NULL; break; - case K_POLL_TYPE_FIFO_DATA_AVAILABLE: - __ASSERT(event->fifo, "invalid fifo\n"); - event->fifo->poll_event = NULL; + case K_POLL_TYPE_DATA_AVAILABLE: + __ASSERT(event->queue, "invalid queue\n"); + event->queue->poll_event = NULL; break; case K_POLL_TYPE_SIGNAL: __ASSERT(event->signal, "invalid poll signal\n"); diff --git a/samples/testing/unit/main.c b/samples/testing/unit/main.c index 88a30b2cb72..75547d2ce52 100644 --- a/samples/testing/unit/main.c +++ b/samples/testing/unit/main.c @@ -17,20 +17,20 @@ void irq_unlock(unsigned int key) #include -void k_fifo_init(struct k_fifo *fifo) {} -void k_fifo_put_list(struct k_fifo *fifo, void *head, void *tail) {} +void k_queue_init(struct k_queue *fifo) {} +void k_queue_append_list(struct k_queue *fifo, void *head, void *tail) {} int k_is_in_isr(void) { return 0; } -void *k_fifo_get(struct k_fifo *fifo, int32_t timeout) +void *k_queue_get(struct k_queue *fifo, int32_t timeout) { return NULL; } -void k_fifo_put(struct k_fifo *fifo, void *data) +void k_queue_append(struct k_queue *fifo, void *data) { } diff --git a/tests/legacy/benchmark/footprint/microkernel/src/microkernel_footprint.c b/tests/legacy/benchmark/footprint/microkernel/src/microkernel_footprint.c index de3b168d01b..6bad9b1b795 100644 --- a/tests/legacy/benchmark/footprint/microkernel/src/microkernel_footprint.c +++ b/tests/legacy/benchmark/footprint/microkernel/src/microkernel_footprint.c @@ -47,12 +47,13 @@ static pfunc func_array[] = { (pfunc)k_sem_reset, (pfunc)k_sem_count_get, - /* FIFOs */ - (pfunc)k_fifo_init, - (pfunc)k_fifo_put, - (pfunc)k_fifo_put_list, - (pfunc)k_fifo_put_slist, - (pfunc)k_fifo_get, + /* queues */ + (pfunc)k_queue_init, + (pfunc)k_queue_append, + (pfunc)k_queue_prepend, + (pfunc)k_queue_append_list, + (pfunc)k_queue_merge_slist, + (pfunc)k_queue_get, /* mem slabs */ (pfunc)k_mem_slab_init, diff --git a/tests/legacy/benchmark/footprint/nanokernel/src/nanokernel_footprint.c b/tests/legacy/benchmark/footprint/nanokernel/src/nanokernel_footprint.c index 6a704f945fc..2a3af50addd 100644 --- a/tests/legacy/benchmark/footprint/nanokernel/src/nanokernel_footprint.c +++ b/tests/legacy/benchmark/footprint/nanokernel/src/nanokernel_footprint.c @@ -67,12 +67,13 @@ static pfunc func_array[] = { (pfunc)k_stack_push, (pfunc)k_stack_pop, - /* FIFOs */ - (pfunc)k_fifo_init, - (pfunc)k_fifo_put, - (pfunc)k_fifo_put_list, - (pfunc)k_fifo_put_slist, - (pfunc)k_fifo_get, + /* queues */ + (pfunc)k_queue_init, + (pfunc)k_queue_append, + (pfunc)k_queue_prepend, + (pfunc)k_queue_append_list, + (pfunc)k_queue_merge_slist, + (pfunc)k_queue_get, #endif }; diff --git a/tests/unit/net/buf/main.c b/tests/unit/net/buf/main.c index 88a30b2cb72..0594b7763bd 100644 --- a/tests/unit/net/buf/main.c +++ b/tests/unit/net/buf/main.c @@ -17,20 +17,20 @@ void irq_unlock(unsigned int key) #include -void k_fifo_init(struct k_fifo *fifo) {} -void k_fifo_put_list(struct k_fifo *fifo, void *head, void *tail) {} +void k_queue_init(struct k_queue *queue) {} +void k_queue_append_list(struct k_queue *queue, void *head, void *tail) {} int k_is_in_isr(void) { return 0; } -void *k_fifo_get(struct k_fifo *fifo, int32_t timeout) +void *k_queue_get(struct k_queue *queue, int32_t timeout) { return NULL; } -void k_fifo_put(struct k_fifo *fifo, void *data) +void k_queue_append(struct k_queue *queue, void *data) { }