agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
clist.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 ykat UG (haftungsbeschraenkt) - All Rights Reserved
3  *
4  * Permission for non-commercial use is hereby granted,
5  * free of charge, without warranty of any kind.
6  */
7 #ifndef ZRTOS_CLIST_H
8 #define ZRTOS_CLIST_H
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 
14 #include <zrtos/types.h>
15 
16 
17 typedef struct _zrtos_clist_node_t{
20 
21 typedef struct _zrtos_clist_t{
24 
26  return thiz->root;
27 }
28 
30  thiz->root = node;
31 }
32 
34  thiz->next = thiz;
35  return true;
36 }
37 
39  zrtos_clist_node_t *node
40 ){
41  return node->next;
42 }
43 
45  zrtos_clist_node_t *node
46 ){
47  return node->next != node;
48 }
49 
51  zrtos_clist_node_t *node
52 ){
53  zrtos_clist_node_t *ret = node;
55  while((next = ret->next) != node){
56  ret = next;
57  }
58  return ret;
59 }
60 
62  thiz->root = 0;
63  return true;
64 }
65 
67  return thiz->root;
68 }
69 
72  return root
74  : root;
75 }
76 
78  zrtos_clist_node_t *thiz
79  ,zrtos_clist_node_t *node
80 ){
81  node->next = thiz->next;
82  thiz->next = node;
83 }
84 
87  if(last){
88  zrtos_clist_node__append(last,node);
89  }else{
90  thiz->root = node;
91  }
92  return true;
93 }
94 
97 
98  if(prev != node){
99  prev->next = node->next;
100  }else{
101  thiz->root = 0;
102  }
103  node->next = node;
104 
105  return true;
106 }
107 
110  if(ret){
111  zrtos_clist__delete(thiz,ret);
112  }
113  return ret;
114 }
115 
117  if(thiz->root){
118  node->next = thiz->root;
119  }
120  thiz->root = node;
121 
122  return true;
123 }
124 
127  if(ret){
128  zrtos_clist__delete(thiz,ret);
129  }
130  return ret;
131 }
132 
135  if(node){
137  thiz
139  );
140  }
141 }
142 
144  zrtos_clist_t *thiz
145  ,bool (*callback)(zrtos_clist_node_t *node,void *arg)
146  ,void *arg
147 ){
149  if(node){
151  do{
152  next = zrtos_clist_node__get_next_node(node);
153  }while(callback(node,arg)
154  && (node = next) != zrtos_clist__get_root(thiz)
155  );
156  }
157 }
158 
159 #define ZRTOS_CLIST__EACH_BEGIN(thiz,node,container,member) \
160  do{\
161  zrtos_clist_t *clist = thiz;\
162  zrtos_clist_node_t *tmp = zrtos_clist__get_root(clist);\
163  zrtos_clist_node_t *next;\
164  container *node;\
165  if(tmp){\
166  do{\
167  next = tmp->next;\
168  node = zrtos_types__get_container_of(\
169  tmp,container,member\
170  );\
171  do{
172 
173 #define ZRTOS_CLIST__EACH_END\
174  }while(0);\
175  tmp = next;\
176  }while(tmp != zrtos_clist__get_root(clist));\
177  }\
178  }while(0)
179 
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 #endif
struct _zrtos_clist_t zrtos_clist_t
bool zrtos_clist__init(zrtos_clist_t *thiz)
Definition: clist.h:61
bool zrtos_clist__delete(zrtos_clist_t *thiz, zrtos_clist_node_t *node)
Definition: clist.h:95
struct _zrtos_clist_node_t zrtos_clist_node_t
zrtos_clist_node_t * zrtos_clist__get_root(zrtos_clist_t *thiz)
Definition: clist.h:25
struct _zrtos_clist_node_t * next
Definition: clist.h:18
static void zrtos_clist_node__append(zrtos_clist_node_t *thiz, zrtos_clist_node_t *node)
Definition: clist.h:77
void zrtos_clist__shift_and_push(zrtos_clist_t *thiz)
Definition: clist.h:133
zrtos_clist_node_t * zrtos_clist__get_first_node(zrtos_clist_t *thiz)
Definition: clist.h:66
zrtos_clist_node_t * zrtos_clist__shift(zrtos_clist_t *thiz)
Definition: clist.h:125
zrtos_clist_node_t * zrtos_clist__pop(zrtos_clist_t *thiz)
Definition: clist.h:108
bool zrtos_clist__unshift(zrtos_clist_t *thiz, zrtos_clist_node_t *node)
Definition: clist.h:116
zrtos_clist_node_t * root
Definition: clist.h:22
bool zrtos_clist__push(zrtos_clist_t *thiz, zrtos_clist_node_t *node)
Definition: clist.h:85
zrtos_clist_node_t * zrtos_clist_node__get_next_node(zrtos_clist_node_t *node)
Definition: clist.h:38
bool zrtos_clist_node__init(zrtos_clist_node_t *thiz)
Definition: clist.h:33
zrtos_clist_node_t * zrtos_clist__get_last_node(zrtos_clist_t *thiz)
Definition: clist.h:70
bool zrtos_clist_node__has_next_node(zrtos_clist_node_t *node)
Definition: clist.h:44
void zrtos_clist__each(zrtos_clist_t *thiz, bool(*callback)(zrtos_clist_node_t *node, void *arg), void *arg)
Definition: clist.h:143
void zrtos_clist__set_root(zrtos_clist_t *thiz, zrtos_clist_node_t *node)
Definition: clist.h:29
zrtos_clist_node_t * zrtos_clist_node__get_previous_node(zrtos_clist_node_t *node)
Definition: clist.h:50