forked from yandex/odyssey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atomic.h
90 lines (73 loc) · 2.04 KB
/
atomic.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
#ifndef ODYSSEY_ATOMIC_H
#define ODYSSEY_ATOMIC_H
/*
* Odyssey.
*
* Scalable PostgreSQL connection pooler.
*/
typedef volatile uint32_t od_atomic_u32_t;
typedef volatile uint64_t od_atomic_u64_t;
static inline uint32_t od_atomic_u32_of(od_atomic_u32_t *atomic)
{
return __sync_fetch_and_add(atomic, 0);
}
static inline uint32_t od_atomic_u32_inc(od_atomic_u32_t *atomic)
{
return __sync_fetch_and_add(atomic, 1);
}
static inline uint32_t od_atomic_u32_dec(od_atomic_u32_t *atomic)
{
return __sync_fetch_and_sub(atomic, 1);
}
static inline uint32_t od_atomic_u32_add(od_atomic_u32_t *atomic,
uint32_t value)
{
return __sync_add_and_fetch(atomic, value);
}
static inline uint32_t od_atomic_u32_sub(od_atomic_u32_t *atomic,
uint32_t value)
{
return __sync_sub_and_fetch(atomic, value);
}
static inline uint32_t od_atomic_u32_or(od_atomic_u32_t *atomic, uint32_t value)
{
return __sync_or_and_fetch(atomic, value);
}
static inline uint32_t od_atomic_u32_xor(od_atomic_u32_t *atomic,
uint32_t value)
{
return __sync_xor_and_fetch(atomic, value);
}
static inline uint64_t od_atomic_u64_of(od_atomic_u64_t *atomic)
{
return __sync_fetch_and_add(atomic, 0);
}
static inline uint64_t od_atomic_u64_inc(od_atomic_u64_t *atomic)
{
return __sync_fetch_and_add(atomic, 1);
}
static inline uint64_t od_atomic_u64_dec(od_atomic_u64_t *atomic)
{
return __sync_fetch_and_sub(atomic, 1);
}
static inline uint64_t od_atomic_u64_add(od_atomic_u64_t *atomic,
uint64_t value)
{
return __sync_add_and_fetch(atomic, value);
}
static inline uint64_t od_atomic_u64_sub(od_atomic_u64_t *atomic,
uint64_t value)
{
return __sync_sub_and_fetch(atomic, value);
}
static inline uint32_t od_atomic_u32_cas(od_atomic_u32_t *atomic,
uint32_t compValue, uint32_t exchValue)
{
return __sync_val_compare_and_swap(atomic, compValue, exchValue);
}
static inline uint64_t od_atomic_u64_cas(od_atomic_u64_t *atomic,
uint64_t compValue, uint64_t exchValue)
{
return __sync_val_compare_and_swap(atomic, compValue, exchValue);
}
#endif /* ODYSSEY_ATOMIC_H */