mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 18:56:10 +08:00
nuttx/queue: change some queue function to macro
This commit is contained in:
@@ -216,9 +216,9 @@
|
||||
|
||||
/* Queue helpers */
|
||||
|
||||
#define dq_get(q) (dq_remfirst(q))
|
||||
#define dq_put(q,n) (dq_addlast((dq_entry_t*)n,(q)))
|
||||
#define dq_put_back(q,n) (dq_addfirst((dq_entry_t*)n,(q)))
|
||||
#define dq_get(q) dq_remfirst(q)
|
||||
#define dq_put(q,n) dq_addlast((dq_entry_t*)(n),(q))
|
||||
#define dq_put_back(q,n) dq_addfirst((dq_entry_t*)(n),(q))
|
||||
#define dq_clear(q) \
|
||||
do \
|
||||
{ \
|
||||
|
||||
+180
-13
@@ -67,6 +67,186 @@
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define sq_addfirst(p, q) \
|
||||
do \
|
||||
{ \
|
||||
FAR sq_entry_t *tmp_node = (p); \
|
||||
tmp_node->flink = (q)->head; \
|
||||
if (!(q)->head) \
|
||||
{ \
|
||||
(q)->tail = tmp_node; \
|
||||
} \
|
||||
(q)->head = tmp_node; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define dq_addfirst(p, q) \
|
||||
do \
|
||||
{ \
|
||||
FAR dq_entry_t *tmp_node = (p); \
|
||||
tmp_node->blink = NULL; \
|
||||
tmp_node->flink = (q)->head; \
|
||||
if (!(q)->head) \
|
||||
{ \
|
||||
(q)->head = tmp_node; \
|
||||
(q)->tail = tmp_node; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
(q)->head->blink = tmp_node; \
|
||||
(q)->head = tmp_node; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define sq_addlast(p, q) \
|
||||
do \
|
||||
{ \
|
||||
FAR sq_entry_t *tmp_node = (p); \
|
||||
tmp_node->flink = NULL; \
|
||||
if (!(q)->head) \
|
||||
{ \
|
||||
(q)->head = tmp_node; \
|
||||
(q)->tail = tmp_node; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
(q)->tail->flink = tmp_node; \
|
||||
(q)->tail = tmp_node; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define dq_addlast(p, q) \
|
||||
do \
|
||||
{ \
|
||||
FAR dq_entry_t *tmp_node = (p); \
|
||||
tmp_node->flink = NULL; \
|
||||
tmp_node->blink = (q)->tail; \
|
||||
if (!(q)->head) \
|
||||
{ \
|
||||
(q)->head = tmp_node; \
|
||||
(q)->tail = tmp_node; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
(q)->tail->flink = tmp_node; \
|
||||
(q)->tail = tmp_node; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define dq_addbefore(n, p, q) \
|
||||
do \
|
||||
{ \
|
||||
FAR dq_entry_t *_tmp_node = (p); \
|
||||
if (!(q)->head || (n) == (q)->head) \
|
||||
{ \
|
||||
dq_addfirst(_tmp_node, q); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
FAR dq_entry_t *tmp_prev = (n)->blink; \
|
||||
_tmp_node->flink = (n); \
|
||||
_tmp_node->blink = tmp_prev; \
|
||||
tmp_prev->flink = _tmp_node; \
|
||||
(n)->blink = _tmp_node; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define sq_for_every(q, p) \
|
||||
for((p) = (q)->head; (p) != NULL; (p) = (p)->flink)
|
||||
|
||||
#define sq_rem(p, q) \
|
||||
do \
|
||||
{ \
|
||||
FAR sq_entry_t *tmp_node = (p); \
|
||||
if ((q)->head && tmp_node) \
|
||||
{ \
|
||||
if (tmp_node == (q)->head) \
|
||||
{ \
|
||||
(q)->head = tmp_node->flink; \
|
||||
if (tmp_node == (q)->tail) \
|
||||
{ \
|
||||
(q)->tail = NULL; \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
FAR sq_entry_t *tmp_prev; \
|
||||
sq_for_every(q, tmp_prev) \
|
||||
{ \
|
||||
if (tmp_prev->flink == tmp_node) \
|
||||
{ \
|
||||
sq_remafter(tmp_prev, q); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define dq_rem(p, q) \
|
||||
do \
|
||||
{ \
|
||||
FAR dq_entry_t *tmp_node = (p); \
|
||||
FAR dq_entry_t *tmp_prev = tmp_node->blink; \
|
||||
FAR dq_entry_t *tmp_next = tmp_node->flink; \
|
||||
if (!tmp_prev) \
|
||||
{ \
|
||||
(q)->head = tmp_next; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
tmp_prev->flink = tmp_next; \
|
||||
} \
|
||||
if (!tmp_next) \
|
||||
{ \
|
||||
(q)->tail = tmp_prev; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
tmp_next->blink = tmp_prev; \
|
||||
} \
|
||||
tmp_node->flink = NULL; \
|
||||
tmp_node->blink = NULL; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define sq_cat(q1, q2) \
|
||||
do \
|
||||
{ \
|
||||
if (sq_empty(q2)) \
|
||||
{ \
|
||||
sq_move(q1, q2); \
|
||||
} \
|
||||
else if (!sq_empty(q1)) \
|
||||
{ \
|
||||
(q2)->tail->flink = (q1)->head; \
|
||||
(q2)->tail = (q1)->tail; \
|
||||
sq_init(q1); \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define dq_cat(q1, q2) \
|
||||
do \
|
||||
{ \
|
||||
if (dq_empty(q2)) \
|
||||
{ \
|
||||
dq_move(q1, q2); \
|
||||
} \
|
||||
else if (!dq_empty(q1)) \
|
||||
{ \
|
||||
(q2)->tail->flink = (q1)->head; \
|
||||
(q1)->head->blink = (q2)->tail; \
|
||||
(q2)->tail = (q1)->tail; \
|
||||
dq_init(q1); \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define sq_next(p) ((p)->flink)
|
||||
#define dq_next(p) ((p)->flink)
|
||||
#define dq_prev(p) ((p)->blink)
|
||||
@@ -125,27 +305,14 @@ extern "C"
|
||||
|
||||
/* Add nodes to queues */
|
||||
|
||||
void sq_addfirst(FAR sq_entry_t *node, FAR sq_queue_t *queue);
|
||||
void dq_addfirst(FAR dq_entry_t *node, FAR dq_queue_t *queue);
|
||||
void sq_addlast(FAR sq_entry_t *node, FAR sq_queue_t *queue);
|
||||
void dq_addlast(FAR dq_entry_t *node, FAR dq_queue_t *queue);
|
||||
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);
|
||||
void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node,
|
||||
FAR dq_queue_t *queue);
|
||||
|
||||
/* Combine queues */
|
||||
|
||||
void sq_cat(FAR sq_queue_t *queue1, FAR sq_queue_t *queue2);
|
||||
void dq_cat(FAR dq_queue_t *queue1, FAR dq_queue_t *queue2);
|
||||
|
||||
/* Remove nodes from queues */
|
||||
|
||||
FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, FAR sq_queue_t *queue);
|
||||
void sq_rem(FAR sq_entry_t *node, FAR sq_queue_t *queue);
|
||||
void dq_rem(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);
|
||||
|
||||
@@ -39,10 +39,6 @@
|
||||
"dlsym","dlfcn.h","defined(CONFIG_LIBC_DLFCN)","FAR void *","FAR void *","FAR const char *"
|
||||
"dlsymtab","dlfcn.h","defined(CONFIG_LIBC_DLFCN)","int","FAR const struct symtab_s *","int"
|
||||
"dq_addafter","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *"
|
||||
"dq_addbefore","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *"
|
||||
"dq_addfirst","queue.h","","void","FAR dq_entry_t *","FAR dq_queue_t *"
|
||||
"dq_addlast","queue.h","","void","FAR dq_entry_t *","FAR dq_queue_t *"
|
||||
"dq_rem","queue.h","","void","FAR dq_entry_t *","FAR dq_queue_t *"
|
||||
"dq_remfirst","queue.h","","FAR dq_entry_t *","FAR dq_queue_t *"
|
||||
"dq_remlast","queue.h","","FAR dq_entry_t *","FAR dq_queue_t *"
|
||||
"ether_ntoa","netinet/ether.h","","FAR char *","FAR const struct ether_addr *"
|
||||
@@ -217,9 +213,6 @@
|
||||
"snprintf","stdio.h","","int","FAR char *","size_t","FAR const IPTR char *","..."
|
||||
"sprintf","stdio.h","","int","FAR char *","FAR const IPTR char *","..."
|
||||
"sq_addafter","queue.h","","void","FAR sq_entry_t *","FAR sq_entry_t *","FAR sq_queue_t *"
|
||||
"sq_addfirst","queue.h","","void","FAR sq_entry_t *","FAR sq_queue_t *"
|
||||
"sq_addlast","queue.h","","void","FAR sq_entry_t *","FAR sq_queue_t *"
|
||||
"sq_rem","queue.h","","void","FAR sq_entry_t *","FAR sq_queue_t *"
|
||||
"sq_remafter","queue.h","","FAR sq_entry_t","FAR sq_entry_t *","FAR sq_queue_t *"
|
||||
"sq_remfirst","queue.h","","FAR sq_entry_t *","FAR sq_queue_t *"
|
||||
"sq_remlast","queue.h","","FAR sq_entry_t *","FAR sq_queue_t *"
|
||||
|
||||
|
@@ -20,10 +20,8 @@
|
||||
|
||||
# Add the queue C files to the build
|
||||
|
||||
CSRCS += sq_addlast.c sq_addfirst.c sq_addafter.c sq_cat.c
|
||||
CSRCS += sq_rem.c sq_remlast.c sq_remfirst.c sq_remafter.c sq_count.c
|
||||
CSRCS += dq_addlast.c dq_addfirst.c dq_addafter.c dq_addbefore.c dq_cat.c
|
||||
CSRCS += dq_rem.c dq_remlast.c dq_remfirst.c dq_count.c
|
||||
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_count.c
|
||||
|
||||
# Add the queue directory to the build
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/queue/dq_addbefore.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 <queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dq_addbefore
|
||||
*
|
||||
* Description:
|
||||
* dq_addbefore adds 'node' before 'next' in 'queue'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node,
|
||||
dq_queue_t *queue)
|
||||
{
|
||||
if (!queue->head || next == queue->head)
|
||||
{
|
||||
dq_addfirst(node, queue);
|
||||
}
|
||||
else
|
||||
{
|
||||
FAR dq_entry_t *prev = next->blink;
|
||||
node->flink = next;
|
||||
node->blink = prev;
|
||||
prev->flink = node;
|
||||
next->blink = node;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/queue/dq_addfirst.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 <queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dq_addfirst
|
||||
*
|
||||
* Description:
|
||||
* dq_addfirst affs 'node' at the beginning of 'queue'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void dq_addfirst(FAR dq_entry_t *node, dq_queue_t *queue)
|
||||
{
|
||||
node->blink = NULL;
|
||||
node->flink = queue->head;
|
||||
|
||||
if (!queue->head)
|
||||
{
|
||||
queue->head = node;
|
||||
queue->tail = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->head->blink = node;
|
||||
queue->head = node;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/queue/dq_addlast.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 <queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dq_addlast
|
||||
*
|
||||
* Description:
|
||||
* dq_addlast adds 'node' to the end of 'queue'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void dq_addlast(FAR dq_entry_t *node, dq_queue_t *queue)
|
||||
{
|
||||
node->flink = NULL;
|
||||
node->blink = queue->tail;
|
||||
|
||||
if (!queue->head)
|
||||
{
|
||||
queue->head = node;
|
||||
queue->tail = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->tail->flink = node;
|
||||
queue->tail = node;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/queue/dq_cat.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 <assert.h>
|
||||
#include <queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dq_cat
|
||||
*
|
||||
* Description:
|
||||
* Move the content of queue1 to the end of queue2.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void dq_cat(FAR dq_queue_t *queue1, FAR dq_queue_t *queue2)
|
||||
{
|
||||
DEBUGASSERT(queue1 != NULL && queue2 != NULL);
|
||||
|
||||
/* If queue2 is empty, then just move queue1 to queue2 */
|
||||
|
||||
if (dq_empty(queue2))
|
||||
{
|
||||
dq_move(queue1, queue2);
|
||||
}
|
||||
|
||||
/* Do nothing if queue1 is empty */
|
||||
|
||||
else if (!dq_empty(queue1))
|
||||
{
|
||||
/* Attach the head of queue1 to the final entry of queue2 */
|
||||
|
||||
queue2->tail->flink = queue1->head;
|
||||
queue1->head->blink = queue2->tail;
|
||||
|
||||
/* The tail of queue1 is the new tail of queue2 */
|
||||
|
||||
queue2->tail = queue1->tail;
|
||||
dq_init(queue1);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/queue/dq_rem.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 <queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dq_rem
|
||||
*
|
||||
* Description:
|
||||
* dq_rem removes 'node' from 'queue'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void dq_rem(FAR dq_entry_t *node, dq_queue_t *queue)
|
||||
{
|
||||
FAR dq_entry_t *prev = node->blink;
|
||||
FAR dq_entry_t *next = node->flink;
|
||||
|
||||
if (!prev)
|
||||
{
|
||||
queue->head = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev->flink = next;
|
||||
}
|
||||
|
||||
if (!next)
|
||||
{
|
||||
queue->tail = prev;
|
||||
}
|
||||
else
|
||||
{
|
||||
next->blink = prev;
|
||||
}
|
||||
|
||||
node->flink = NULL;
|
||||
node->blink = NULL;
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/queue/sq_addfirst.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 <queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sq_addfirst
|
||||
*
|
||||
* Description:
|
||||
* The sq_addfirst function places the 'node' at the head of the 'queue'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void sq_addfirst(FAR sq_entry_t *node, sq_queue_t *queue)
|
||||
{
|
||||
node->flink = queue->head;
|
||||
if (!queue->head)
|
||||
{
|
||||
queue->tail = node;
|
||||
}
|
||||
|
||||
queue->head = node;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/queue/sq_addlast.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 <queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sq_addlast
|
||||
*
|
||||
* Description:
|
||||
* The sq_addlast function places the 'node' at the tail of
|
||||
* the 'queue'
|
||||
****************************************************************************/
|
||||
|
||||
void sq_addlast(FAR sq_entry_t *node, sq_queue_t *queue)
|
||||
{
|
||||
node->flink = NULL;
|
||||
if (!queue->head)
|
||||
{
|
||||
queue->head = node;
|
||||
queue->tail = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->tail->flink = node;
|
||||
queue->tail = node;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/queue/sq_cat.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 <assert.h>
|
||||
#include <queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sq_cat
|
||||
*
|
||||
* Description:
|
||||
* Move the content of queue1 to the end of queue2.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void sq_cat(FAR sq_queue_t *queue1, FAR sq_queue_t *queue2)
|
||||
{
|
||||
DEBUGASSERT(queue1 != NULL && queue2 != NULL);
|
||||
|
||||
/* If queue2 is empty, then just move queue1 to queue2 */
|
||||
|
||||
if (sq_empty(queue2))
|
||||
{
|
||||
sq_move(queue1, queue2);
|
||||
}
|
||||
|
||||
/* Do nothing if queue1 is empty */
|
||||
|
||||
else if (!sq_empty(queue1))
|
||||
{
|
||||
/* Attach the head of queue1 to the final entry of queue2 */
|
||||
|
||||
queue2->tail->flink = queue1->head;
|
||||
|
||||
/* The tail of queue1 is the new tail of queue2 */
|
||||
|
||||
queue2->tail = queue1->tail;
|
||||
sq_init(queue1);
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/queue/sq_rem.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 <queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sq_rem
|
||||
*
|
||||
* Description:
|
||||
* sq_rem removes a 'node' for 'queue.'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void sq_rem(FAR sq_entry_t *node, sq_queue_t *queue)
|
||||
{
|
||||
if (queue->head && node)
|
||||
{
|
||||
if (node == queue->head)
|
||||
{
|
||||
queue->head = node->flink;
|
||||
if (node == queue->tail)
|
||||
{
|
||||
queue->tail = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FAR sq_entry_t *prev;
|
||||
|
||||
for (prev = (FAR sq_entry_t *)queue->head;
|
||||
prev && prev->flink != node;
|
||||
prev = prev->flink);
|
||||
|
||||
if (prev)
|
||||
{
|
||||
sq_remafter(prev, queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user