-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathTHAtomic.h
60 lines (47 loc) · 1.38 KB
/
THAtomic.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
#ifndef TH_ATOMIC_INC
#define TH_ATOMIC_INC
#include "THGeneral.h"
/******************************************************************************
* Atomic operations for TH
* Five backends are integrated:
* - C11 atomic operations
* - MSVC intrinsics
* - GCC intrinsics
* - Pthread if none of the above is available
* - Unsafe mode in none of the above is available
******************************************************************************/
/******************************************************************************
* all-purpose functions
******************************************************************************/
/*
* *a = newvalue
*/
void THAtomicSet(int volatile *a, int newvalue);
/*
* return *a
*/
int THAtomicGet(int volatile *a);
/*
* *a += value,
* return previous *a
*/
int THAtomicAdd(int volatile *a, int value);
/*
* check if (*a == oldvalue)
* if true: set *a to newvalue, return 1
* if false: return 0
*/
int THAtomicCompareAndSwap(int volatile *a, int oldvalue, int newvalue);
/******************************************************************************
* refcounting functions
******************************************************************************/
/*
* *a++
*/
void THAtomicIncrementRef(int volatile *a);
/*
* *a--,
* return 1 if *a == 0 after the operation, 0 otherwise
*/
int THAtomicDecrementRef(int volatile *a);
#endif