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

Latest commit

 

History

History
116 lines (82 loc) · 3.38 KB

testatomic.c

File metadata and controls

116 lines (82 loc) · 3.38 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 Uint32 val32 = 0;
Jun 24, 2009
Jun 24, 2009
27
28
Uint32 ret32 = 0;
Jul 9, 2009
Jul 9, 2009
29
volatile Uint64 val64 = 0;
Jun 24, 2009
Jun 24, 2009
30
31
Uint64 ret64 = 0;
Sep 17, 2009
Sep 17, 2009
32
33
SDL_SpinLock lock = 0;
Jun 29, 2009
Jun 29, 2009
34
35
SDL_bool tfret = SDL_FALSE;
Sep 17, 2009
Sep 17, 2009
36
printf("\nspin lock---------------------------------------\n\n");
Jun 24, 2009
Jun 24, 2009
37
Sep 17, 2009
Sep 17, 2009
38
39
40
41
SDL_AtomicLock(&lock);
printf("AtomicLock lock=%d\n", lock);
SDL_AtomicUnlock(&lock);
printf("AtomicUnlock lock=%d\n", lock);
Jun 29, 2009
Jun 29, 2009
42
Sep 17, 2009
Sep 17, 2009
43
printf("\n32 bit -----------------------------------------\n\n");
Jun 29, 2009
Jun 29, 2009
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);
Jun 24, 2009
Jun 24, 2009
51
SDL_AtomicClear32(&val32);
Jun 29, 2009
Jun 29, 2009
52
53
printf("Clear32 val=%d\n", val32);
Jun 24, 2009
Jun 24, 2009
54
ret32 = SDL_AtomicFetchThenIncrement32(&val32);
Jun 29, 2009
Jun 29, 2009
55
56
printf("FetchThenIncrement32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
57
ret32 = SDL_AtomicFetchThenDecrement32(&val32);
Jun 29, 2009
Jun 29, 2009
58
59
printf("FetchThenDecrement32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
60
ret32 = SDL_AtomicFetchThenAdd32(&val32, 10);
Jun 29, 2009
Jun 29, 2009
61
62
printf("FetchThenAdd32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
63
ret32 = SDL_AtomicFetchThenSubtract32(&val32, 10);
Jun 29, 2009
Jun 29, 2009
64
65
printf("FetchThenSubtract32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
66
ret32 = SDL_AtomicIncrementThenFetch32(&val32);
Jun 29, 2009
Jun 29, 2009
67
68
printf("IncrementThenFetch32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
69
ret32 = SDL_AtomicDecrementThenFetch32(&val32);
Jun 29, 2009
Jun 29, 2009
70
71
printf("DecrementThenFetch32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
72
ret32 = SDL_AtomicAddThenFetch32(&val32, 10);
Jun 29, 2009
Jun 29, 2009
73
74
printf("AddThenFetch32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
75
ret32 = SDL_AtomicSubtractThenFetch32(&val32, 10);
Jun 29, 2009
Jun 29, 2009
76
printf("SubtractThenFetch32 ret=%d val=%d\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
77
Jun 29, 2009
Jun 29, 2009
78
#ifdef SDL_HAS_64BIT_TYPE
Sep 17, 2009
Sep 17, 2009
79
printf("\n64 bit -----------------------------------------\n\n");
Jun 29, 2009
Jun 29, 2009
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);
Jun 24, 2009
Jun 24, 2009
87
SDL_AtomicClear64(&val64);
Jun 29, 2009
Jun 29, 2009
88
89
printf("Clear64 val=%lld\n", val64);
Jun 24, 2009
Jun 24, 2009
90
ret64 = SDL_AtomicFetchThenIncrement64(&val64);
Jun 29, 2009
Jun 29, 2009
91
92
printf("FetchThenIncrement64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
93
ret64 = SDL_AtomicFetchThenDecrement64(&val64);
Jun 29, 2009
Jun 29, 2009
94
95
printf("FetchThenDecrement64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
96
ret64 = SDL_AtomicFetchThenAdd64(&val64, 10);
Jun 29, 2009
Jun 29, 2009
97
98
printf("FetchThenAdd64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
99
ret64 = SDL_AtomicFetchThenSubtract64(&val64, 10);
Jun 29, 2009
Jun 29, 2009
100
101
printf("FetchThenSubtract64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
102
ret64 = SDL_AtomicIncrementThenFetch64(&val64);
Jun 29, 2009
Jun 29, 2009
103
104
printf("IncrementThenFetch64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
105
ret64 = SDL_AtomicDecrementThenFetch64(&val64);
Jun 29, 2009
Jun 29, 2009
106
107
printf("DecrementThenFetch64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
108
ret64 = SDL_AtomicAddThenFetch64(&val64, 10);
Jun 29, 2009
Jun 29, 2009
109
110
printf("AddThenFetch64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
111
ret64 = SDL_AtomicSubtractThenFetch64(&val64, 10);
Jun 29, 2009
Jun 29, 2009
112
printf("SubtractThenFetch64 ret=%lld val=%lld\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
113
114
115
116
#endif
return 0;
}