This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
testatomic.c
116 lines (82 loc) · 3.38 KB
1
2
#include "SDL.h"
3
/*
4
5
Absolutely basic tests just to see if we get the expected value
after calling each function.
6
7
*/
8
9
10
11
12
13
14
15
16
17
18
19
20
21
char *
tf(SDL_bool tf)
{
static char *t = "true";
static char *f = "false";
if (tf)
{
return t;
}
return f;
}
22
int
23
main(int argc, char **argv)
24
{
25
26
volatile Uint32 val32 = 0;
27
28
Uint32 ret32 = 0;
29
volatile Uint64 val64 = 0;
30
31
Uint64 ret64 = 0;
32
33
SDL_SpinLock lock = 0;
34
35
SDL_bool tfret = SDL_FALSE;
36
printf("\nspin lock---------------------------------------\n\n");
37
38
39
40
41
SDL_AtomicLock(&lock);
printf("AtomicLock lock=%d\n", lock);
SDL_AtomicUnlock(&lock);
printf("AtomicUnlock lock=%d\n", lock);
42
43
printf("\n32 bit -----------------------------------------\n\n");
44
45
46
47
48
49
50
val32 = 0;
tfret = SDL_AtomicTestThenSet32(&val32);
printf("TestThenSet32 tfret=%s val=%d\n", tf(tfret), val32);
tfret = SDL_AtomicTestThenSet32(&val32);
printf("TestThenSet32 tfret=%s val=%d\n", tf(tfret), val32);
51
SDL_AtomicClear32(&val32);
52
53
printf("Clear32 val=%d\n", val32);
54
ret32 = SDL_AtomicFetchThenIncrement32(&val32);
55
56
printf("FetchThenIncrement32 ret=%d val=%d\n", ret32, val32);
57
ret32 = SDL_AtomicFetchThenDecrement32(&val32);
58
59
printf("FetchThenDecrement32 ret=%d val=%d\n", ret32, val32);
60
ret32 = SDL_AtomicFetchThenAdd32(&val32, 10);
61
62
printf("FetchThenAdd32 ret=%d val=%d\n", ret32, val32);
63
ret32 = SDL_AtomicFetchThenSubtract32(&val32, 10);
64
65
printf("FetchThenSubtract32 ret=%d val=%d\n", ret32, val32);
66
ret32 = SDL_AtomicIncrementThenFetch32(&val32);
67
68
printf("IncrementThenFetch32 ret=%d val=%d\n", ret32, val32);
69
ret32 = SDL_AtomicDecrementThenFetch32(&val32);
70
71
printf("DecrementThenFetch32 ret=%d val=%d\n", ret32, val32);
72
ret32 = SDL_AtomicAddThenFetch32(&val32, 10);
73
74
printf("AddThenFetch32 ret=%d val=%d\n", ret32, val32);
75
ret32 = SDL_AtomicSubtractThenFetch32(&val32, 10);
76
printf("SubtractThenFetch32 ret=%d val=%d\n", ret32, val32);
77
78
#ifdef SDL_HAS_64BIT_TYPE
79
printf("\n64 bit -----------------------------------------\n\n");
80
81
82
83
84
85
86
val64 = 0;
tfret = SDL_AtomicTestThenSet64(&val64);
printf("TestThenSet64 tfret=%s val=%lld\n", tf(tfret), val64);
tfret = SDL_AtomicTestThenSet64(&val64);
printf("TestThenSet64 tfret=%s val=%lld\n", tf(tfret), val64);
87
SDL_AtomicClear64(&val64);
88
89
printf("Clear64 val=%lld\n", val64);
90
ret64 = SDL_AtomicFetchThenIncrement64(&val64);
91
92
printf("FetchThenIncrement64 ret=%lld val=%lld\n", ret64, val64);
93
ret64 = SDL_AtomicFetchThenDecrement64(&val64);
94
95
printf("FetchThenDecrement64 ret=%lld val=%lld\n", ret64, val64);
96
ret64 = SDL_AtomicFetchThenAdd64(&val64, 10);
97
98
printf("FetchThenAdd64 ret=%lld val=%lld\n", ret64, val64);
99
ret64 = SDL_AtomicFetchThenSubtract64(&val64, 10);
100
101
printf("FetchThenSubtract64 ret=%lld val=%lld\n", ret64, val64);
102
ret64 = SDL_AtomicIncrementThenFetch64(&val64);
103
104
printf("IncrementThenFetch64 ret=%lld val=%lld\n", ret64, val64);
105
ret64 = SDL_AtomicDecrementThenFetch64(&val64);
106
107
printf("DecrementThenFetch64 ret=%lld val=%lld\n", ret64, val64);
108
ret64 = SDL_AtomicAddThenFetch64(&val64, 10);
109
110
printf("AddThenFetch64 ret=%lld val=%lld\n", ret64, val64);
111
ret64 = SDL_AtomicSubtractThenFetch64(&val64, 10);
112
printf("SubtractThenFetch64 ret=%lld val=%lld\n", ret64, val64);
113
114
115
116
#endif
return 0;
}