550W Document
550W, a high-end OS
list.h
浏览该文件的文档.
1
#pragma once
2
#include <
common/types.h
>
3
4
/* clang-format off */
5
// double-linked list
6
// TODO: use your own list design!!
7
typedef
struct
list_node
{
8
struct
list_node
*
next
, *
prev
;
9
}
list_node_t
;
10
11
typedef
list_node_t
list_head
;
12
13
#define LIST_HEAD_INIT(name) { &(name), &(name) }
14
15
#define LIST_HEAD(name) \
16
list_head name = LIST_HEAD_INIT(name)
17
18
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
19
20
#define container_of(ptr, type, member) ({ \
21
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
22
(type *)( (char *)__mptr - offsetof(type,member) );})
23
24
25
#define list_entry(ptr, type, member) \
26
container_of(ptr, type, member)
27
28
static
inline
void
init_list_head(
list_head
*list)
29
{
30
list->
next
= list;
31
list->
prev
= list;
32
}
33
34
static
inline
void
list_init_with_null(
list_head
*list){
35
list->
next
=
NULL
;
36
list->
prev
=
NULL
;
37
}
38
39
// add
40
static
inline
void
__list_add(
list_head
*
new
,
list_head
*
prev
,
list_head
*
next
)
41
{
42
next
->
prev
=
new
;
43
new
->
next
=
next
;
44
new
->
prev
=
prev
;
45
prev
->
next
=
new
;
46
}
47
48
static
inline
void
list_add(
list_head
*
new
,
list_head
*
head
)
49
{
50
__list_add(
new
,
head
,
head
->
next
);
51
}
52
53
static
inline
void
list_add_tail(
list_head
*
new
,
list_head
*
head
)
54
{
55
__list_add(
new
,
head
->
prev
,
head
);
56
}
57
58
// del
59
static
inline
void
__list_del(
list_head
*
prev
,
list_head
*
next
)
60
{
61
next
->
prev
=
prev
;
62
prev
->
next
=
next
;
63
}
64
65
static
inline
void
__list_del_entry(
list_head
*entry)
66
{
67
__list_del(entry->
prev
, entry->
next
);
68
}
69
70
static
inline
void
list_del(
list_head
*entry)
71
{
72
__list_del_entry(entry);
73
entry->
next
=
NULL
;
74
entry->
prev
=
NULL
;
75
}
76
77
static
inline
void
list_move(
list_head
*list,
list_head
*
head
)
78
{
79
__list_del_entry(list);
80
list_add(list,
head
);
81
}
82
83
static
inline
void
list_move_tail(
list_head
*list,
list_head
*
head
)
84
{
85
__list_del(list->
prev
, list->
next
);
86
list_add_tail(list,
head
);
87
}
88
89
90
// judge
91
static
inline
int
list_is_first(
list_head
*list,
const
list_head
*
head
)
92
{
93
return
list->
prev
==
head
;
94
}
95
96
static
inline
int
list_is_last(
list_head
*list,
list_head
*
head
)
97
{
98
return
list->
next
==
head
;
99
}
100
101
static
inline
int
list_is_empty(
list_head
*
head
)
102
{
103
return
head
->
next
==
head
;
104
}
105
106
/* clang-format on */
list_node_t
struct list_node list_node_t
list_head
list_node_t list_head
Definition:
list.h:11
buf::prev
struct buf * prev
Definition:
virtio.h:85
buf::next
struct buf * next
Definition:
virtio.h:86
list_node
Definition:
list.h:7
list_node::next
struct list_node * next
Definition:
list.h:8
list_node::prev
struct list_node * prev
Definition:
list.h:8
types.h
NULL
#define NULL
Definition:
types.h:6
head
buf_t head
Definition:
virtio_blk.c:215
src
include
lib
list.h
制作者
1.9.1