test/testatomic.c
author Bob Pendleton <bob@pendleton.com>
Tue, 09 Jun 2009 17:33:44 +0000
changeset 3180 77d6336711fc
child 3186 51750b7a966f
permissions -rw-r--r--
First commit for SDL atomic operations.
On my linux box it compiles and installs correctly and testatomic runs without errors.
bob@3180
     1
#include "SDL.h"
bob@3180
     2
bob@3180
     3
int
bob@3180
     4
main(int argc, char** argv)
bob@3180
     5
{
bob@3180
     6
  int rv = 10;
bob@3180
     7
  volatile int atomic;
bob@3180
     8
bob@3180
     9
  SDL_atomic_int_set(&atomic, 10);
bob@3180
    10
  if(SDL_atomic_int_get(&atomic) != 10)
bob@3180
    11
    printf("Error: ");
bob@3180
    12
  printf("SDL_atomic_int_set(atomic, 10): atomic-> %d\n",
bob@3180
    13
         SDL_atomic_int_get(&atomic));
bob@3180
    14
    
bob@3180
    15
  SDL_atomic_int_add(&atomic, 10);
bob@3180
    16
  if(SDL_atomic_int_get(&atomic) != 20)
bob@3180
    17
    printf("Error: ");
bob@3180
    18
  printf("SDL_atomic_int_add(atomic, 10): atomic-> %d\n",
bob@3180
    19
         SDL_atomic_int_get(&atomic));
bob@3180
    20
  
bob@3180
    21
  rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30);
bob@3180
    22
  if(rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 30)
bob@3180
    23
    printf("Error: ");
bob@3180
    24
  printf("SDL_atomic_int_cmp_xchg(atomic, 20, 30): rv-> %d, atomic-> %d\n",
bob@3180
    25
         rv, SDL_atomic_int_get(&atomic));
bob@3180
    26
  
bob@3180
    27
  rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30);
bob@3180
    28
  if(rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 30)
bob@3180
    29
    printf("Error: ");
bob@3180
    30
  printf("SDL_atomic_int_cmp_xchg(atomic, 20, 40): rv-> %d, atomic-> %d\n",
bob@3180
    31
         rv, SDL_atomic_int_get(&atomic));
bob@3180
    32
  
bob@3180
    33
  rv = SDL_atomic_int_xchg_add(&atomic, 10);
bob@3180
    34
  if(rv != 30 || SDL_atomic_int_get(&atomic) != 40)
bob@3180
    35
    printf("Error: ");
bob@3180
    36
  printf("SDL_atomic_int_xchg_add(atomic, 10): rv-> %d, atomic-> %d\n",
bob@3180
    37
         rv, SDL_atomic_int_get(&atomic));
bob@3180
    38
bob@3180
    39
  SDL_atomic_int_inc(&atomic);
bob@3180
    40
  if(SDL_atomic_int_get(&atomic) != 41)
bob@3180
    41
    printf("Error: ");
bob@3180
    42
  printf("SDL_atomic_int_inc(atomic): atomic-> %d\n",
bob@3180
    43
         SDL_atomic_int_get(&atomic));
bob@3180
    44
bob@3180
    45
  rv = SDL_atomic_int_dec_test(&atomic);
bob@3180
    46
  if(rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 40)
bob@3180
    47
    printf("Error: ");
bob@3180
    48
  printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n",
bob@3180
    49
         rv, SDL_atomic_int_get(&atomic));
bob@3180
    50
  
bob@3180
    51
  SDL_atomic_int_set(&atomic, 1);
bob@3180
    52
  if(SDL_atomic_int_get(&atomic) != 1)
bob@3180
    53
    printf("Error: ");    
bob@3180
    54
    printf("SDL_atomic_int_set(atomic, 1): atomic-> %d\n",
bob@3180
    55
           SDL_atomic_int_get(&atomic));
bob@3180
    56
bob@3180
    57
  rv = SDL_atomic_int_dec_test(&atomic);
bob@3180
    58
  if(rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 0)
bob@3180
    59
    printf("Error: ");
bob@3180
    60
  printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n",
bob@3180
    61
         rv, SDL_atomic_int_get(&atomic));
bob@3180
    62
  
bob@3180
    63
  return 0;
bob@3180
    64
}