]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Typed lists: enabled defining the list structure independently on the node
authorMaria Matejka <mq@ucw.cz>
Sun, 11 Feb 2024 21:57:55 +0000 (22:57 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 27 Mar 2024 13:28:37 +0000 (14:28 +0100)
lib/tlists.h

index d7f1cf03e62af1e0df4ac4d87b02f68ca4b22ef2..70b8eb3f436cd4c2915fea22df7d7ddc7a3888c2 100644 (file)
 
 #define TLIST_NAME(x)  MACRO_CONCAT_AFTER(TLIST_PREFIX,_##x)
 #ifndef TLIST_LIST_STRUCT
-#define TLIST_LIST_STRUCT      TLIST_NAME(list)
+#define TLIST_LIST_STRUCT      struct TLIST_NAME(list)
 #endif
 
-typedef struct TLIST_LIST_STRUCT {
-  TLIST_TYPE *first;
-  TLIST_TYPE *last;
-} TLIST_LIST_STRUCT;
+#ifndef TLIST_DEFINED_BEFORE
+TLIST_STRUCT_DEF(TLIST_PREFIX, TLIST_TYPE);
+#endif
 
-static inline struct TLIST_LIST_STRUCT * TLIST_NAME(enlisted)(TLIST_TYPE *node)
+static inline TLIST_LIST_STRUCT * TLIST_NAME(enlisted)(TLIST_TYPE *node)
 {
   return node->TLIST_ITEM.list;
 }
@@ -206,6 +205,7 @@ static inline void TLIST_NAME(rem_node)(TLIST_LIST_STRUCT *list, TLIST_TYPE *nod
 #endif
 
 #define TLIST_LIST(_name)              struct _name##_list
+#define TLIST_STRUCT_DEF(_name, _type) TLIST_LIST(_name) { _type *first, *last; }
 
 #define TLIST_NODE_IN(_name, _type)    { _type *next; _type *prev; TLIST_LIST(_name) *list; }
 #define TLIST_NODE(_name, _type)       struct _name##_node TLIST_NODE_IN(_name, _type)