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

Latest commit

 

History

History
129 lines (94 loc) · 3.82 KB

testatomic.c

File metadata and controls

129 lines (94 loc) · 3.82 KB
 
Oct 4, 2009
Oct 4, 2009
1
#include <stdio.h>
2
3
#include "SDL.h"
Sep 29, 2009
Sep 29, 2009
4
5
6
7
8
9
10
11
12
13
14
15
/* Make sure we have good macros for printing 32 and 64 bit values */
#ifndef PRIu32
#define PRIu32 "u"
#endif
#ifndef PRIu64
#ifdef __WIN32__
#define PRIu64 "I64u"
#else
#define PRIu64 "llu"
#endif
#endif
Jun 24, 2009
Jun 24, 2009
16
/*
Jun 29, 2009
Jun 29, 2009
17
18
Absolutely basic tests just to see if we get the expected value
after calling each function.
Jun 24, 2009
Jun 24, 2009
19
20
*/
Oct 4, 2009
Oct 4, 2009
21
char *
Jun 29, 2009
Jun 29, 2009
22
23
24
25
26
27
28
29
30
31
32
33
tf(SDL_bool tf)
{
static char *t = "true";
static char *f = "false";
if (tf)
{
return t;
}
return f;
}
Oct 4, 2009
Oct 4, 2009
34
35
int
Sep 23, 2009
Sep 23, 2009
36
main(int argc, char *argv[])
Jun 10, 2009
Jun 10, 2009
38
Jul 9, 2009
Jul 9, 2009
39
volatile Uint32 val32 = 0;
Jun 24, 2009
Jun 24, 2009
40
41
Uint32 ret32 = 0;
Jul 9, 2009
Jul 9, 2009
42
volatile Uint64 val64 = 0;
Jun 24, 2009
Jun 24, 2009
43
44
Uint64 ret64 = 0;
Sep 17, 2009
Sep 17, 2009
45
46
SDL_SpinLock lock = 0;
Jun 29, 2009
Jun 29, 2009
47
48
SDL_bool tfret = SDL_FALSE;
Sep 17, 2009
Sep 17, 2009
49
printf("\nspin lock---------------------------------------\n\n");
Jun 24, 2009
Jun 24, 2009
50
Sep 17, 2009
Sep 17, 2009
51
52
53
54
SDL_AtomicLock(&lock);
printf("AtomicLock lock=%d\n", lock);
SDL_AtomicUnlock(&lock);
printf("AtomicUnlock lock=%d\n", lock);
Jun 29, 2009
Jun 29, 2009
55
Sep 17, 2009
Sep 17, 2009
56
printf("\n32 bit -----------------------------------------\n\n");
Jun 29, 2009
Jun 29, 2009
57
58
59
val32 = 0;
tfret = SDL_AtomicTestThenSet32(&val32);
Sep 29, 2009
Sep 29, 2009
60
printf("TestThenSet32 tfret=%s val=%"PRIu32"\n", tf(tfret), val32);
Jun 29, 2009
Jun 29, 2009
61
tfret = SDL_AtomicTestThenSet32(&val32);
Sep 29, 2009
Sep 29, 2009
62
printf("TestThenSet32 tfret=%s val=%"PRIu32"\n", tf(tfret), val32);
Jun 29, 2009
Jun 29, 2009
63
Jun 24, 2009
Jun 24, 2009
64
SDL_AtomicClear32(&val32);
Sep 29, 2009
Sep 29, 2009
65
printf("Clear32 val=%"PRIu32"\n", val32);
Jun 29, 2009
Jun 29, 2009
66
Jun 24, 2009
Jun 24, 2009
67
ret32 = SDL_AtomicFetchThenIncrement32(&val32);
Sep 29, 2009
Sep 29, 2009
68
printf("FetchThenIncrement32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
Jun 29, 2009
Jun 29, 2009
69
Jun 24, 2009
Jun 24, 2009
70
ret32 = SDL_AtomicFetchThenDecrement32(&val32);
Sep 29, 2009
Sep 29, 2009
71
printf("FetchThenDecrement32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
Jun 29, 2009
Jun 29, 2009
72
Jun 24, 2009
Jun 24, 2009
73
ret32 = SDL_AtomicFetchThenAdd32(&val32, 10);
Sep 29, 2009
Sep 29, 2009
74
printf("FetchThenAdd32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
Jun 29, 2009
Jun 29, 2009
75
Jun 24, 2009
Jun 24, 2009
76
ret32 = SDL_AtomicFetchThenSubtract32(&val32, 10);
Sep 29, 2009
Sep 29, 2009
77
printf("FetchThenSubtract32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
Jun 29, 2009
Jun 29, 2009
78
Jun 24, 2009
Jun 24, 2009
79
ret32 = SDL_AtomicIncrementThenFetch32(&val32);
Sep 29, 2009
Sep 29, 2009
80
printf("IncrementThenFetch32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
Jun 29, 2009
Jun 29, 2009
81
Jun 24, 2009
Jun 24, 2009
82
ret32 = SDL_AtomicDecrementThenFetch32(&val32);
Sep 29, 2009
Sep 29, 2009
83
printf("DecrementThenFetch32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
Jun 29, 2009
Jun 29, 2009
84
Jun 24, 2009
Jun 24, 2009
85
ret32 = SDL_AtomicAddThenFetch32(&val32, 10);
Sep 29, 2009
Sep 29, 2009
86
printf("AddThenFetch32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
Jun 29, 2009
Jun 29, 2009
87
Jun 24, 2009
Jun 24, 2009
88
ret32 = SDL_AtomicSubtractThenFetch32(&val32, 10);
Sep 29, 2009
Sep 29, 2009
89
printf("SubtractThenFetch32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
Jun 24, 2009
Jun 24, 2009
90
Jun 29, 2009
Jun 29, 2009
91
#ifdef SDL_HAS_64BIT_TYPE
Sep 17, 2009
Sep 17, 2009
92
printf("\n64 bit -----------------------------------------\n\n");
Jun 29, 2009
Jun 29, 2009
93
94
95
val64 = 0;
tfret = SDL_AtomicTestThenSet64(&val64);
Sep 29, 2009
Sep 29, 2009
96
printf("TestThenSet64 tfret=%s val=%"PRIu64"\n", tf(tfret), val64);
Jun 29, 2009
Jun 29, 2009
97
tfret = SDL_AtomicTestThenSet64(&val64);
Sep 29, 2009
Sep 29, 2009
98
printf("TestThenSet64 tfret=%s val=%"PRIu64"\n", tf(tfret), val64);
Jun 29, 2009
Jun 29, 2009
99
Jun 24, 2009
Jun 24, 2009
100
SDL_AtomicClear64(&val64);
Sep 29, 2009
Sep 29, 2009
101
printf("Clear64 val=%"PRIu64"\n", val64);
Jun 29, 2009
Jun 29, 2009
102
Jun 24, 2009
Jun 24, 2009
103
ret64 = SDL_AtomicFetchThenIncrement64(&val64);
Sep 29, 2009
Sep 29, 2009
104
printf("FetchThenIncrement64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
Jun 29, 2009
Jun 29, 2009
105
Jun 24, 2009
Jun 24, 2009
106
ret64 = SDL_AtomicFetchThenDecrement64(&val64);
Sep 29, 2009
Sep 29, 2009
107
printf("FetchThenDecrement64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
Jun 29, 2009
Jun 29, 2009
108
Jun 24, 2009
Jun 24, 2009
109
ret64 = SDL_AtomicFetchThenAdd64(&val64, 10);
Sep 29, 2009
Sep 29, 2009
110
printf("FetchThenAdd64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
Jun 29, 2009
Jun 29, 2009
111
Jun 24, 2009
Jun 24, 2009
112
ret64 = SDL_AtomicFetchThenSubtract64(&val64, 10);
Sep 29, 2009
Sep 29, 2009
113
printf("FetchThenSubtract64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
Jun 29, 2009
Jun 29, 2009
114
Jun 24, 2009
Jun 24, 2009
115
ret64 = SDL_AtomicIncrementThenFetch64(&val64);
Sep 29, 2009
Sep 29, 2009
116
printf("IncrementThenFetch64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
Jun 29, 2009
Jun 29, 2009
117
Jun 24, 2009
Jun 24, 2009
118
ret64 = SDL_AtomicDecrementThenFetch64(&val64);
Sep 29, 2009
Sep 29, 2009
119
printf("DecrementThenFetch64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
Jun 29, 2009
Jun 29, 2009
120
Jun 24, 2009
Jun 24, 2009
121
ret64 = SDL_AtomicAddThenFetch64(&val64, 10);
Sep 29, 2009
Sep 29, 2009
122
printf("AddThenFetch64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
Jun 29, 2009
Jun 29, 2009
123
Jun 24, 2009
Jun 24, 2009
124
ret64 = SDL_AtomicSubtractThenFetch64(&val64, 10);
Sep 29, 2009
Sep 29, 2009
125
printf("SubtractThenFetch64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
Jun 24, 2009
Jun 24, 2009
126
127
128
129
#endif
return 0;
}