-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
49 lines (32 loc) · 1.13 KB
/
stack.h
File metadata and controls
49 lines (32 loc) · 1.13 KB
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
#ifndef _HEADER_S
#define _HEADER_S
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdatomic.h>
#define STACK_NEXT ((1ull << 56) - 1)
#define FOREACH_STACK(s, n) \
for (struct stacknode *n = (struct stacknode *)(atomic_load(&(s)->root) & STACK_NEXT), *n##next = NULL; \
(n##next = n ? (struct stacknode *)(atomic_load(&n->next) & STACK_NEXT) : NULL, n); n = n##next)
struct stacknode {
_Atomic uint64_t next;
};
struct stack {
_Atomic int64_t count;
_Atomic uint64_t root;
};
void stack_push(uint8_t tid, struct stack *l, struct stacknode *n);
struct stacknode *stack_pop(uint8_t tid, struct stack *);
struct strings {
char **data;
size_t len;
size_t cap;
};
void strings_push(struct strings *ss, char *s);
void strings_clear(struct strings *ss);
void strings_free(struct strings *ss);
#define STACK_FREE_VARARG(_1,_2,NAME,...) NAME
#define STACK_FREE(s) do { FOREACH_STACK(s, n) free(n); } while(0);
#define STACK_FREE2(s, f) do { FOREACH_STACK(s, n) f(n); } while(0);
#define stack_free(...) STACK_FREE_VARARG(__VA_ARGS__, STACK_FREE2, STACK_FREE)(__VA_ARGS__)
#endif