-
Notifications
You must be signed in to change notification settings - Fork 0
/
lflist.h
131 lines (101 loc) · 3.63 KB
/
lflist.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
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
122
123
124
125
126
127
128
129
130
131
#pragma once
/* NB: lflist.cpp doesn't actually include this. You're better off reading
lflist.hpp. */
typedef struct flref{
volatile struct flanchor *ptr;
uptr gen;
}flref;
#ifdef FAKELOCKFREE
#include <fakelflist.h>
#else
#include <nalloc.h>
enum flst{
COMMIT,
RDY,
ADD,
ABORT,
};
struct flx{
union{
struct{
enum flst st:2;
uptr nil:1;
uptr pt:WORDBITS-3;
};
uptr constexp;
};
uptr gen;
};
typedef struct flx flx;
typedef volatile struct flanchor flanchor;
struct flanchor{
flx n;
flx p;
}align(2 * sizeof(dptr));
#define FLANCHOR(list){ \
.n.constexp = (list) \
? 5 + (uptr) (list) \
: 0, \
.p.constexp = (list) \
? 5 + (uptr) (list) \
: 0, \
}
typedef volatile struct lflist{
struct flanchor nil;
}lflist;
#define LFLIST(l, elem){ \
{.n = {.constexp = (elem) \
? 1 + (uptr) (elem) \
: 5 + (uptr) (l)}, \
.p = {.constexp = (elem) \
? (uptr) (elem) \
: 5 + (uptr) (l)}, \
}}
static inline constfun
flanchor *flptr(flref a){
return a.ptr;
}
static inline
flref flref_of(flanchor *a){
return (flref){.ptr = a, .gen = a->p.gen};
}
#endif /* FAKELOCKFREE */
flanchor *flptr(flref a);
flref flref_of(flanchor *a);
err lflist_enq_cas(uptr ng, flref a, lflist *l, type *t);
err lflist_enq(flref a, lflist *l, type *t);
flref lflist_unenq(lflist *l, type *t);
flref lflist_deq(lflist *l, type *t);
err lflist_del_cas(uptr ng, flref a, type *t);
err lflist_del(flref a, type *t);
err lflist_jam(flref a, type *t);
bool flanc_valid(flanchor *a);
#ifndef FAKELOCKFREE
static inline
const char *flstatestr(uptr s){
return (const char *[]){"COMMIT", "RDY", "ADD", "ABORT"}[s];
}
#define pudef (struct flx, \
"{%:% %, %}", (void *)(uptr)(a->pt << 3), (uptr) a->nil, \
flstatestr(a->st), (uptr) a->gen)
#include <pudef.h>
#define pudef (struct flref, \
"{%:%}", (void *) a->ptr, a->gen)
#include <pudef.h>
#define pudef (struct flanchor, "n:%, p:%", a->n, a->p)
#include <pudef.h>
#define pudef (struct lflist, "LIST(%)", a->nil)
#include <pudef.h>
#endif
#ifndef LOG_LFLISTM
#define LOG_LFLISTM 0
#endif
#define lflist_enq_cas(ng, a, t, l) \
linref_account(0, trace(LFLISTM, 2, lflist_enq_cas, PUN(uptr, ng), a, t, l))
#define lflist_del_cas(ng, a, t) \
linref_account(0, trace(LFLISTM, 2, lflist_del_cas, PUN(uptr, ng), a, t))
#define lflist_del(as...) linref_account(0, trace(LFLISTM, 2, lflist_del, as))
#define lflist_unenq(as...) \
linref_account(flptr(account_expr) ? 1 : 0, trace(LFLISTM, 2, lflist_unenq, as))
#define lflist_enq(as...) linref_account(0, trace(LFLISTM, 2, lflist_enq, as))
#define lflist_jam(as...) linref_account(0, trace(LFLISTM, 2, lflist_jam, as))