forked from wuxb45/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwh.h
313 lines (222 loc) · 8.47 KB
/
wh.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
* Copyright (c) 2016--2021 Wu, Xingbo <[email protected]>
*
* All rights reserved. No warranty, explicit or implicit, provided.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
struct wormhole;
struct wormref;
// wormhole {{{
// the wh created by wormhole_create() can work with all of safe/unsafe operations.
extern struct wormhole *
wormhole_create(const struct kvmap_mm * const mm);
// the wh created by whunsafe_create() can only work with the unsafe operations.
extern struct wormhole *
whunsafe_create(const struct kvmap_mm * const mm);
extern struct kv *
wormhole_get(struct wormref * const ref, const struct kref * const key, struct kv * const out);
extern bool
wormhole_probe(struct wormref * const ref, const struct kref * const key);
extern bool
wormhole_put(struct wormref * const ref, struct kv * const kv);
extern bool
wormhole_merge(struct wormref * const ref, const struct kref * const kref,
kv_merge_func uf, void * const priv);
extern bool
wormhole_inpr(struct wormref * const ref, const struct kref * const key,
kv_inp_func uf, void * const priv);
extern bool
wormhole_inpw(struct wormref * const ref, const struct kref * const key,
kv_inp_func uf, void * const priv);
extern bool
wormhole_del(struct wormref * const ref, const struct kref * const key);
extern u64
wormhole_delr(struct wormref * const ref, const struct kref * const start,
const struct kref * const end);
extern struct wormhole_iter *
wormhole_iter_create(struct wormref * const ref);
extern void
wormhole_iter_seek(struct wormhole_iter * const iter, const struct kref * const key);
extern bool
wormhole_iter_valid(struct wormhole_iter * const iter);
extern struct kv *
wormhole_iter_peek(struct wormhole_iter * const iter, struct kv * const out);
extern bool
wormhole_iter_kref(struct wormhole_iter * const iter, struct kref * const kref);
extern bool
wormhole_iter_kvref(struct wormhole_iter * const iter, struct kvref * const kvref);
extern void
wormhole_iter_skip1(struct wormhole_iter * const iter);
extern void
wormhole_iter_skip(struct wormhole_iter * const iter, const u32 nr);
extern struct kv *
wormhole_iter_next(struct wormhole_iter * const iter, struct kv * const out);
extern bool
wormhole_iter_inp(struct wormhole_iter * const iter, kv_inp_func uf, void * const priv);
extern void
wormhole_iter_park(struct wormhole_iter * const iter);
extern void
wormhole_iter_destroy(struct wormhole_iter * const iter);
extern struct wormref *
wormhole_ref(struct wormhole * const map);
extern struct wormhole *
wormhole_unref(struct wormref * const ref);
extern void
wormhole_park(struct wormref * const ref);
extern void
wormhole_resume(struct wormref * const ref);
extern void
wormhole_refresh_qstate(struct wormref * const ref);
// clean with more threads
extern void
wormhole_clean_th(struct wormhole * const map, const u32 nr_threads);
extern void
wormhole_clean(struct wormhole * const map);
extern void
wormhole_destroy(struct wormhole * const map);
// safe API (no need to refresh qstate)
extern struct kv *
whsafe_get(struct wormref * const ref, const struct kref * const key, struct kv * const out);
extern bool
whsafe_probe(struct wormref * const ref, const struct kref * const key);
extern bool
whsafe_put(struct wormref * const ref, struct kv * const kv);
extern bool
whsafe_merge(struct wormref * const ref, const struct kref * const kref,
kv_merge_func uf, void * const priv);
extern bool
whsafe_inpr(struct wormref * const ref, const struct kref * const key,
kv_inp_func uf, void * const priv);
extern bool
whsafe_inpw(struct wormref * const ref, const struct kref * const key,
kv_inp_func uf, void * const priv);
extern bool
whsafe_del(struct wormref * const ref, const struct kref * const key);
extern u64
whsafe_delr(struct wormref * const ref, const struct kref * const start,
const struct kref * const end);
// use wormhole_iter_create
extern void
whsafe_iter_seek(struct wormhole_iter * const iter, const struct kref * const key);
extern struct kv *
whsafe_iter_peek(struct wormhole_iter * const iter, struct kv * const out);
// use wormhole_iter_valid
// use wormhole_iter_peek
// use wormhole_iter_kref
// use wormhole_iter_kvref
// use wormhole_iter_skip1
// use wormhole_iter_skip
// use wormhole_iter_next
// use wormhole_iter_inp
extern void
whsafe_iter_park(struct wormhole_iter * const iter);
extern void
whsafe_iter_destroy(struct wormhole_iter * const iter);
extern struct wormref *
whsafe_ref(struct wormhole * const map);
// use wormhole_unref
// unsafe API
extern struct kv *
whunsafe_get(struct wormhole * const map, const struct kref * const key, struct kv * const out);
extern bool
whunsafe_probe(struct wormhole * const map, const struct kref * const key);
extern bool
whunsafe_put(struct wormhole * const map, struct kv * const kv);
extern bool
whunsafe_merge(struct wormhole * const map, const struct kref * const kref,
kv_merge_func uf, void * const priv);
extern bool
whunsafe_inp(struct wormhole * const map, const struct kref * const key,
kv_inp_func uf, void * const priv);
extern bool
whunsafe_del(struct wormhole * const map, const struct kref * const key);
extern u64
whunsafe_delr(struct wormhole * const map, const struct kref * const start,
const struct kref * const end);
extern struct wormhole_iter *
whunsafe_iter_create(struct wormhole * const map);
extern void
whunsafe_iter_seek(struct wormhole_iter * const iter, const struct kref * const key);
// unsafe iter_valid: use wormhole_iter_valid
// unsafe iter_peek: use wormhole_iter_peek
// unsafe iter_kref: use wormhole_iter_kref
extern void
whunsafe_iter_skip1(struct wormhole_iter * const iter);
extern void
whunsafe_iter_skip(struct wormhole_iter * const iter, const u32 nr);
extern struct kv *
whunsafe_iter_next(struct wormhole_iter * const iter, struct kv * const out);
// unsafe iter_inp: use wormhole_iter_inp
extern void
whunsafe_iter_destroy(struct wormhole_iter * const iter);
extern void
wormhole_fprint(struct wormhole * const map, FILE * const out);
extern const struct kvmap_api kvmap_api_wormhole;
extern const struct kvmap_api kvmap_api_whsafe;
extern const struct kvmap_api kvmap_api_whunsafe;
// }}} wormhole
// wh {{{
extern struct wormhole *
wh_create(void);
extern struct wormref *
wh_ref(struct wormhole * const wh);
extern void
wh_unref(struct wormref * const ref);
extern void
wh_park(struct wormref * const ref);
extern void
wh_resume(struct wormref * const ref);
extern void
wh_clean(struct wormhole * const map);
extern void
wh_destroy(struct wormhole * const map);
extern bool
wh_put(struct wormref * const ref, const void * const kbuf, const u32 klen,
const void * const vbuf, const u32 vlen);
extern bool
wh_del(struct wormref * const ref, const void * const kbuf, const u32 klen);
extern bool
wh_probe(struct wormref * const ref, const void * const kbuf, const u32 klen);
extern bool
wh_get(struct wormref * const ref, const void * const kbuf, const u32 klen,
void * const vbuf_out, const u32 vbuf_size, u32 * const vlen_out);
extern bool
wh_inpr(struct wormref * const ref, const void * const kbuf, const u32 klen,
kv_inp_func uf, void * const priv);
extern bool
wh_inpw(struct wormref * const ref, const void * const kbuf, const u32 klen,
kv_inp_func uf, void * const priv);
extern bool
wh_merge(struct wormref * const ref, const void * const kbuf, const u32 klen,
kv_merge_func uf, void * const priv);
extern u64
wh_delr(struct wormref * const ref, const void * const kbuf_start, const u32 klen_start,
const void * const kbuf_end, const u32 klen_end);
extern struct wormhole_iter *
wh_iter_create(struct wormref * const ref);
extern void
wh_iter_seek(struct wormhole_iter * const iter, const void * const kbuf, const u32 klen);
extern bool
wh_iter_valid(struct wormhole_iter * const iter);
extern bool
wh_iter_peek(struct wormhole_iter * const iter,
void * const kbuf_out, const u32 kbuf_size, u32 * const klen_out,
void * const vbuf_out, const u32 vbuf_size, u32 * const vlen_out);
extern void
wh_iter_skip1(struct wormhole_iter * const iter);
extern void
wh_iter_skip(struct wormhole_iter * const iter, const u32 nr);
extern bool
wh_iter_inp(struct wormhole_iter * const iter, kv_inp_func uf, void * const priv);
extern void
wh_iter_park(struct wormhole_iter * const iter);
extern void
wh_iter_destroy(struct wormhole_iter * const iter);
// }}} wh
#ifdef __cplusplus
}
#endif
// vim:fdm=marker