agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
list.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_LIST_H
8 #define ZRTOS_LIST_H
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 
14 #include <zrtos/types.h>
15 
16 
17 typedef struct _zrtos_list_node_t{
20 
21 typedef struct _zrtos_list_t{
25 
27  return thiz->first;
28 }
29 
31  return thiz->last;
32 }
33 
35  thiz->next = 0;
36  return true;
37 }
38 
40  zrtos_list_node_t *node
41 ){
42  return node->next;
43 }
44 
46  zrtos_list_node_t *node
47 ){
48  return node->next != 0;
49 }
50 
52  thiz->first = 0;
53  thiz->last = 0;
54  return true;
55 }
56 
59  if(last){
60  thiz->last = last->next = node;
61  }else{
62  thiz->first = thiz->last = node;
63  }
64  return true;
65 }
66 
69  if(first){
70  thiz->first = node;
71  node->next = first;
72  }else{
73  thiz->first = thiz->last = node;
74  }
75  return true;
76 }
77 
80  if(ret){
81  thiz->first = ret->next;
82  if(thiz->first == 0){
83  thiz->last = 0;
84  }
85  }
86  return ret;
87 }
88 
91  if(node){
92  zrtos_list__push(thiz,node);
93  }
94 }
95 
99  if(node == prev){
100  zrtos_list__shift(thiz);
101  }else{
102  while((next = prev->next) != node){
103  prev = next;
104  }
105  if((prev->next = node->next) == 0){
106  thiz->last = prev;
107  }
108  }
109 }
110 
112  return zrtos_list__get_first_node(thiz) == 0;
113 }
114 
116  zrtos_list_t *thiz
117  ,void (*callback)(zrtos_list_t *thiz,zrtos_list_node_t *node)
118 ){
119  while(!zrtos_list__is_empty(thiz)){
120  zrtos_list_node_t *node = zrtos_list__shift(thiz);
121  callback(thiz,node);
122  }
123 }
124 
126  zrtos_list_t *thiz
127  ,bool (*callback)(zrtos_list_node_t *node,void *arg)
128  ,void *arg
129 ){
131  zrtos_list_node_t *root = node;
132  if(node){
134  do{
135  next = node->next;
136  }while(callback(node,arg) && (node = next) != root);
137  }
138 }
139 
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 #endif
zrtos_list_node_t * first
Definition: list.h:22
bool zrtos_list__is_empty(zrtos_list_t *thiz)
Definition: list.h:111
zrtos_list_node_t * last
Definition: list.h:23
void zrtos_list__delete(zrtos_list_t *thiz, zrtos_list_node_t *node)
Definition: list.h:96
bool zrtos_list__unshift(zrtos_list_t *thiz, zrtos_list_node_t *node)
Definition: list.h:67
struct _zrtos_list_node_t * next
Definition: list.h:18
zrtos_list_node_t * zrtos_list__get_last_node(zrtos_list_t *thiz)
Definition: list.h:30
bool zrtos_list_node__has_next_node(zrtos_list_node_t *node)
Definition: list.h:45
void zrtos_list__each(zrtos_list_t *thiz, bool(*callback)(zrtos_list_node_t *node, void *arg), void *arg)
Definition: list.h:125
bool zrtos_list__init(zrtos_list_t *thiz)
Definition: list.h:51
void zrtos_list__shift_and_push(zrtos_list_t *thiz)
Definition: list.h:89
zrtos_list_node_t * zrtos_list__get_first_node(zrtos_list_t *thiz)
Definition: list.h:26
zrtos_list_node_t * zrtos_list_node__get_next_node(zrtos_list_node_t *node)
Definition: list.h:39
bool zrtos_list_node__init(zrtos_list_node_t *thiz)
Definition: list.h:34
bool zrtos_list__push(zrtos_list_t *thiz, zrtos_list_node_t *node)
Definition: list.h:57
struct _zrtos_list_t zrtos_list_t
zrtos_list_node_t * zrtos_list__shift(zrtos_list_t *thiz)
Definition: list.h:78
struct _zrtos_list_node_t zrtos_list_node_t
void zrtos_list__deinit(zrtos_list_t *thiz, void(*callback)(zrtos_list_t *thiz, zrtos_list_node_t *node))
Definition: list.h:115