-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunrelacy.h
96 lines (76 loc) · 2.4 KB
/
unrelacy.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
#ifndef __UNRELACY_H__
#define __UNRELACY_H__
#include <stdatomic.h>
#include <stdlib.h>
#include <stdio.h>
#include <mutex>
#include <condition_variable>
#include <model-assert.h>
#include <librace.h>
#define $
#define ASSERT(expr) MODEL_ASSERT(expr)
#define RL_ASSERT(expr) MODEL_ASSERT(expr)
#define RL_NEW new
#define RL_DELETE(expr) delete expr
#define mo_seqcst memory_order_relaxed
#define mo_release memory_order_release
#define mo_acquire memory_order_acquire
#define mo_acq_rel memory_order_acq_rel
#define mo_relaxed memory_order_relaxed
namespace rl {
/* This 'useless' struct is declared just so we can use partial template
* specialization in our store and load functions. */
template <typename T, size_t n>
struct useless {
static void store(void *addr, T val);
static T load(const void *addr);
};
template <typename T>
struct useless<T, 1> {
static void store(void *addr, T val) { store_8(addr, (uint8_t)val); }
static T load(const void *addr) { return (T)load_8(addr); }
};
template <typename T>
struct useless<T, 2> {
static void store(void *addr, T val) { store_16(addr, (uint16_t)val); }
static T load(const void *addr) { return (T)load_16(addr); }
};
template <typename T>
struct useless<T, 4> {
static void store(void *addr, T val) { store_32(addr, (uint32_t)val); }
static T load(const void *addr) { return (T)load_32(addr); }
};
template <typename T>
struct useless<T, 8> {
static void store(void *addr, T val) { store_64(addr, (uint64_t)val); }
static T load(const void *addr) { return (T)load_64(addr); }
};
template <typename T>
struct var {
var() { useless<T, sizeof(T)>::store(&value, 0); }
var(T v) { useless<T, sizeof(T)>::store(&value, v); }
var(var const& r) {
value = r.value;
}
~var() { }
void operator = (T v) { useless<T, sizeof(T)>::store(&value, v); }
T operator () () { return useless<T, sizeof(T)>::load(&value); }
void operator += (T v) {
useless<T, sizeof(T)>::store(&value,
useless<T, sizeof(T)>::load(&value) + v);
}
bool operator == (const struct var<T> v) const { return useless<T, sizeof(T)>::load(&value) == useless<T, sizeof(T)>::load(&v.value); }
T value;
};
class backoff_t
{
public:
typedef int debug_info_param;
void yield(debug_info_param info) { }
void yield() { }
};
typedef backoff_t backoff;
typedef backoff_t linear_backoff;
typedef backoff_t exp_backoff;
}
#endif /* __UNRELACY_H__ */