lifo: Make use of k_queue as implementation

Once all users of k_lifo migrate to k_queue this should no longer be
needed.

Change-Id: Ib8af40c57bf8feba7b06d6d891cfa57b44faad42
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2017-02-21 15:49:52 +02:00 committed by Anas Nashif
commit 0dc4dd46d4
8 changed files with 11 additions and 150 deletions

View file

@ -1424,17 +1424,12 @@ struct k_fifo {
*/
struct k_lifo {
_wait_q_t wait_q;
void *list;
_OBJECT_TRACING_NEXT_PTR(k_lifo);
struct k_queue _queue;
};
#define K_LIFO_INITIALIZER(obj) \
{ \
.wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \
.list = NULL, \
_OBJECT_TRACING_INIT \
._queue = K_QUEUE_INITIALIZER(obj._queue) \
}
/**
@ -1456,7 +1451,8 @@ struct k_lifo {
*
* @return N/A
*/
extern void k_lifo_init(struct k_lifo *lifo);
#define k_lifo_init(lifo) \
k_queue_init((struct k_queue *) lifo)
/**
* @brief Add an element to a lifo.
@ -1472,7 +1468,8 @@ extern void k_lifo_init(struct k_lifo *lifo);
*
* @return N/A
*/
extern void k_lifo_put(struct k_lifo *lifo, void *data);
#define k_lifo_put(lifo, data) \
k_queue_prepend((struct k_queue *) lifo, data)
/**
* @brief Get an element from a lifo.
@ -1489,7 +1486,8 @@ extern void k_lifo_put(struct k_lifo *lifo, void *data);
* @return Address of the data item if successful; NULL if returned
* without waiting, or waiting period timed out.
*/
extern void *k_lifo_get(struct k_lifo *lifo, int32_t timeout);
#define k_lifo_get(lifo, timeout) \
k_queue_get((struct k_queue *) lifo, timeout)
/**
* @brief Statically define and initialize a lifo.
@ -1502,7 +1500,7 @@ extern void *k_lifo_get(struct k_lifo *lifo, int32_t timeout);
*/
#define K_LIFO_DEFINE(name) \
struct k_lifo name \
__in_section(_k_lifo, static, name) = \
__in_section(_k_queue, static, name) = \
K_LIFO_INITIALIZER(name)
/**

View file

@ -72,13 +72,6 @@
_k_queue_list_end = .;
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
SECTION_DATA_PROLOGUE(_k_lifo_area, (OPTIONAL),)
{
_k_lifo_list_start = .;
KEEP(*(SORT_BY_NAME("._k_lifo.static.*")))
_k_lifo_list_end = .;
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
SECTION_DATA_PROLOGUE(_k_stack_area, (OPTIONAL),)
{
_k_stack_list_start = .;

View file

@ -19,7 +19,6 @@ lib-y += $(strip \
sched.o \
mutex.o \
queue.o \
lifo.o \
stack.o \
mem_slab.o \
mem_pool.o \

View file

@ -1,105 +0,0 @@
/*
* Copyright (c) 2010-2015 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
*
* @brief dynamic-size LIFO queue object
*/
#include <kernel.h>
#include <kernel_structs.h>
#include <debug/object_tracing_common.h>
#include <toolchain.h>
#include <sections.h>
#include <wait_q.h>
#include <ksched.h>
#include <init.h>
extern struct k_lifo _k_lifo_list_start[];
extern struct k_lifo _k_lifo_list_end[];
struct k_lifo *_trace_list_k_lifo;
#ifdef CONFIG_OBJECT_TRACING
/*
* Complete initialization of statically defined lifos.
*/
static int init_lifo_module(struct device *dev)
{
ARG_UNUSED(dev);
struct k_lifo *lifo;
for (lifo = _k_lifo_list_start; lifo < _k_lifo_list_end; lifo++) {
SYS_TRACING_OBJ_INIT(k_lifo, lifo);
}
return 0;
}
SYS_INIT(init_lifo_module, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS);
#endif /* CONFIG_OBJECT_TRACING */
void k_lifo_init(struct k_lifo *lifo)
{
lifo->list = (void *)0;
sys_dlist_init(&lifo->wait_q);
SYS_TRACING_OBJ_INIT(k_lifo, lifo);
}
void k_lifo_put(struct k_lifo *lifo, void *data)
{
struct k_thread *first_pending_thread;
unsigned int key;
key = irq_lock();
first_pending_thread = _unpend_first_thread(&lifo->wait_q);
if (first_pending_thread) {
_abort_thread_timeout(first_pending_thread);
_ready_thread(first_pending_thread);
_set_thread_return_value_with_data(first_pending_thread,
0, data);
if (!_is_in_isr() && _must_switch_threads()) {
(void)_Swap(key);
return;
}
} else {
*(void **)data = lifo->list;
lifo->list = data;
}
irq_unlock(key);
}
void *k_lifo_get(struct k_lifo *lifo, int32_t timeout)
{
unsigned int key;
void *data;
key = irq_lock();
if (likely(lifo->list)) {
data = lifo->list;
lifo->list = *(void **)data;
irq_unlock(key);
return data;
}
if (timeout == K_NO_WAIT) {
irq_unlock(key);
return NULL;
}
_pend_current_thread(&lifo->wait_q, timeout);
return _Swap(key) ? NULL : _current->base.swap_data;
}

View file

@ -34,14 +34,7 @@ void k_queue_append(struct k_queue *fifo, void *data)
{
}
void k_lifo_init(struct k_lifo *lifo) {}
void *k_lifo_get(struct k_lifo *lifo, int32_t timeout)
{
return NULL;
}
void k_lifo_put(struct k_lifo *lifo, void *data)
void k_queue_prepend(struct k_queue *fifo, void *data)
{
}

View file

@ -81,11 +81,6 @@ static pfunc func_array[] = {
(pfunc)k_sem_group_give,
(pfunc)k_sem_group_reset,
/* LIFOs */
(pfunc)k_lifo_init,
(pfunc)k_lifo_put,
(pfunc)k_lifo_get,
/* stacks */
(pfunc)k_stack_init,
(pfunc)k_stack_push,

View file

@ -57,11 +57,6 @@ static pfunc func_array[] = {
(pfunc)k_sem_count_get,
#ifdef TEST_max
/* LIFOs */
(pfunc)k_lifo_init,
(pfunc)k_lifo_put,
(pfunc)k_lifo_get,
/* stacks */
(pfunc)k_stack_init,
(pfunc)k_stack_push,

View file

@ -34,14 +34,7 @@ void k_queue_append(struct k_queue *queue, void *data)
{
}
void k_lifo_init(struct k_lifo *lifo) {}
void *k_lifo_get(struct k_lifo *lifo, int32_t timeout)
{
return NULL;
}
void k_lifo_put(struct k_lifo *lifo, void *data)
void k_queue_prepend(struct k_queue *fifo, void *data)
{
}