Skip to content

Commit

Permalink
queue: inline queue
Browse files Browse the repository at this point in the history
test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20
running
qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Jul 1, 2024
1 parent 09146be commit 5da5aef
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 644 deletions.
201 changes: 189 additions & 12 deletions include/nuttx/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,24 +343,201 @@ extern "C"

/* Add nodes to queues */

void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
FAR sq_queue_t *queue);
void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
FAR dq_queue_t *queue);
static inline_function void sq_addafter(FAR sq_entry_t *prev,
FAR sq_entry_t *node,
FAR sq_queue_t *queue)
{
if (!queue->head || prev == queue->tail)
{
sq_addlast(node, queue);
}
else
{
node->flink = prev->flink;
prev->flink = node;
}
}

static inline_function void dq_addafter(FAR dq_entry_t *prev,
FAR dq_entry_t *node,
FAR dq_queue_t *queue)
{
if (!queue->head || prev == queue->tail)
{
dq_addlast(node, queue);
}
else
{
FAR dq_entry_t *next = prev->flink;
node->blink = prev;
node->flink = next;
next->blink = node;
prev->flink = node;
}
}

/* Remove nodes from queues */

FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, FAR sq_queue_t *queue);
FAR dq_entry_t *dq_remafter(FAR dq_entry_t *node, FAR dq_queue_t *queue);
FAR sq_entry_t *sq_remlast(FAR sq_queue_t *queue);
FAR dq_entry_t *dq_remlast(FAR dq_queue_t *queue);
FAR sq_entry_t *sq_remfirst(FAR sq_queue_t *queue);
FAR dq_entry_t *dq_remfirst(FAR dq_queue_t *queue);
static inline_function FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node,
FAR sq_queue_t *queue)
{
FAR sq_entry_t *ret = node->flink;

if (queue->head && ret)
{
if (queue->tail == ret)
{
queue->tail = node;
node->flink = NULL;
}
else
{
node->flink = ret->flink;
}

ret->flink = NULL;
}

return ret;
}

static inline_function FAR dq_entry_t *dq_remafter(FAR dq_entry_t *node,
FAR dq_queue_t *queue)
{
FAR dq_entry_t *ret = node->flink;

if (queue->head != NULL && ret != NULL)
{
dq_rem(ret, queue);
}

return ret;
}

static inline_function FAR sq_entry_t *sq_remlast(FAR sq_queue_t *queue)
{
FAR sq_entry_t *ret = queue->tail;

if (ret)
{
if (queue->head == queue->tail)
{
queue->head = NULL;
queue->tail = NULL;
}
else
{
FAR sq_entry_t *prev;
for (prev = queue->head;
prev && prev->flink != ret;
prev = prev->flink);

if (prev)
{
prev->flink = NULL;
queue->tail = prev;
}
}

ret->flink = NULL;
}

return ret;
}

static inline_function FAR dq_entry_t *dq_remlast(FAR dq_queue_t *queue)
{
FAR dq_entry_t *ret = queue->tail;

if (ret)
{
FAR dq_entry_t *prev = ret->blink;
if (!prev)
{
queue->head = NULL;
queue->tail = NULL;
}
else
{
queue->tail = prev;
prev->flink = NULL;
}

ret->flink = NULL;
ret->blink = NULL;
}

return ret;
}

static inline_function FAR sq_entry_t *sq_remfirst(FAR sq_queue_t *queue)
{
FAR sq_entry_t *ret = queue->head;

if (ret)
{
queue->head = ret->flink;
if (!queue->head)
{
queue->tail = NULL;
}

ret->flink = NULL;
}

return ret;
}

static inline_function FAR dq_entry_t *dq_remfirst(FAR dq_queue_t *queue)
{
FAR dq_entry_t *ret = queue->head;

if (ret)
{
FAR dq_entry_t *next = ret->flink;
if (!next)
{
queue->head = NULL;
queue->tail = NULL;
}
else
{
queue->head = next;
next->blink = NULL;
}

ret->flink = NULL;
ret->blink = NULL;
}

return ret;
}

/* Count nodes in queues */

size_t sq_count(FAR sq_queue_t *queue);
size_t dq_count(FAR dq_queue_t *queue);
static inline_function size_t sq_count(FAR sq_queue_t *queue)
{
FAR sq_entry_t *node;
size_t count;

for (node = queue->head, count = 0;
node != NULL;
node = node->flink, count++);

return count;
}

static inline_function size_t dq_count(FAR dq_queue_t *queue)
{
FAR dq_entry_t *node;
size_t count;

for (node = queue->head, count = 0;
node != NULL;
node = node->flink, count++);

return count;
}

#undef EXTERN
#ifdef __cplusplus
Expand Down
1 change: 0 additions & 1 deletion libs/libc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ include netdb/Make.defs
include obstack/Make.defs
include pthread/Make.defs
include pwd/Make.defs
include queue/Make.defs
include regex/Make.defs
include sched/Make.defs
include search/Make.defs
Expand Down
32 changes: 0 additions & 32 deletions libs/libc/queue/CMakeLists.txt

This file was deleted.

29 changes: 0 additions & 29 deletions libs/libc/queue/Make.defs

This file was deleted.

54 changes: 0 additions & 54 deletions libs/libc/queue/dq_addafter.c

This file was deleted.

54 changes: 0 additions & 54 deletions libs/libc/queue/dq_count.c

This file was deleted.

Loading

0 comments on commit 5da5aef

Please sign in to comment.