odyssey/sources/list.h

72 lines
1.3 KiB
C
Raw Normal View History

#ifndef OD_LIST_H
#define OD_LIST_H
/*
2018-03-12 14:03:15 +00:00
* Odyssey.
*
2018-04-04 13:19:58 +00:00
* Scalable PostgreSQL connection pooler.
*/
typedef struct od_list od_list_t;
struct od_list
{
od_list_t *next, *prev;
};
static inline void
2017-05-24 12:13:44 +00:00
od_list_init(od_list_t *list)
{
list->next = list->prev = list;
}
static inline void
2017-05-24 12:13:44 +00:00
od_list_append(od_list_t *list, od_list_t *node)
{
node->next = list;
node->prev = list->prev;
node->prev->next = node;
node->next->prev = node;
}
static inline void
2017-05-24 12:13:44 +00:00
od_list_unlink(od_list_t *node)
{
node->prev->next = node->next;
node->next->prev = node->prev;
}
static inline void
2017-05-24 12:13:44 +00:00
od_list_push(od_list_t *list, od_list_t *node)
{
node->next = list->next;
node->prev = list;
node->prev->next = node;
node->next->prev = node;
}
static inline od_list_t*
2017-05-24 12:13:44 +00:00
od_list_pop(od_list_t *list)
{
register od_list_t *pop = list->next;
2017-05-24 12:13:44 +00:00
od_list_unlink(pop);
return pop;
}
static inline int
2017-05-24 12:13:44 +00:00
od_list_empty(od_list_t *list)
{
return list->next == list && list->prev == list;
}
2018-02-28 14:32:32 +00:00
#define od_list_foreach(list, iterator) \
for (iterator = (list)->next; iterator != list; \
iterator = (iterator)->next)
2018-02-28 14:32:32 +00:00
#define od_list_foreach_safe(list, iterator, safe) \
for (iterator = (list)->next; \
iterator != list && (safe = iterator->next); \
iterator = safe)
#endif /* OD_LIST_H */