Mercurial > sdl-ios-xcode
comparison src/atomic/linux/SDL_atomic.c @ 3200:ef2c029a3a9d
First draft of atomic operations code for GCC and linux.
author | Bob Pendleton <bob@pendleton.com> |
---|---|
date | Wed, 24 Jun 2009 20:20:57 +0000 |
parents | 3e1bf2b8bd81 |
children | c297230efc75 |
comparison
equal
deleted
inserted
replaced
3199:3e1bf2b8bd81 | 3200:ef2c029a3a9d |
---|---|
27 #include "SDL_atomic.h" | 27 #include "SDL_atomic.h" |
28 | 28 |
29 Uint32 | 29 Uint32 |
30 SDL_AtomicExchange32(Uint32 * ptr, Uint32 value) | 30 SDL_AtomicExchange32(Uint32 * ptr, Uint32 value) |
31 { | 31 { |
32 return 0; | 32 return __sync_lock_test_and_set(ptr, value); |
33 } | 33 } |
34 | 34 |
35 SDL_bool | 35 SDL_bool |
36 SDL_AtomicCompareThenSet32(Uint32 * ptr, Uint32 oldvalue, Uint32 newvalue) | 36 SDL_AtomicCompareThenSet32(Uint32 * ptr, Uint32 oldvalue, Uint32 newvalue) |
37 { | 37 { |
38 return SDL_false; | 38 return (SDL_bool)__sync_bool_compare_and_swap(ptr, oldvalue, newvalue); |
39 } | 39 } |
40 | 40 |
41 SDL_bool | 41 SDL_bool |
42 SDL_AtomicTestThenSet32(Uint32 * ptr) | 42 SDL_AtomicTestThenSet32(Uint32 * ptr) |
43 { | 43 { |
44 return SDL_false; | 44 return (SDL_bool)(0 == __sync_lock_test_and_set(ptr, 1)); |
45 } | 45 } |
46 | 46 |
47 void | 47 void |
48 SDL_AtomicClear32(Uint32 * ptr) | 48 SDL_AtomicClear32(Uint32 * ptr) |
49 { | 49 { |
50 __sync_lock_release(ptr); | |
50 } | 51 } |
51 | 52 |
52 Uint32 | 53 Uint32 |
53 SDL_AtomicFetchThenIncrement32(Uint32 * ptr) | 54 SDL_AtomicFetchThenIncrement32(Uint32 * ptr) |
54 { | 55 { |
55 return 0; | 56 return __sync_fetch_and_add(ptr, 1); |
56 } | 57 } |
57 | 58 |
58 Uint32 | 59 Uint32 |
59 SDL_AtomicFetchThenDecrement32(Uint32 * ptr) | 60 SDL_AtomicFetchThenDecrement32(Uint32 * ptr) |
60 { | 61 { |
61 return 0; | 62 return __sync_fetch_and_sub(ptr, 1); |
62 } | 63 } |
63 | 64 |
64 Uint32 | 65 Uint32 |
65 SDL_AtomicFetchThenAdd32(Uint32 * ptr, Uint32 value) | 66 SDL_AtomicFetchThenAdd32(Uint32 * ptr, Uint32 value) |
66 { | 67 { |
67 return 0; | 68 return __sync_fetch_and_add(ptr, value); |
68 } | 69 } |
69 | 70 |
70 Uint32 | 71 Uint32 |
71 SDL_AtomicFetchThenSubtract32(Uint32 * ptr, Uint32 value) | 72 SDL_AtomicFetchThenSubtract32(Uint32 * ptr, Uint32 value) |
72 { | 73 { |
73 return 0; | 74 return __sync_fetch_and_sub(ptr, value); |
74 } | 75 } |
75 | 76 |
76 Uint32 | 77 Uint32 |
77 SDL_AtomicIncrementThenFetch32(Uint32 * ptr) | 78 SDL_AtomicIncrementThenFetch32(Uint32 * ptr) |
78 { | 79 { |
79 return 0; | 80 return __sync_add_and_fetch(ptr, 1); |
80 } | 81 } |
81 | 82 |
82 Uint32 | 83 Uint32 |
83 SDL_AtomicDecrementThenFetch32(Uint32 * ptr) | 84 SDL_AtomicDecrementThenFetch32(Uint32 * ptr) |
84 { | 85 { |
85 return 0; | 86 return __sync_sub_and_fetch(ptr, 1); |
86 } | 87 } |
87 | 88 |
88 Uint32 | 89 Uint32 |
89 SDL_AtomicAddThenFetch32(Uint32 * ptr, Uint32 value) | 90 SDL_AtomicAddThenFetch32(Uint32 * ptr, Uint32 value) |
90 { | 91 { |
91 return 0; | 92 return __sync_add_and_fetch(ptr, value); |
92 } | 93 } |
93 | 94 |
94 Uint32 | 95 Uint32 |
95 SDL_AtomicSubtractThenFetch32(Uint32 * ptr, Uint32 value) | 96 SDL_AtomicSubtractThenFetch32(Uint32 * ptr, Uint32 value) |
96 { | 97 { |
97 return 0; | 98 return __sync_sub_and_fetch(ptr, value); |
98 } | 99 } |
99 | |
100 | 100 |
101 #ifdef SDL_HAS_64BIT_TYPE | 101 #ifdef SDL_HAS_64BIT_TYPE |
102 | 102 |
103 Uint64 | 103 Uint64 |
104 SDL_AtomicExchange64(Uint64 * ptr, Uint64 value) | 104 SDL_AtomicExchange64(Uint64 * ptr, Uint64 value) |
105 { | 105 { |
106 return 0; | 106 return __sync_lock_test_and_set(ptr, value); |
107 } | 107 } |
108 | 108 |
109 SDL_bool | 109 SDL_bool |
110 SDL_AtomicCompareThenSet64(Uint64 * ptr, | 110 SDL_AtomicCompareThenSet64(Uint64 * ptr, Uint64 oldvalue, Uint64 newvalue) |
111 Uint64 oldvalue, Uint64 newvalue) | |
112 { | 111 { |
113 return SDL_false; | 112 return (SDL_bool)__sync_bool_compare_and_swap(ptr, oldvalue, newvalue); |
114 } | 113 } |
115 | 114 |
116 SDL_bool | 115 SDL_bool |
117 SDL_AtomicTestThenSet64(Uint64 * ptr) | 116 SDL_AtomicTestThenSet64(Uint64 * ptr) |
118 { | 117 { |
119 return SDL_false; | 118 return (SDL_bool)(0 == __sync_lock_test_and_set(ptr, 1)); |
120 } | 119 } |
121 | 120 |
122 void | 121 void |
123 SDL_AtomicClear64(Uint64 * ptr) | 122 SDL_AtomicClear64(Uint64 * ptr) |
124 { | 123 { |
124 __sync_lock_release(ptr); | |
125 } | 125 } |
126 | 126 |
127 Uint64 | 127 Uint64 |
128 SDL_AtomicFetchThenIncrement64(Uint64 * ptr) | 128 SDL_AtomicFetchThenIncrement64(Uint64 * ptr) |
129 { | 129 { |
130 return 0; | 130 return __sync_fetch_and_add(ptr, 1); |
131 } | 131 } |
132 | 132 |
133 Uint64 | 133 Uint64 |
134 SDL_AtomicFetchThenDecrement64(Uint64 * ptr) | 134 SDL_AtomicFetchThenDecrement64(Uint64 * ptr) |
135 { | 135 { |
136 return 0; | 136 return __sync_fetch_and_sub(ptr, 1); |
137 } | 137 } |
138 | 138 |
139 Uint64 | 139 Uint64 |
140 SDL_AtomicFetchThenAdd64(Uint64 * ptr, Uint64 value) | 140 SDL_AtomicFetchThenAdd64(Uint64 * ptr, Uint64 value) |
141 { | 141 { |
142 return 0; | 142 return __sync_fetch_and_add(ptr, value); |
143 } | 143 } |
144 | 144 |
145 Uint64 | 145 Uint64 |
146 SDL_AtomicFetchThenSubtract64(Uint64 * ptr, Uint64 value) | 146 SDL_AtomicFetchThenSubtract64(Uint64 * ptr, Uint64 value) |
147 { | 147 { |
148 return 0; | 148 return __sync_fetch_and_sub(ptr, value); |
149 } | 149 } |
150 | 150 |
151 Uint64 | 151 Uint64 |
152 SDL_AtomicIncrementThenFetch64(Uint64 * ptr) | 152 SDL_AtomicIncrementThenFetch64(Uint64 * ptr) |
153 { | 153 { |
154 return 0; | 154 return __sync_add_and_fetch(ptr, 1); |
155 } | 155 } |
156 | 156 |
157 Uint64 | 157 Uint64 |
158 SDL_AtomicDecrementThenFetch64(Uint64 * ptr) | 158 SDL_AtomicDecrementThenFetch64(Uint64 * ptr) |
159 { | 159 { |
160 return 0; | 160 return __sync_sub_and_fetch(ptr, 1); |
161 } | 161 } |
162 | 162 |
163 Uint64 | 163 Uint64 |
164 SDL_AtomicAddThenFetch64(Uint64 * ptr, Uint64 value) | 164 SDL_AtomicAddThenFetch64(Uint64 * ptr, Uint64 value) |
165 { | 165 { |
166 return 0; | 166 return __sync_add_and_fetch(ptr, value); |
167 } | 167 } |
168 | 168 |
169 Uint64 | 169 Uint64 |
170 SDL_AtomicSubtractThenFetch64(Uint64 * ptr, Uint64 value) | 170 SDL_AtomicSubtractThenFetch64(Uint64 * ptr, Uint64 value) |
171 { | 171 { |
172 return 0; | 172 return __sync_sub_and_fetch(ptr, value); |
173 } | 173 } |
174 | |
175 #endif | 174 #endif |
176 #endif | 175 #endif |