Mercurial > sdl-ios-xcode
annotate test/testatomic.c @ 5006:8e8876e4aec6
Include windows.h in SDL_atomic.h by default, but don't include the atomic API in SDL.h
This allows all SDL code to take advantage of the atomic intrinsics on Windows, but doesn't cause applications just including SDL.h to pull in windows.h
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 16 Jan 2011 17:45:42 -0800 |
parents | 0c72ae7b7cb2 |
children | 9d6b527e0912 |
rev | line source |
---|---|
3338 | 1 #include <stdio.h> |
5006
8e8876e4aec6
Include windows.h in SDL_atomic.h by default, but don't include the atomic API in SDL.h
Sam Lantinga <slouken@libsdl.org>
parents:
5004
diff
changeset
|
2 |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
3 #include "SDL.h" |
5006
8e8876e4aec6
Include windows.h in SDL_atomic.h by default, but don't include the atomic API in SDL.h
Sam Lantinga <slouken@libsdl.org>
parents:
5004
diff
changeset
|
4 #include "SDL_atomic.h" |
5004
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
5 #include "SDL_assert.h" |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
6 |
3201
c297230efc75
Disabling 64 bit atomics operations until I figure out why they do not link.
Bob Pendleton <bob@pendleton.com>
parents:
3199
diff
changeset
|
7 /* |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
8 Absolutely basic tests just to see if we get the expected value |
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
9 after calling each function. |
3201
c297230efc75
Disabling 64 bit atomics operations until I figure out why they do not link.
Bob Pendleton <bob@pendleton.com>
parents:
3199
diff
changeset
|
10 */ |
c297230efc75
Disabling 64 bit atomics operations until I figure out why they do not link.
Bob Pendleton <bob@pendleton.com>
parents:
3199
diff
changeset
|
11 |
5004
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
12 static |
3338 | 13 char * |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
14 tf(SDL_bool tf) |
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
15 { |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
16 static char *t = "TRUE"; |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
17 static char *f = "FALSE"; |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
18 |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
19 if (tf) |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
20 { |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
21 return t; |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
22 } |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
23 |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
24 return f; |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
25 } |
3338 | 26 |
5004
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
27 static |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
28 void RunBasicTest() |
3180
77d6336711fc
First commit for SDL atomic operations.
Bob Pendleton <bob@pendleton.com>
parents:
diff
changeset
|
29 { |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
30 int value; |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
31 SDL_SpinLock lock = 0; |
3261
72b542f34739
The new, cleaner, version of the atomic operations. The dummy code is what you should start working with to port atomic ops.
Bob Pendleton <bob@pendleton.com>
parents:
3237
diff
changeset
|
32 |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
33 SDL_bool tfret = SDL_FALSE; |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
34 |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
35 printf("\nspin lock---------------------------------------\n\n"); |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
36 |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
37 SDL_AtomicLock(&lock); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
38 printf("AtomicLock lock=%d\n", lock); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
39 SDL_AtomicUnlock(&lock); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
40 printf("AtomicUnlock lock=%d\n", lock); |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
41 |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
42 printf("\natomic -----------------------------------------\n\n"); |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
43 |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
44 SDL_atomic_t v; |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
45 |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
46 SDL_AtomicSet(&v, 0); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
47 tfret = SDL_AtomicSet(&v, 10) == 0; |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
48 printf("AtomicSet(10) tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
49 tfret = SDL_AtomicAdd(&v, 10) == 10; |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
50 printf("AtomicAdd(10) tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
51 |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
52 SDL_AtomicSet(&v, 0); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
53 SDL_AtomicIncRef(&v); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
54 tfret = (SDL_AtomicGet(&v) == 1); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
55 printf("AtomicIncRef() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
56 SDL_AtomicIncRef(&v); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
57 tfret = (SDL_AtomicGet(&v) == 2); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
58 printf("AtomicIncRef() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
59 tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
60 printf("AtomicDecRef() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
61 tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
62 printf("AtomicDecRef() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
63 |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
64 SDL_AtomicSet(&v, 10); |
5004
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
65 tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE); |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
66 printf("AtomicCAS() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
67 value = SDL_AtomicGet(&v); |
5004
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
68 tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE); |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
69 printf("AtomicCAS() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); |
5004
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
70 } |
3202
3aa519a5c676
I've made so many changes I don't dare continue until I check the current stuff in.
Bob Pendleton <bob@pendleton.com>
parents:
3201
diff
changeset
|
71 |
5004
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
72 /* Atomic operation test, adapted from code by Michael Davidsaver at: |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
73 http://bazaar.launchpad.net/~mdavidsaver/epics-base/atomic/revision/12105#src/libCom/test/epicsAtomicTest.c |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
74 */ |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
75 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
76 /* Tests semantics of atomic operations. Also a stress test |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
77 * to see if they are really atomic. |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
78 * |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
79 * Serveral threads adding to the same variable. |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
80 * at the end the value is compared with the expected |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
81 * and with a non-atomic counter. |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
82 */ |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
83 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
84 /* Number of concurrent incrementers */ |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
85 #define NThreads 2 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
86 #define CountInc 100 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
87 #define VALBITS (sizeof(atomicValue)*8) |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
88 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
89 #define atomicValue int |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
90 #define CountTo ((atomicValue)((unsigned int)(1<<(VALBITS-1))-1)) |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
91 #define NInter (CountTo/CountInc/NThreads) |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
92 #define Expect (CountTo-NInter*CountInc*NThreads) |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
93 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
94 SDL_COMPILE_TIME_ASSERT(size, CountTo>0); /* check for rollover */ |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
95 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
96 static SDL_atomic_t good = { 42 }; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
97 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
98 static atomicValue bad = 42; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
99 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
100 static SDL_atomic_t threadsRunning; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
101 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
102 static SDL_sem *threadDone; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
103 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
104 static |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
105 int adder(void* junk) |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
106 { |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
107 unsigned long N=NInter; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
108 printf("Thread subtracting %d %lu times\n",CountInc,N); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
109 while (N--) { |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
110 SDL_AtomicAdd(&good, -CountInc); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
111 bad-=CountInc; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
112 } |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
113 SDL_AtomicAdd(&threadsRunning, -1); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
114 SDL_SemPost(threadDone); |
5003
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
115 return 0; |
3a95a2b93eb3
Updated the atomic API for better use cases
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
116 } |
5004
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
117 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
118 static |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
119 void runAdder(void) |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
120 { |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
121 Uint32 start, end; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
122 int T=NThreads; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
123 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
124 start = SDL_GetTicks(); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
125 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
126 threadDone = SDL_CreateSemaphore(0); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
127 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
128 SDL_AtomicSet(&threadsRunning, NThreads); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
129 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
130 while (T--) |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
131 SDL_CreateThread(adder, NULL); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
132 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
133 while (SDL_AtomicGet(&threadsRunning) > 0) |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
134 SDL_SemWait(threadDone); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
135 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
136 SDL_DestroySemaphore(threadDone); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
137 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
138 end = SDL_GetTicks(); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
139 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
140 printf("Finished in %f sec\n", (end - start) / 1000.f); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
141 } |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
142 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
143 static |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
144 void RunEpicTest() |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
145 { |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
146 int b; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
147 atomicValue v; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
148 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
149 printf("\nepic test---------------------------------------\n\n"); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
150 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
151 printf("Size asserted to be >= 32-bit\n"); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
152 SDL_assert(sizeof(atomicValue)>=4); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
153 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
154 printf("Check static initializer\n"); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
155 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
156 SDL_assert(v==42); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
157 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
158 SDL_assert(bad==42); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
159 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
160 printf("Test negative values\n"); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
161 SDL_AtomicSet(&good, -5); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
162 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
163 SDL_assert(v==-5); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
164 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
165 printf("Verify maximum value\n"); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
166 SDL_AtomicSet(&good, CountTo); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
167 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
168 SDL_assert(v==CountTo); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
169 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
170 printf("Test compare and exchange\n"); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
171 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
172 b=SDL_AtomicCAS(&good, 500, 43); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
173 SDL_assert(!b); /* no swap since CountTo!=500 */ |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
174 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
175 SDL_assert(v==CountTo); /* ensure no swap */ |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
176 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
177 b=SDL_AtomicCAS(&good, CountTo, 44); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
178 SDL_assert(!!b); /* will swap */ |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
179 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
180 SDL_assert(v==44); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
181 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
182 printf("Test Add\n"); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
183 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
184 v=SDL_AtomicAdd(&good, 1); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
185 SDL_assert(v==44); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
186 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
187 SDL_assert(v==45); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
188 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
189 v=SDL_AtomicAdd(&good, 10); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
190 SDL_assert(v==45); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
191 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
192 SDL_assert(v==55); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
193 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
194 printf("Test Add (Negative values)\n"); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
195 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
196 v=SDL_AtomicAdd(&good, -20); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
197 SDL_assert(v==55); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
198 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
199 SDL_assert(v==35); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
200 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
201 v=SDL_AtomicAdd(&good, -50); /* crossing zero down */ |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
202 SDL_assert(v==35); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
203 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
204 SDL_assert(v==-15); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
205 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
206 v=SDL_AtomicAdd(&good, 30); /* crossing zero up */ |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
207 SDL_assert(v==-15); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
208 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
209 SDL_assert(v==15); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
210 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
211 printf("Reset before count down test\n"); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
212 SDL_AtomicSet(&good, CountTo); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
213 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
214 SDL_assert(v==CountTo); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
215 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
216 bad=CountTo; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
217 SDL_assert(bad==CountTo); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
218 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
219 printf("Counting down from %d, Expect %d remaining\n",CountTo,Expect); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
220 runAdder(); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
221 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
222 v=SDL_AtomicGet(&good); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
223 printf("Atomic %d Non-Atomic %d\n",v,bad); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
224 SDL_assert(v==Expect); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
225 SDL_assert(bad!=Expect); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
226 } |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
227 |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
228 int |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
229 main(int argc, char *argv[]) |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
230 { |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
231 RunBasicTest(); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
232 RunEpicTest(); |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
233 return 0; |
0c72ae7b7cb2
Added native atomic operations for Windows, Mac OS X, and gcc compiler intrinsics.
Sam Lantinga <slouken@libsdl.org>
parents:
5003
diff
changeset
|
234 } |