Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
233 lines (168 loc) · 7.71 KB

testatomic.c

File metadata and controls

233 lines (168 loc) · 7.71 KB
 
1
2
#include "SDL.h"
Jun 24, 2009
Jun 24, 2009
3
/*
Jun 29, 2009
Jun 29, 2009
4
5
Absolutely basic tests just to see if we get the expected value
after calling each function.
Jun 24, 2009
Jun 24, 2009
6
7
*/
Jun 29, 2009
Jun 29, 2009
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
Jun 10, 2009
Jun 10, 2009
23
main(int argc, char **argv)
Jun 10, 2009
Jun 10, 2009
25
Jul 9, 2009
Jul 9, 2009
26
volatile Uint8 val8 = 0;
Jun 29, 2009
Jun 29, 2009
27
28
Uint8 ret8 = 0;
Jul 9, 2009
Jul 9, 2009
29
volatile Uint16 val16 = 0;
Jun 29, 2009
Jun 29, 2009
30
31
Uint16 ret16 = 0;
Jul 9, 2009
Jul 9, 2009
32
volatile Uint32 val32 = 0;
Jun 24, 2009
Jun 24, 2009
33
34
Uint32 ret32 = 0;
Jul 9, 2009
Jul 9, 2009
35
volatile Uint64 val64 = 0;
Jun 24, 2009
Jun 24, 2009
36
37
Uint64 ret64 = 0;
Jun 29, 2009
Jun 29, 2009
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
SDL_bool tfret = SDL_FALSE;
printf("8 bit -----------------------------------------\n\n");
ret8 = SDL_AtomicExchange8(&val8, 10);
printf("Exchange8 ret=%d val=%d\n", ret8, val8);
ret8 = SDL_AtomicExchange8(&val8, 0);
printf("Exchange8 ret=%d val=%d\n", ret8, val8);
val8 = 10;
tfret = SDL_AtomicCompareThenSet8(&val8, 10, 20);
printf("CompareThenSet8 tfret=%s val=%d\n", tf(tfret), val8);
val8 = 10;
tfret = SDL_AtomicCompareThenSet8(&val8, 0, 20);
printf("CompareThenSet8 tfret=%s val=%d\n", tf(tfret), val8);
val8 = 0;
tfret = SDL_AtomicTestThenSet8(&val8);
printf("TestThenSet8 tfret=%s val=%d\n", tf(tfret), val8);
tfret = SDL_AtomicTestThenSet8(&val8);
printf("TestThenSet8 tfret=%s val=%d\n", tf(tfret), val8);
SDL_AtomicClear8(&val8);
printf("Clear8 val=%d\n", val8);
ret8 = SDL_AtomicFetchThenIncrement8(&val8);
printf("FetchThenIncrement8 ret=%d val=%d\n", ret8, val8);
ret8 = SDL_AtomicFetchThenDecrement8(&val8);
printf("FetchThenDecrement8 ret=%d val=%d\n", ret8, val8);
ret8 = SDL_AtomicFetchThenAdd8(&val8, 10);
printf("FetchThenAdd8 ret=%d val=%d\n", ret8, val8);
ret8 = SDL_AtomicFetchThenSubtract8(&val8, 10);
printf("FetchThenSubtract8 ret=%d val=%d\n", ret8, val8);
ret8 = SDL_AtomicIncrementThenFetch8(&val8);
printf("IncrementThenFetch8 ret=%d val=%d\n", ret8, val8);
ret8 = SDL_AtomicDecrementThenFetch8(&val8);
printf("DecrementThenFetch8 ret=%d val=%d\n", ret8, val8);
ret8 = SDL_AtomicAddThenFetch8(&val8, 10);
printf("AddThenFetch8 ret=%d val=%d\n", ret8, val8);
ret8 = SDL_AtomicSubtractThenFetch8(&val8, 10);
printf("SubtractThenFetch8 ret=%d val=%d\n", ret8, val8);
printf("16 bit -----------------------------------------\n\n");
ret16 = SDL_AtomicExchange16(&val16, 10);
printf("Exchange16 ret=%d val=%d\n", ret16, val16);
ret16 = SDL_AtomicExchange16(&val16, 0);
printf("Exchange16 ret=%d val=%d\n", ret16, val16);
val16 = 10;
tfret = SDL_AtomicCompareThenSet16(&val16, 10, 20);
printf("CompareThenSet16 tfret=%s val=%d\n", tf(tfret), val16);
val16 = 10;
tfret = SDL_AtomicCompareThenSet16(&val16, 0, 20);
printf("CompareThenSet16 tfret=%s val=%d\n", tf(tfret), val16);
val16 = 0;
tfret = SDL_AtomicTestThenSet16(&val16);
printf("TestThenSet16 tfret=%s val=%d\n", tf(tfret), val16);
tfret = SDL_AtomicTestThenSet16(&val16);
printf("TestThenSet16 tfret=%s val=%d\n", tf(tfret), val16);
SDL_AtomicClear16(&val16);
printf("Clear16 val=%d\n", val16);
ret16 = SDL_AtomicFetchThenIncrement16(&val16);
printf("FetchThenIncrement16 ret=%d val=%d\n", ret16, val16);
ret16 = SDL_AtomicFetchThenDecrement16(&val16);
printf("FetchThenDecrement16 ret=%d val=%d\n", ret16, val16);
ret16 = SDL_AtomicFetchThenAdd16(&val16, 10);
printf("FetchThenAdd16 ret=%d val=%d\n", ret16, val16);
ret16 = SDL_AtomicFetchThenSubtract16(&val16, 10);
printf("FetchThenSubtract16 ret=%d val=%d\n", ret16, val16);
ret16 = SDL_AtomicIncrementThenFetch16(&val16);
printf("IncrementThenFetch16 ret=%d val=%d\n", ret16, val16);
ret16 = SDL_AtomicDecrementThenFetch16(&val16);
printf("DecrementThenFetch16 ret=%d val=%d\n", ret16, val16);
ret16 = SDL_AtomicAddThenFetch16(&val16, 10);
printf("AddThenFetch16 ret=%d val=%d\n", ret16, val16);
ret16 = SDL_AtomicSubtractThenFetch16(&val16, 10);
printf("SubtractThenFetch16 ret=%d val=%d\n", ret16, val16);
printf("32 bit -----------------------------------------\n\n");
Jun 24, 2009
Jun 24, 2009
137
138
ret32 = SDL_AtomicExchange32(&val32, 10);
Jun 29, 2009
Jun 29, 2009
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
printf("Exchange32 ret=%d val=%d\n", ret32, val32);
ret32 = SDL_AtomicExchange32(&val32, 0);
printf("Exchange32 ret=%d val=%d\n", ret32, val32);
val32 = 10;
tfret = SDL_AtomicCompareThenSet32(&val32, 10, 20);
printf("CompareThenSet32 tfret=%s val=%d\n", tf(tfret), val32);
val32 = 10;
tfret = SDL_AtomicCompareThenSet32(&val32, 0, 20);
printf("CompareThenSet32 tfret=%s val=%d\n", tf(tfret), val32);
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);
Jun 24, 2009
Jun 24, 2009
156
SDL_AtomicClear32(&val32);
Jun 29, 2009
Jun 29, 2009
157
158
printf("Clear32 val=%d\n", val32);
Jun 24, 2009
Jun 24, 2009
159
ret32 = SDL_AtomicFetchThenIncrement32(&val32);
Jun 29, 2009
Jun 29, 2009
160
161
printf("FetchThenIncrement32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
162
ret32 = SDL_AtomicFetchThenDecrement32(&val32);
Jun 29, 2009
Jun 29, 2009
163
164
printf("FetchThenDecrement32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
165
ret32 = SDL_AtomicFetchThenAdd32(&val32, 10);
Jun 29, 2009
Jun 29, 2009
166
167
printf("FetchThenAdd32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
168
ret32 = SDL_AtomicFetchThenSubtract32(&val32, 10);
Jun 29, 2009
Jun 29, 2009
169
170
printf("FetchThenSubtract32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
171
ret32 = SDL_AtomicIncrementThenFetch32(&val32);
Jun 29, 2009
Jun 29, 2009
172
173
printf("IncrementThenFetch32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
174
ret32 = SDL_AtomicDecrementThenFetch32(&val32);
Jun 29, 2009
Jun 29, 2009
175
176
printf("DecrementThenFetch32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
177
ret32 = SDL_AtomicAddThenFetch32(&val32, 10);
Jun 29, 2009
Jun 29, 2009
178
179
printf("AddThenFetch32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
180
ret32 = SDL_AtomicSubtractThenFetch32(&val32, 10);
Jun 29, 2009
Jun 29, 2009
181
printf("SubtractThenFetch32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
182
Jun 29, 2009
Jun 29, 2009
183
184
#ifdef SDL_HAS_64BIT_TYPE
printf("64 bit -----------------------------------------\n\n");
Jun 24, 2009
Jun 24, 2009
185
186
ret64 = SDL_AtomicExchange64(&val64, 10);
Jun 29, 2009
Jun 29, 2009
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
printf("Exchange64 ret=%lld val=%lld\n", ret64, val64);
ret64 = SDL_AtomicExchange64(&val64, 0);
printf("Exchange64 ret=%lld val=%lld\n", ret64, val64);
val64 = 10;
tfret = SDL_AtomicCompareThenSet64(&val64, 10, 20);
printf("CompareThenSet64 tfret=%s val=%lld\n", tf(tfret), val64);
val64 = 10;
tfret = SDL_AtomicCompareThenSet64(&val64, 0, 20);
printf("CompareThenSet64 tfret=%s val=%lld\n", tf(tfret), val64);
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);
Jun 24, 2009
Jun 24, 2009
204
SDL_AtomicClear64(&val64);
Jun 29, 2009
Jun 29, 2009
205
206
printf("Clear64 val=%lld\n", val64);
Jun 24, 2009
Jun 24, 2009
207
ret64 = SDL_AtomicFetchThenIncrement64(&val64);
Jun 29, 2009
Jun 29, 2009
208
209
printf("FetchThenIncrement64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
210
ret64 = SDL_AtomicFetchThenDecrement64(&val64);
Jun 29, 2009
Jun 29, 2009
211
212
printf("FetchThenDecrement64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
213
ret64 = SDL_AtomicFetchThenAdd64(&val64, 10);
Jun 29, 2009
Jun 29, 2009
214
215
printf("FetchThenAdd64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
216
ret64 = SDL_AtomicFetchThenSubtract64(&val64, 10);
Jun 29, 2009
Jun 29, 2009
217
218
printf("FetchThenSubtract64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
219
ret64 = SDL_AtomicIncrementThenFetch64(&val64);
Jun 29, 2009
Jun 29, 2009
220
221
printf("IncrementThenFetch64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
222
ret64 = SDL_AtomicDecrementThenFetch64(&val64);
Jun 29, 2009
Jun 29, 2009
223
224
printf("DecrementThenFetch64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
225
ret64 = SDL_AtomicAddThenFetch64(&val64, 10);
Jun 29, 2009
Jun 29, 2009
226
227
printf("AddThenFetch64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
228
ret64 = SDL_AtomicSubtractThenFetch64(&val64, 10);
Jun 29, 2009
Jun 29, 2009
229
printf("SubtractThenFetch64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
230
231
232
233
#endif
return 0;
}