-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHazardPointer.h
37 lines (26 loc) · 916 Bytes
/
HazardPointer.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
#pragma once
#include <stdatomic.h>
#include <stddef.h>
#include <stdint.h>
#define MAX_THREADS 128
static const int RETIRED_THRESHOLD = MAX_THREADS;
typedef struct RetiredPointer_Node {
void* pointer;
struct RetiredPointer_Node* next;
} RetiredPointer_Node;
typedef struct RetiredPointer_List {
RetiredPointer_Node* head;
RetiredPointer_Node* tail;
int size;
} RetiredPointer_List;
struct HazardPointer {
_Atomic(void*) pointer[MAX_THREADS];
RetiredPointer_List* retired_ptrs[MAX_THREADS];
};
typedef struct HazardPointer HazardPointer;
void HazardPointer_register(int thread_id, int num_threads);
void HazardPointer_initialize(HazardPointer* hp);
void HazardPointer_finalize(HazardPointer* hp);
void* HazardPointer_protect(HazardPointer* hp, const _Atomic(void*)* atom);
void HazardPointer_clear(HazardPointer* hp);
void HazardPointer_retire(HazardPointer* hp, void* ptr);