test/testatomic.c
changeset 3201 c297230efc75
parent 3199 3e1bf2b8bd81
child 3202 3aa519a5c676
     1.1 --- a/test/testatomic.c	Wed Jun 24 20:20:57 2009 +0000
     1.2 +++ b/test/testatomic.c	Wed Jun 24 22:24:23 2009 +0000
     1.3 @@ -1,64 +1,51 @@
     1.4  #include "SDL.h"
     1.5  
     1.6 +/*
     1.7 +  Absolutely basic test just to see if we get the expected value after
     1.8 +  calling each function.
     1.9 +*/
    1.10 +
    1.11  int
    1.12  main(int argc, char **argv)
    1.13  {
    1.14 -/*     int rv = 10; */
    1.15 -/*     volatile int atomic; */
    1.16  
    1.17 -/*     SDL_atomic_int_set(&atomic, 10); */
    1.18 -/*     if (SDL_atomic_int_get(&atomic) != 10) */
    1.19 -/*         printf("Error: "); */
    1.20 -/*     printf("SDL_atomic_int_set(atomic, 10): atomic-> %d\n", */
    1.21 -/*            SDL_atomic_int_get(&atomic)); */
    1.22 +   Uint32 val32 = 0;
    1.23 +   Uint32 ret32 = 0;
    1.24  
    1.25 -/*     SDL_atomic_int_add(&atomic, 10); */
    1.26 -/*     if (SDL_atomic_int_get(&atomic) != 20) */
    1.27 -/*         printf("Error: "); */
    1.28 -/*     printf("SDL_atomic_int_add(atomic, 10): atomic-> %d\n", */
    1.29 -/*            SDL_atomic_int_get(&atomic)); */
    1.30 +   Uint64 val64 = 0;
    1.31 +   Uint64 ret64 = 0;
    1.32  
    1.33 -/*     rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30); */
    1.34 -/*     if (rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 30) */
    1.35 -/*         printf("Error: "); */
    1.36 -/*     printf("SDL_atomic_int_cmp_xchg(atomic, 20, 30): rv-> %d, atomic-> %d\n", */
    1.37 -/*            rv, SDL_atomic_int_get(&atomic)); */
    1.38 +   SDL_bool tfval = SDL_FALSE;
    1.39  
    1.40 -/*     rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30); */
    1.41 -/*     if (rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 30) */
    1.42 -/*         printf("Error: "); */
    1.43 -/*     printf("SDL_atomic_int_cmp_xchg(atomic, 20, 40): rv-> %d, atomic-> %d\n", */
    1.44 -/*            rv, SDL_atomic_int_get(&atomic)); */
    1.45 +   ret32 = SDL_AtomicExchange32(&val32, 10);
    1.46 +   tfval = SDL_AtomicCompareThenSet32(&val32, 10, 20);
    1.47 +   tfval = SDL_AtomicTestThenSet32(&val32);
    1.48 +   SDL_AtomicClear32(&val32);
    1.49 +   ret32 = SDL_AtomicFetchThenIncrement32(&val32);
    1.50 +   ret32 = SDL_AtomicFetchThenDecrement32(&val32);
    1.51 +   ret32 = SDL_AtomicFetchThenAdd32(&val32, 10);
    1.52 +   ret32 = SDL_AtomicFetchThenSubtract32(&val32, 10);
    1.53 +   ret32 = SDL_AtomicIncrementThenFetch32(&val32);
    1.54 +   ret32 = SDL_AtomicDecrementThenFetch32(&val32);
    1.55 +   ret32 = SDL_AtomicAddThenFetch32(&val32, 10);
    1.56 +   ret32 = SDL_AtomicSubtractThenFetch32(&val32, 10);
    1.57  
    1.58 -/*     rv = SDL_atomic_int_xchg_add(&atomic, 10); */
    1.59 -/*     if (rv != 30 || SDL_atomic_int_get(&atomic) != 40) */
    1.60 -/*         printf("Error: "); */
    1.61 -/*     printf("SDL_atomic_int_xchg_add(atomic, 10): rv-> %d, atomic-> %d\n", */
    1.62 -/*            rv, SDL_atomic_int_get(&atomic)); */
    1.63 +/* #ifdef SDL_HAS_64BIT_TYPE */
    1.64 +#if 0
    1.65  
    1.66 -/*     SDL_atomic_int_inc(&atomic); */
    1.67 -/*     if (SDL_atomic_int_get(&atomic) != 41) */
    1.68 -/*         printf("Error: "); */
    1.69 -/*     printf("SDL_atomic_int_inc(atomic): atomic-> %d\n", */
    1.70 -/*            SDL_atomic_int_get(&atomic)); */
    1.71 +   ret64 = SDL_AtomicExchange64(&val64, 10);
    1.72 +   tfval = SDL_AtomicCompareThenSet64(&val64, 10, 20);
    1.73 +   tfval = SDL_AtomicTestThenSet64(&val64);
    1.74 +   SDL_AtomicClear64(&val64);
    1.75 +   ret64 = SDL_AtomicFetchThenIncrement64(&val64);
    1.76 +   ret64 = SDL_AtomicFetchThenDecrement64(&val64);
    1.77 +   ret64 = SDL_AtomicFetchThenAdd64(&val64, 10);
    1.78 +   ret64 = SDL_AtomicFetchThenSubtract64(&val64, 10);
    1.79 +   ret64 = SDL_AtomicIncrementThenFetch64(&val64);
    1.80 +   ret64 = SDL_AtomicDecrementThenFetch64(&val64);
    1.81 +   ret64 = SDL_AtomicAddThenFetch64(&val64, 10);
    1.82 +   ret64 = SDL_AtomicSubtractThenFetch64(&val64, 10);
    1.83 +#endif
    1.84  
    1.85 -/*     rv = SDL_atomic_int_dec_test(&atomic); */
    1.86 -/*     if (rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 40) */
    1.87 -/*         printf("Error: "); */
    1.88 -/*     printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n", */
    1.89 -/*            rv, SDL_atomic_int_get(&atomic)); */
    1.90 -
    1.91 -/*     SDL_atomic_int_set(&atomic, 1); */
    1.92 -/*     if (SDL_atomic_int_get(&atomic) != 1) */
    1.93 -/*         printf("Error: "); */
    1.94 -/*     printf("SDL_atomic_int_set(atomic, 1): atomic-> %d\n", */
    1.95 -/*            SDL_atomic_int_get(&atomic)); */
    1.96 -
    1.97 -/*     rv = SDL_atomic_int_dec_test(&atomic); */
    1.98 -/*     if (rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 0) */
    1.99 -/*         printf("Error: "); */
   1.100 -/*     printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n", */
   1.101 -/*            rv, SDL_atomic_int_get(&atomic)); */
   1.102 -
   1.103 -    return 0;
   1.104 -}
   1.105 +   return 0;
   1.106 +   }