mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 10:58:49 +08:00
libs/libc/queue: inline queue list to improve performance
add a config CONFIG_LIBC_INLINE_QUEUE to inline the queue list 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 <hujun5@xiaomi.com>
This commit is contained in:
parent
1e57a5653c
commit
41e976d119
15 changed files with 254 additions and 554 deletions
|
@ -31,6 +31,14 @@
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_LIBC_INLINE_QUEUE
|
||||
# ifndef STATIC_INLINE
|
||||
# define STATIC_INLINE static inline_function
|
||||
# endif
|
||||
#else
|
||||
# define STATIC_INLINE
|
||||
#endif
|
||||
|
||||
#define sq_init(q) \
|
||||
do \
|
||||
{ \
|
||||
|
@ -343,24 +351,241 @@ extern "C"
|
|||
|
||||
/* Add nodes to queues */
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
|
||||
FAR sq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
|
||||
FAR dq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Remove nodes from queues */
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, FAR sq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
FAR dq_entry_t *dq_remafter(FAR dq_entry_t *node, FAR dq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
FAR sq_entry_t *sq_remlast(FAR sq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
FAR dq_entry_t *dq_remlast(FAR dq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
FAR sq_entry_t *sq_remfirst(FAR sq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
FAR dq_entry_t *dq_remfirst(FAR dq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Count nodes in queues */
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
size_t sq_count(FAR sq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
size_t dq_count(FAR dq_queue_t *queue);
|
||||
#else
|
||||
STATIC_INLINE 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -33,3 +33,4 @@ source "libs/libc/stream/Kconfig"
|
|||
source "libs/libc/regex/Kconfig"
|
||||
source "libs/libc/gpsutils/Kconfig"
|
||||
source "libs/libc/fdt/Kconfig"
|
||||
source "libs/libc/queue/Kconfig"
|
||||
|
|
|
@ -18,15 +18,4 @@
|
|||
#
|
||||
# ##############################################################################
|
||||
|
||||
target_sources(
|
||||
c
|
||||
PRIVATE sq_addafter.c
|
||||
sq_remlast.c
|
||||
sq_remfirst.c
|
||||
sq_remafter.c
|
||||
sq_count.c
|
||||
dq_addafter.c
|
||||
dq_remlast.c
|
||||
dq_remfirst.c
|
||||
dq_remafter.c
|
||||
dq_count.c)
|
||||
target_sources(c PRIVATE queue.c)
|
||||
|
|
10
libs/libc/queue/Kconfig
Normal file
10
libs/libc/queue/Kconfig
Normal file
|
@ -0,0 +1,10 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config LIBC_INLINE_QUEUE
|
||||
bool "Inline queue list to improve the performance"
|
||||
default !DEFAULT_SMALL
|
||||
---help---
|
||||
Inline queue list to improve the performance
|
|
@ -20,8 +20,7 @@
|
|||
|
||||
# Add the queue C files to the build
|
||||
|
||||
CSRCS += sq_addafter.c sq_remlast.c sq_remfirst.c sq_remafter.c sq_count.c
|
||||
CSRCS += dq_addafter.c dq_remlast.c dq_remfirst.c dq_remafter.c dq_count.c
|
||||
CSRCS += queue.c
|
||||
|
||||
# Add the queue directory to the build
|
||||
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/dq_addafter.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dq_addafter
|
||||
*
|
||||
* Description:
|
||||
* dq_addafter function adds 'node' after 'prev' in the 'queue.'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/dq_count.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
#include <assert.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dq_count
|
||||
*
|
||||
* Description:
|
||||
* Return the number of nodes in the queue.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
size_t dq_count(FAR dq_queue_t *queue)
|
||||
{
|
||||
FAR dq_entry_t *node;
|
||||
size_t count;
|
||||
|
||||
DEBUGASSERT(queue != NULL);
|
||||
|
||||
for (node = queue->head, count = 0;
|
||||
node != NULL;
|
||||
node = node->flink, count++);
|
||||
|
||||
return count;
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/dq_remafter.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dq_remafter
|
||||
*
|
||||
* Description:
|
||||
* dq_remafter removes the entry following 'node' from the 'queue'.
|
||||
* Returns a reference to the removed entry.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/dq_remfirst.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dq_remfirst
|
||||
*
|
||||
* Description:
|
||||
* dq_remfirst removes 'node' from the head of 'queue'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR dq_entry_t *dq_remfirst(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;
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/dq_remlast.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/***************************************************(************************
|
||||
* Name: dq_remlast
|
||||
*
|
||||
* Description:
|
||||
* dq_remlast removes the last entry from 'queue'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR dq_entry_t *dq_remlast(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;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/sq_count.c
|
||||
* libs/libc/queue/queue.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
@ -24,31 +24,23 @@
|
|||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
#include <assert.h>
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_LIBC_INLINE_QUEUE
|
||||
|
||||
# define CONFIG_LIBC_INLINE_QUEUE
|
||||
# define STATIC_INLINE
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
# include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sq_count
|
||||
*
|
||||
* Description:
|
||||
* Return the number of nodes in the queue.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
size_t sq_count(FAR sq_queue_t *queue)
|
||||
{
|
||||
FAR sq_entry_t *node;
|
||||
size_t count;
|
||||
|
||||
DEBUGASSERT(queue != NULL);
|
||||
|
||||
for (node = queue->head, count = 0;
|
||||
node != NULL;
|
||||
node = node->flink, count++);
|
||||
|
||||
return count;
|
||||
}
|
||||
#endif
|
|
@ -1,51 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/sq_addafter.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sq_addafter.c
|
||||
*
|
||||
* Description:
|
||||
* The sq_addafter function adds 'node' after 'prev' in the 'queue.'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
|
||||
sq_queue_t *queue)
|
||||
{
|
||||
if (!queue->head || prev == queue->tail)
|
||||
{
|
||||
sq_addlast(node, queue);
|
||||
}
|
||||
else
|
||||
{
|
||||
node->flink = prev->flink;
|
||||
prev->flink = node;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/sq_remafter.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sq_remafter
|
||||
*
|
||||
* Description:
|
||||
* sq_remafter removes the entry following 'node' from the 'queue'.
|
||||
* Returns a reference to the removed entry.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, 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;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/sq_remfirst.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sq_remfirst
|
||||
*
|
||||
* Description:
|
||||
* sq_remfirst function removes the first entry from 'queue'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR sq_entry_t *sq_remfirst(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;
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/****************************************************************************
|
||||
* libs/libc/queue/sq_remlast.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sq_remlast
|
||||
*
|
||||
* Description:
|
||||
* Removes the last entry in a singly-linked queue.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR sq_entry_t *sq_remlast(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;
|
||||
}
|
Loading…
Reference in a new issue