-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtomicMarkableReference.h
More file actions
98 lines (85 loc) · 3.04 KB
/
Copy pathAtomicMarkableReference.h
File metadata and controls
98 lines (85 loc) · 3.04 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
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
#ifndef ATOMICMARKABLEREFERENCE_H
#define ATOMICMARKABLEREFERENCE_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct atomic_markable_reference atomic_markable_reference;
atomic_markable_reference* atomic_markable_reference_init(void* init_obj, int init_mark);
void atomic_markable_reference_destroy(atomic_markable_reference* m_ref);
/*
* Atomically sets the value of the mark.
* Returns:
* true if successful
*/
int attempt_mark(atomic_markable_reference* m_ref,
int expected_mark, int new_mark);
/*
* Atomically sets the value of both the reference and mark to the given
* update values if the current reference is == to the expected reference
* and the current mark is equal to the expected mark.
* Parameters:
* expectedReference - the expected value of the reference
* newReference - the new value for the reference
* expectedMark - the expected value of the mark
* newMark - the new value for the mark
* Returns:
* true if successful
*/
int compare_and_set(atomic_markable_reference* m_ref, void* expected_ref,
void* new_ref, int expected_mark, int new_mark);
/*
* Returns the current values of both the reference and the mark.
* Typical usage is int holder; ref = v.get(holder);
* Parameters:
* markHolder - an allocated int. On return, it will hold the value of the mark.
* Returns:
* the current value of the reference
*/
void* get(atomic_markable_reference* m_ref, int* mark_value);
/*
* Returns the current value of the reference.
* Returns:
* the current value of the reference
*/
void* get_reference(atomic_markable_reference* m_ref);
/*
* Returns the current value of the mark.
* Returns:
* the current value of the mark
*/
int is_marked(atomic_markable_reference* m_ref);
/*
* Unconditionally sets the value of both the reference and mark.
* Parameters:
* newReference - the new value for the reference
* newMark - the new value for the mark
*/
void set(atomic_markable_reference* m_ref, void* new_ref, int new_mark);
/*
* Atomically sets the value of both the reference and mark to the given update
* values if the current reference is == to the expected reference and the current
* mark is equal to the expected mark.
* May fail spuriously and does not provide ordering guarantees, so is only
* rarely an appropriate alternative to compareAndSet.
* Parameters:
* expectedReference - the expected value of the reference
* newReference - the new value for the reference
* expectedMark - the expected value of the mark
* newMark - the new value for the mark
* Returns:
* true if successful
*/
int weak_compare_and_set(atomic_markable_reference* m_ref, void* expected_ref,
void* new_ref, int expected_mark, int new_mark);
/*
* In C, the implementation is architecture dependent, and not every
* implementation is lock free, this should atomically tell you if both
* the mark and reference values in the underlying structure are lock free
* Returns:
* true if both member variables are lock free
*/
int is_lock_free(atomic_markable_reference* m_ref);
#ifdef __cplusplus
}
#endif
#endif