-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
74 lines (60 loc) · 1.7 KB
/
list.h
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
#pragma once
typedef struct _MP_LIST_ENTRY
{
struct _MP_LIST_ENTRY *prev, *next;
}MP_LIST_ENTRY, *PMP_LIST_ENTRY;
static inline void InitializeMPListEntry( struct _MP_LIST_ENTRY *list )
{
list->prev = list->next = list;
}
static inline void __MP_LIST_ADD( struct _MP_LIST_ENTRY *entry,
struct _MP_LIST_ENTRY *prev,
struct _MP_LIST_ENTRY *next )
{
next->prev = entry;
entry->next = next;
entry->prev = prev;
prev->next = entry;
}
static inline void MPListInsertToTail( struct _MP_LIST_ENTRY *head,
struct _MP_LIST_ENTRY *entry )
{
__MP_LIST_ADD( entry, head->prev, head );
}
static inline void MPListInsertToHead( struct _MP_LIST_ENTRY *head,
struct _MP_LIST_ENTRY *entry )
{
__MP_LIST_ADD( entry, head, head->next );
}
static inline void __MP_LIST_DEL( struct _MP_LIST_ENTRY * prev,
struct _MP_LIST_ENTRY * next )
{
next->prev = prev;
prev->next = next;
}
static inline void MPRemoveEntryList( struct _MP_LIST_ENTRY *entry )
{
__MP_LIST_DEL( entry->prev, entry->next );
entry->next = NULL;
entry->prev = NULL;
}
static inline bool MPListIsEmpty( const struct _MP_LIST_ENTRY *head )
{
return head->next == head;
}
static inline int MPListIsLast( const struct _MP_LIST_ENTRY *list,
const struct _MP_LIST_ENTRY *head )
{
return list->next == head;
}
static inline int MPListIsFirst( const struct _MP_LIST_ENTRY *list,
const struct _MP_LIST_ENTRY *head )
{
return list->prev == head;
}
#ifndef container_of
#define container_of(ptr, type, member) ((type *) ((char *) (ptr) - offsetof(type, member)))
#endif
//linux replace to container_of
#define MPListFirstEntry(H,S,M) container_of((H)->next,S,M)
#define MPListLastEntry(H,S,M) container_of((H)->prev,S,M)