mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 02:36:11 +08:00
Add library functions to concatenate and move lists. Add scheduler function to merge prioritized function to merge prioritized lists (not yet used).
This commit is contained in:
+47
-11
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* include/queue.h
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,12 +46,45 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define sq_init(q) do { (q)->head = NULL; (q)->tail = NULL; } while (0)
|
||||
#define dq_init(q) do { (q)->head = NULL; (q)->tail = NULL; } while (0)
|
||||
#define sq_init(q) \
|
||||
do \
|
||||
{ \
|
||||
(q)->head = NULL; \
|
||||
(q)->tail = NULL; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define sq_next(p) ((p)->flink)
|
||||
#define dq_next(p) ((p)->flink)
|
||||
#define dq_prev(p) ((p)->blink)
|
||||
#define dq_init(q) \
|
||||
do \
|
||||
{ \
|
||||
(q)->head = NULL; \
|
||||
(q)->tail = NULL; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define sq_move(q1,q2) \
|
||||
do \
|
||||
{ \
|
||||
(q2)->head = (q1)->head; \
|
||||
(q2)->tail = (q1)->tail; \
|
||||
(q1)->head = NULL; \
|
||||
(q1)->tail = NULL; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define dq_move(q1,q2) \
|
||||
do \
|
||||
{ \
|
||||
(q2)->head = (q1)->head; \
|
||||
(q2)->tail = (q1)->tail; \
|
||||
(q1)->head = NULL; \
|
||||
(q1)->tail = NULL; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define sq_next(p) ((p)->flink)
|
||||
#define dq_next(p) ((p)->flink)
|
||||
#define dq_prev(p) ((p)->blink)
|
||||
|
||||
#define sq_empty(q) ((q)->head == NULL)
|
||||
#define dq_empty(q) ((q)->head == NULL)
|
||||
@@ -113,13 +146,16 @@ void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
|
||||
void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node,
|
||||
FAR dq_queue_t *queue);
|
||||
|
||||
FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, FAR sq_queue_t *queue);
|
||||
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);
|
||||
|
||||
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);
|
||||
FAR dq_entry_t *dq_remfirst(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);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -35,11 +35,10 @@
|
||||
|
||||
# Add the queue C files to the build
|
||||
|
||||
CSRCS += sq_addlast.c sq_addfirst.c sq_addafter.c \
|
||||
sq_rem.c sq_remlast.c sq_remfirst.c sq_remafter.c
|
||||
|
||||
CSRCS += dq_addlast.c dq_addfirst.c dq_addafter.c dq_addbefore.c \
|
||||
dq_rem.c dq_remlast.c dq_remfirst.c
|
||||
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
|
||||
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
|
||||
|
||||
# Add the queue directory to the build
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* libc/queue/dq_cat.c
|
||||
*
|
||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
* libc/queue/sq_cat.c
|
||||
*
|
||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,9 @@
|
||||
############################################################################
|
||||
|
||||
CSRCS += sched_garbage.c sched_getfiles.c
|
||||
CSRCS += sched_addreadytorun.c sched_removereadytorun.c sched_addprioritized.c
|
||||
CSRCS += sched_mergepending.c sched_addblocked.c sched_removeblocked.c
|
||||
CSRCS += sched_addreadytorun.c sched_removereadytorun.c
|
||||
CSRCS += sched_addprioritized.c sched_mergeprioritized.c sched_mergepending.c
|
||||
CSRCS += sched_addblocked.c sched_removeblocked.c
|
||||
CSRCS += sched_free.c sched_gettcb.c sched_verifytcb.c sched_releasetcb.c
|
||||
CSRCS += sched_getsockets.c sched_getstreams.c
|
||||
CSRCS += sched_setparam.c sched_setpriority.c sched_getparam.c
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
* the head of the task list is changed.
|
||||
* - The caller must set the task_state field of the TCB to
|
||||
* match the state associated with the list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool sched_addprioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list)
|
||||
|
||||
Reference in New Issue
Block a user