FreeRTOS Emulator with SDL2 Based Graphics and Input Library  1.0
A POSIX wrapper to run FreeRTOS on an x86 machine with some basic input and output libraries aimed at making teaching FreeRTOS simpler.
ll.h
Go to the documentation of this file.
1 #ifndef __LL_H__
2 #define __LL_H__
3 
4 /****************************************************************************
5  ----------------------------------------------------------------------
6  Copyright (C) Alexander Hoffman, 2022
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ----------------------------------------------------------------------
21  ****************************************************************************/
22 
23 #include <stddef.h>
24 #include <stdint.h>
25 #include <stdio.h>
26 
36 struct list_item {
37  struct list_item *next, *prev;
38 };
39 
40 #define ll_get_container(ptr, type, member) \
41  ((type*)((void*)ptr - ((size_t) & ((type*)0)->member)))
42 
43 
44 #define ll_get_first_container(head, type, member) \
45  ll_get_container(head.next, type, member)
46 
47 #define ll_get_last_container(head, type, member) \
48  ll_get_container(head.prev, type, member)
49 
50 #define ll_get_next_container(container_ptr, type, member) \
51  ll_get_container(container_ptr->member.next, type, member)
52 
53 #define ll_get_prev_container(container_ptr, type, member) \
54  ll_get_container(container_ptr->member.prev, type, member)
55 
58 static inline void ll_init_list(struct list_item *list)
59 {
60  list->next = list;
61  list->prev = list;
62 }
63 
64 static inline void __ll_add(
65  struct list_item *new_item, struct list_item *prev, struct list_item *next)
66 {
67 
68  new_item->next = next;
69  new_item->prev = prev;
70  prev->next = new_item;
71  next->prev = new_item;
72 }
73 
77 static inline void ll_add(struct list_item *new_item, struct list_item *prev)
78 {
79  __ll_add(new_item, prev, prev->next);
80 }
81 
85 static inline void ll_add_tail(
86  struct list_item *new_item, struct list_item *next)
87 {
88  __ll_add(new_item, next->prev, next);
89 }
90 
91 static inline void __ll_del(struct list_item *prev, struct list_item *next)
92 {
93  prev->next = next;
94  next->prev = next;
95 }
96 
99 static inline void ll_del(struct list_item *del)
100 {
101  __ll_del(del->prev, del->next);
102  del->next = NULL;
103  del->prev = NULL;
104 }
105 
106 #define ll_del_free(ptr, type, member) \
107  ll_del(ptr); free(ll_get_container(ptr, type, member));
108 
112 static inline unsigned char ll_is_empty(struct list_item *head)
113 {
114  return head->next == head;
115 }
116 
118 #endif // __LL_H__
aIO_t head
Definition: AsyncIO.c:102
struct aIO * next
Definition: AsyncIO.c:89
Definition: ll.h:36
struct list_item * prev
Definition: ll.h:37
struct list_item * next
Definition: ll.h:37