1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#ifndef __LIBCEPHFS_PROXY_LIST_H__
#define __LIBCEPHFS_PROXY_LIST_H__
#include "proxy.h"
#define LIST_INIT(_list) { _list, _list }
#define list_entry(_ptr, _type, _field) container_of(_ptr, _type, _field)
#define list_first_entry(_list, _type, _field) \
list_entry((_list)->next, _type, _field)
#define list_last_entry(_list, _type, _field) \
list_entry((_list)->prev, _type, _field)
#define list_next_entry(_ptr, _field) \
list_first_entry(&_ptr->_field, __typeof(*_ptr), _field)
#define list_for_each_entry(_ptr, _list, _field) \
for (_ptr = list_first_entry(_list, __typeof(*_ptr), _field); \
&_ptr->_field != _list; _ptr = list_next_entry(_ptr, _field))
static inline void list_init(list_t *list)
{
list->next = list;
list->prev = list;
}
static inline bool list_empty(list_t *list)
{
return list->next == list;
}
static inline void list_add_between(list_t *item, list_t *prev, list_t *next)
{
item->next = next;
item->prev = prev;
prev->next = item;
next->prev = item;
}
static inline void list_add(list_t *item, list_t *list)
{
list_add_between(item, list, list->next);
}
static inline void list_add_tail(list_t *item, list_t *list)
{
list_add_between(item, list->prev, list);
}
static inline void list_del(list_t *list)
{
list->next->prev = list->prev;
list->prev->next = list->next;
}
static inline void list_del_init(list_t *list)
{
list_del(list);
list_init(list);
}
static inline void list_move(list_t *item, list_t *list)
{
list_del(item);
list_add(item, list);
}
static inline void list_move_tail(list_t *item, list_t *list)
{
list_del(item);
list_add_tail(item, list);
}
static inline void list_splice_between(list_t *src, list_t *prev, list_t *next)
{
list_t *first, *last;
first = src->next;
last = src->prev;
first->prev = prev;
prev->next = first;
last->next = next;
next->prev = last;
}
static inline void list_splice(list_t *src, list_t *dst)
{
if (!list_empty(src)) {
list_splice_between(src, dst, dst->next);
}
}
static inline void list_splice_tail(list_t *src, list_t *dst)
{
if (!list_empty(src)) {
list_splice_between(src, dst->prev, dst);
}
}
static inline void list_splice_init(list_t *src, list_t *dst)
{
if (!list_empty(src)) {
list_splice_between(src, dst, dst->next);
list_init(src);
}
}
static inline void list_splice_tail_init(list_t *src, list_t *dst)
{
if (!list_empty(src)) {
list_splice_between(src, dst->prev, dst);
list_init(src);
}
}
#endif
|