FreeRTOS C-Addons  1.1.0
C-Addon functionality to FreeRTOS
dlist.c
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2017, Michael Becker (michael.f.becker@gmail.com)
4  *
5  * This file is part of the FreeRTOS Add-ons project.
6  *
7  * Source Code:
8  * https://github.com/michaelbecker/freertos-addons
9  *
10  * Project Page:
11  * http://michaelbecker.github.io/freertos-addons/
12  *
13  * On-line Documentation:
14  * http://michaelbecker.github.io/freertos-addons/docs/html/index.html
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining a
17  * copy of this software and associated documentation files
18  * (the "Software"), to deal in the Software without restriction, including
19  * without limitation the rights to use, copy, modify, merge, publish,
20  * distribute, sublicense, and/or sell copies of the Software, and to
21  * permit persons to whom the Software is furnished to do so,subject to the
22  * following conditions:
23  *
24  * + The above copyright notice and this permission notice shall be included
25  * in all copies or substantial portions of the Software.
26  * + Credit is appreciated, but not required, if you find this project
27  * useful enough to include in your application, product, device, etc.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
33  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
34  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36  *
37  ***************************************************************************/
38 
39 
40 #include <stdlib.h>
41 #include "dlist.h"
42 
43 
45  DlNode_t *Node)
46 {
47  if (Marker == NULL)
48  return;
49 
50  if (Node == NULL)
51  return;
52 
53  Node->Next = Marker->Next;
54  Node->Prev = Marker;
55 
56  Marker->Next->Prev = Node;
57  Marker->Next = Node;
58 }
59 
60 
62  DlNode_t *Node)
63 {
64  DlInsertNodeAfter(Marker->Prev, Node);
65 }
66 
67 
69  DlNode_t *Node)
70 {
71  DlInsertNodeAfter(Head, Node);
72 }
73 
74 
76  DlNode_t *Node)
77 {
78  DlInsertNodeAfter(Head->Prev, Node);
79 }
80 
81 
83 {
84  if (Node == NULL)
85  return;
86 
87  Node->Next->Prev = Node->Prev;
88  Node->Prev->Next = Node->Next;
89 }
90 
91 
93 {
94  /****************/
95  DlNode_t *Node;
96  /****************/
97 
98  if (Head == NULL)
99  return NULL;
100 
101  if (DlIsListEmpty(Head))
102  return NULL;
103 
104  Node = Head->Next;
105 
106  DlRemoveNode(Node);
107 
108  return Node;
109 }
110 
111 
113 {
114  /****************/
115  DlNode_t *Node;
116  /****************/
117 
118  if (Head == NULL)
119  return NULL;
120 
121  if (DlIsListEmpty(Head))
122  return NULL;
123 
124  Node = Head->Prev;
125 
126  DlRemoveNode(Node);
127 
128  return Node;
129 }
130 
131 
void DlRemoveNode(DlNode_t *Node)
Definition: dlist.c:82
struct DlNode_t_ * Next
Definition: dlist.h:58
void DlAddNodeToHead(DlNode_t *Head, DlNode_t *Node)
Definition: dlist.c:68
DlNode_t * DlRemoveNodeFromTail(DlNode_t *Head)
Definition: dlist.c:112
void DlInsertNodeAfter(DlNode_t *Marker, DlNode_t *Node)
Definition: dlist.c:44
struct DlNode_t_ * Prev
Definition: dlist.h:63
#define DlIsListEmpty(_head)
Definition: dlist.h:128
DlNode_t * DlRemoveNodeFromHead(DlNode_t *Head)
Definition: dlist.c:92
void DlAddNodeToTail(DlNode_t *Head, DlNode_t *Node)
Definition: dlist.c:75
void DlInsertNodeBefore(DlNode_t *Marker, DlNode_t *Node)
Definition: dlist.c:61