test/testatomic.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 10 Jun 2009 13:34:20 +0000
changeset 3186 51750b7a966f
parent 3180 77d6336711fc
child 3199 3e1bf2b8bd81
permissions -rw-r--r--
indent
bob@3180
     1
#include "SDL.h"
bob@3180
     2
bob@3180
     3
int
slouken@3186
     4
main(int argc, char **argv)
bob@3180
     5
{
slouken@3186
     6
    int rv = 10;
slouken@3186
     7
    volatile int atomic;
bob@3180
     8
slouken@3186
     9
    SDL_atomic_int_set(&atomic, 10);
slouken@3186
    10
    if (SDL_atomic_int_get(&atomic) != 10)
slouken@3186
    11
        printf("Error: ");
slouken@3186
    12
    printf("SDL_atomic_int_set(atomic, 10): atomic-> %d\n",
slouken@3186
    13
           SDL_atomic_int_get(&atomic));
bob@3180
    14
slouken@3186
    15
    SDL_atomic_int_add(&atomic, 10);
slouken@3186
    16
    if (SDL_atomic_int_get(&atomic) != 20)
slouken@3186
    17
        printf("Error: ");
slouken@3186
    18
    printf("SDL_atomic_int_add(atomic, 10): atomic-> %d\n",
slouken@3186
    19
           SDL_atomic_int_get(&atomic));
bob@3180
    20
slouken@3186
    21
    rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30);
slouken@3186
    22
    if (rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 30)
slouken@3186
    23
        printf("Error: ");
slouken@3186
    24
    printf("SDL_atomic_int_cmp_xchg(atomic, 20, 30): rv-> %d, atomic-> %d\n",
slouken@3186
    25
           rv, SDL_atomic_int_get(&atomic));
slouken@3186
    26
slouken@3186
    27
    rv = SDL_atomic_int_cmp_xchg(&atomic, 20, 30);
slouken@3186
    28
    if (rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 30)
slouken@3186
    29
        printf("Error: ");
slouken@3186
    30
    printf("SDL_atomic_int_cmp_xchg(atomic, 20, 40): rv-> %d, atomic-> %d\n",
slouken@3186
    31
           rv, SDL_atomic_int_get(&atomic));
slouken@3186
    32
slouken@3186
    33
    rv = SDL_atomic_int_xchg_add(&atomic, 10);
slouken@3186
    34
    if (rv != 30 || SDL_atomic_int_get(&atomic) != 40)
slouken@3186
    35
        printf("Error: ");
slouken@3186
    36
    printf("SDL_atomic_int_xchg_add(atomic, 10): rv-> %d, atomic-> %d\n",
slouken@3186
    37
           rv, SDL_atomic_int_get(&atomic));
slouken@3186
    38
slouken@3186
    39
    SDL_atomic_int_inc(&atomic);
slouken@3186
    40
    if (SDL_atomic_int_get(&atomic) != 41)
slouken@3186
    41
        printf("Error: ");
slouken@3186
    42
    printf("SDL_atomic_int_inc(atomic): atomic-> %d\n",
slouken@3186
    43
           SDL_atomic_int_get(&atomic));
slouken@3186
    44
slouken@3186
    45
    rv = SDL_atomic_int_dec_test(&atomic);
slouken@3186
    46
    if (rv != SDL_FALSE || SDL_atomic_int_get(&atomic) != 40)
slouken@3186
    47
        printf("Error: ");
slouken@3186
    48
    printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n",
slouken@3186
    49
           rv, SDL_atomic_int_get(&atomic));
slouken@3186
    50
slouken@3186
    51
    SDL_atomic_int_set(&atomic, 1);
slouken@3186
    52
    if (SDL_atomic_int_get(&atomic) != 1)
slouken@3186
    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
slouken@3186
    57
    rv = SDL_atomic_int_dec_test(&atomic);
slouken@3186
    58
    if (rv != SDL_TRUE || SDL_atomic_int_get(&atomic) != 0)
slouken@3186
    59
        printf("Error: ");
slouken@3186
    60
    printf("SDL_atomic_int_dec_test(atomic): rv-> %d, atomic-> %d\n",
slouken@3186
    61
           rv, SDL_atomic_int_get(&atomic));
slouken@3186
    62
slouken@3186
    63
    return 0;
bob@3180
    64
}