comparison include/SDL_atomic.h @ 3181:030899df1af5

OK, had to add some casts to get SDL_atomic.h to compile with C++. testatomic still compiles and runs.
author Bob Pendleton <bob@pendleton.com>
date Tue, 09 Jun 2009 19:39:23 +0000
parents 77d6336711fc
children 51750b7a966f
comparison
equal deleted inserted replaced
3180:77d6336711fc 3181:030899df1af5
75 : "=a" (rv), 75 : "=a" (rv),
76 "=m" (*atomic) 76 "=m" (*atomic)
77 : "r" (newvalue), 77 : "r" (newvalue),
78 "m" (*atomic), 78 "m" (*atomic),
79 "0" (oldvalue)); 79 "0" (oldvalue));
80 return (rv == oldvalue); 80 return (SDL_bool)(rv == oldvalue);
81 } 81 }
82 82
83 static __inline__ SDL_bool 83 static __inline__ SDL_bool
84 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) 84 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
85 { 85 {
93 : "=a" (rv), 93 : "=a" (rv),
94 "=m" (*atomic) 94 "=m" (*atomic)
95 : "r" (newvalue), 95 : "r" (newvalue),
96 "m" (*atomic), 96 "m" (*atomic),
97 "0" (oldvalue)); 97 "0" (oldvalue));
98 return (rv == oldvalue); 98 return (SDL_bool)(rv == oldvalue);
99 } 99 }
100 #elif defined(__GNUC__) && defined(__alpha__) 100 #elif defined(__GNUC__) && defined(__alpha__)
101 # define ATOMIC_MEMORY_BARRIER (__asm__ __volatile__ ("mb" : : : "memory")) 101 # define ATOMIC_MEMORY_BARRIER (__asm__ __volatile__ ("mb" : : : "memory"))
102 # define ATOMIC_INT_CMP_XCHG(atomic,value) \ 102 # define ATOMIC_INT_CMP_XCHG(atomic,value) \
103 ({ \ 103 ({ \
139 "=&r" (rv) 139 "=&r" (rv)
140 : "m" (*atomic), 140 : "m" (*atomic),
141 "Ir" (oldvalue), 141 "Ir" (oldvalue),
142 "Ir" (newvalue) 142 "Ir" (newvalue)
143 : "memory"); 143 : "memory");
144 return (rv != 0); 144 return (SDL_bool)(rv != 0);
145 } 145 }
146 # elif (SIZEOF_VOIDP == 8) 146 # elif (SIZEOF_VOIDP == 8)
147 static __inline__ SDL_bool 147 static __inline__ SDL_bool
148 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) 148 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
149 { 149 {
162 "=&r" (rv) 162 "=&r" (rv)
163 : "m" (*atomic), 163 : "m" (*atomic),
164 "Ir" (oldvalue), 164 "Ir" (oldvalue),
165 "Ir" (newvalue) 165 "Ir" (newvalue)
166 : "memory"); 166 : "memory");
167 return (rv != 0); 167 return (SDL_bool)(rv != 0);
168 } 168 }
169 # else 169 # else
170 # error "Your system has an unsupported pointer size" 170 # error "Your system has an unsupported pointer size"
171 # endif /* SIZEOF_VOIDP */ 171 # endif /* SIZEOF_VOIDP */
172 #elif defined(__GNUC__) && defined(__sparc__) 172 #elif defined(__GNUC__) && defined(__sparc__)
193 "=m" (*atomic) 193 "=m" (*atomic)
194 : "r" (oldvalue), 194 : "r" (oldvalue),
195 "m" (*atomic), 195 "m" (*atomic),
196 "r" (atomic), 196 "r" (atomic),
197 "0" (newvalue)); 197 "0" (newvalue));
198 return (rv == oldvalue); 198 return (SDL_bool)(rv == oldvalue);
199 } 199 }
200 # elif (SIZEOF_VOIDP == 8) 200 # elif (SIZEOF_VOIDP == 8)
201 static __inline__ SDL_bool 201 static __inline__ SDL_bool
202 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) 202 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
203 { 203 {
208 "=m" (*a) 208 "=m" (*a)
209 : "r" (oldvalue), 209 : "r" (oldvalue),
210 "m" (*a), 210 "m" (*a),
211 "r" (a), 211 "r" (a),
212 "0" (newvalue)); 212 "0" (newvalue));
213 return (rv == oldvalue); 213 return (SDL_bool)(rv == oldvalue);
214 } 214 }
215 # else 215 # else
216 # error "Your system has an unsupported pointer size" 216 # error "Your system has an unsupported pointer size"
217 # endif /* SIZEOF_VOIDP */ 217 # endif /* SIZEOF_VOIDP */
218 #elif defined(__GNUC__) && (defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) || defined(_M_PPC)) 218 #elif defined(__GNUC__) && (defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) || defined(_M_PPC))
271 : "b" (atomic), 271 : "b" (atomic),
272 "r" (oldvalue), 272 "r" (oldvalue),
273 "r" 273 "r"
274 : "cr0", 274 : "cr0",
275 "memory"); 275 "memory");
276 return (rv == 0); 276 return (SDL_bool)(rv == 0);
277 } 277 }
278 278
279 static __inline__ SDL_bool 279 static __inline__ SDL_bool
280 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) 280 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
281 { 281 {
291 : "b" (atomic), 291 : "b" (atomic),
292 "r" (oldvalue), 292 "r" (oldvalue),
293 "r" (newvalue) 293 "r" (newvalue)
294 : "cr0", 294 : "cr0",
295 "memory"); 295 "memory");
296 return (rv == 0); 296 return (SDL_bool)(rv == 0);
297 } 297 }
298 # elif (SIZEOF_VOIDP == 8) 298 # elif (SIZEOF_VOIDP == 8)
299 static __inline__ SDL_bool 299 static __inline__ SDL_bool
300 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) 300 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
301 { 301 {
312 : "b" (atomic), 312 : "b" (atomic),
313 "r" (oldvalue), 313 "r" (oldvalue),
314 "r" 314 "r"
315 : "cr0", 315 : "cr0",
316 "memory"); 316 "memory");
317 return (rv == 0); 317 return (SDL_bool)(rv == 0);
318 } 318 }
319 319
320 static __inline__ SDL_bool 320 static __inline__ SDL_bool
321 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) 321 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
322 { 322 {
332 : "b" (atomic), 332 : "b" (atomic),
333 "r" (oldvalue), 333 "r" (oldvalue),
334 "r" (newvalue) 334 "r" (newvalue)
335 : "cr0", 335 : "cr0",
336 "memory"); 336 "memory");
337 return (rv == 0); 337 return (SDL_bool)(rv == 0);
338 } 338 }
339 # else 339 # else
340 # error "Your system has an unsupported pointer size" 340 # error "Your system has an unsupported pointer size"
341 # endif /* SIZEOF_VOIDP */ 341 # endif /* SIZEOF_VOIDP */
342 #elif defined(__GNUC__) && (defined(__IA64__) || defined(__ia64__)) 342 #elif defined(__GNUC__) && (defined(__IA64__) || defined(__ia64__))
461 "=&d" (tmp) 461 "=&d" (tmp)
462 : "d" (value), 462 : "d" (value),
463 "m" (*atomic), 463 "m" (*atomic),
464 "0" (rv) 464 "0" (rv)
465 : "memory"); 465 : "memory");
466 return rv; 466 return (SDL_bool)rv;
467 } 467 }
468 468
469 static __inline__ void 469 static __inline__ void
470 SDL_atomic_int_add(volatile int* atomic, int value) 470 SDL_atomic_int_add(volatile int* atomic, int value)
471 { 471 {
487 "=m" (*atomic), 487 "=m" (*atomic),
488 "=d" (readvalue) 488 "=d" (readvalue)
489 : "d" (newvalue), 489 : "d" (newvalue),
490 "m" (*atomic), 490 "m" (*atomic),
491 "2" (oldvalue)); 491 "2" (oldvalue));
492 return rv; 492 return (SDL_bool)rv;
493 } 493 }
494 494
495 static __inline__ SDL_bool 495 static __inline__ SDL_bool
496 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) 496 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
497 { 497 {
503 "=m" (*atomic), 503 "=m" (*atomic),
504 "=d" (readvalue) 504 "=d" (readvalue)
505 : "d" (newvalue), 505 : "d" (newvalue),
506 "m" (*atomic), 506 "m" (*atomic),
507 "2" (oldvalue)); 507 "2" (oldvalue));
508 return rv; 508 return (SDL_bool)rv;
509 } 509 }
510 #elif defined(__GNUC__) && defined(__s390__) 510 #elif defined(__GNUC__) && defined(__s390__)
511 # define ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue) \ 511 # define ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue) \
512 ({ \ 512 ({ \
513 int rv = oldvalue; \ 513 int rv = oldvalue; \
528 : "+d" (rv), 528 : "+d" (rv),
529 "=Q" (*atomic) 529 "=Q" (*atomic)
530 : "d" (newvalue), 530 : "d" (newvalue),
531 "m" (*atomic) 531 "m" (*atomic)
532 : "cc"); 532 : "cc");
533 return (rv == oldvalue); 533 return (SDL_bool)(rv == oldvalue);
534 } 534 }
535 # elif (SIZEOF_VOIDP == 8) 535 # elif (SIZEOF_VOIDP == 8)
536 static __inline__ SDL_bool 536 static __inline__ SDL_bool
537 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) 537 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
538 { 538 {
542 : "+d" (rv), 542 : "+d" (rv),
543 "=Q" (*a) 543 "=Q" (*a)
544 : "d" ((long)(newvalue)), 544 : "d" ((long)(newvalue)),
545 "m" (*a) 545 "m" (*a)
546 : "cc"); 546 : "cc");
547 return (rv == oldvalue); 547 return (SDL_bool)(rv == oldvalue);
548 } 548 }
549 # else 549 # else
550 # error "Your system has an unsupported pointer size" 550 # error "Your system has an unsupported pointer size"
551 # endif /* SIZEOF_VOIDP */ 551 # endif /* SIZEOF_VOIDP */
552 #elif defined(__WIN32__) 552 #elif defined(__WIN32__)
565 565
566 # if (WINVER > 0X0400) 566 # if (WINVER > 0X0400)
567 static __inline__ SDL_bool 567 static __inline__ SDL_bool
568 SDL_atmoic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) 568 SDL_atmoic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
569 { 569 {
570 return ((SDL_bool)InterlockedCompareExchangePointer((PVOID*)atomic, 570 return (SDL_bool)(InterlockedCompareExchangePointer((PVOID*)atomic,
571 (PVOID)newvalue, 571 (PVOID)newvalue,
572 (PVOID)oldvalue) == oldvalue); 572 (PVOID)oldvalue) == oldvalue);
573 } 573 }
574 574
575 575
576 static __inline__ SDL_bool 576 static __inline__ SDL_bool
577 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue) 577 SDL_atomic_ptr_cmp_xchg(volatile void** atomic, void* oldvalue, void* newvalue)
622 622
623 #ifdef ATOMIC_INT_CMP_XCHG 623 #ifdef ATOMIC_INT_CMP_XCHG
624 static __inline__ SDL_bool 624 static __inline__ SDL_bool
625 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue) 625 SDL_atomic_int_cmp_xchg(volatile int* atomic, int oldvalue, int newvalue)
626 { 626 {
627 return ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue); 627 return (SDL_bool)ATOMIC_INT_CMP_XCHG(atomic,oldvalue,newvalue);
628 } 628 }
629 629
630 static __inline__ int 630 static __inline__ int
631 SDL_atomic_int_xchg_add(volatile int* atomic, int value) 631 SDL_atomic_int_xchg_add(volatile int* atomic, int value)
632 { 632 {