test/testatomic.c
author Bob Pendleton <bob@pendleton.com>
Tue, 11 Aug 2009 21:27:19 +0000
changeset 3237 916f396fe65d
parent 3216 48a80f2a7ff2
child 3261 72b542f34739
permissions -rw-r--r--
Start of redesign, getting rid of 8 and 16 bit operations in .h and test files.
bob@3180
     1
#include "SDL.h"
bob@3180
     2
bob@3201
     3
/*
bob@3202
     4
  Absolutely basic tests just to see if we get the expected value
bob@3202
     5
  after calling each function.
bob@3201
     6
*/
bob@3201
     7
bob@3202
     8
char * 
bob@3202
     9
tf(SDL_bool tf)
bob@3202
    10
{
bob@3202
    11
   static char *t = "true";
bob@3202
    12
   static char *f = "false";
bob@3202
    13
bob@3202
    14
   if (tf)
bob@3202
    15
   {
bob@3202
    16
      return t;
bob@3202
    17
   }
bob@3202
    18
bob@3202
    19
   return f;
bob@3202
    20
}
bob@3202
    21
  
bob@3180
    22
int
slouken@3186
    23
main(int argc, char **argv)
bob@3180
    24
{
bob@3180
    25
bob@3216
    26
   volatile Uint32 val32 = 0;
bob@3201
    27
   Uint32 ret32 = 0;
bob@3180
    28
bob@3216
    29
   volatile Uint64 val64 = 0;
bob@3201
    30
   Uint64 ret64 = 0;
bob@3180
    31
bob@3202
    32
   SDL_bool tfret = SDL_FALSE;
bob@3202
    33
bob@3202
    34
   printf("32 bit -----------------------------------------\n\n");
slouken@3186
    35
bob@3201
    36
   ret32 = SDL_AtomicExchange32(&val32, 10);
bob@3202
    37
   printf("Exchange32           ret=%d val=%d\n", ret32, val32);
bob@3202
    38
   ret32 = SDL_AtomicExchange32(&val32, 0);
bob@3202
    39
   printf("Exchange32           ret=%d val=%d\n", ret32, val32);
bob@3202
    40
bob@3202
    41
   val32 = 10;
bob@3202
    42
   tfret = SDL_AtomicCompareThenSet32(&val32, 10, 20);
bob@3202
    43
   printf("CompareThenSet32     tfret=%s val=%d\n", tf(tfret), val32);
bob@3202
    44
   val32 = 10;
bob@3202
    45
   tfret = SDL_AtomicCompareThenSet32(&val32, 0, 20);
bob@3202
    46
   printf("CompareThenSet32     tfret=%s val=%d\n", tf(tfret), val32);
bob@3202
    47
bob@3202
    48
   val32 = 0;
bob@3202
    49
   tfret = SDL_AtomicTestThenSet32(&val32);
bob@3202
    50
   printf("TestThenSet32        tfret=%s val=%d\n", tf(tfret), val32);
bob@3202
    51
   tfret = SDL_AtomicTestThenSet32(&val32);
bob@3202
    52
   printf("TestThenSet32        tfret=%s val=%d\n", tf(tfret), val32);
bob@3202
    53
bob@3201
    54
   SDL_AtomicClear32(&val32);
bob@3202
    55
   printf("Clear32              val=%d\n", val32);
bob@3202
    56
bob@3201
    57
   ret32 = SDL_AtomicFetchThenIncrement32(&val32);
bob@3202
    58
   printf("FetchThenIncrement32 ret=%d val=%d\n", ret32, val32);
bob@3202
    59
bob@3201
    60
   ret32 = SDL_AtomicFetchThenDecrement32(&val32);
bob@3202
    61
   printf("FetchThenDecrement32 ret=%d val=%d\n", ret32, val32);
bob@3202
    62
bob@3201
    63
   ret32 = SDL_AtomicFetchThenAdd32(&val32, 10);
bob@3202
    64
   printf("FetchThenAdd32       ret=%d val=%d\n", ret32, val32);
bob@3202
    65
bob@3201
    66
   ret32 = SDL_AtomicFetchThenSubtract32(&val32, 10);
bob@3202
    67
   printf("FetchThenSubtract32  ret=%d val=%d\n", ret32, val32);
bob@3202
    68
bob@3201
    69
   ret32 = SDL_AtomicIncrementThenFetch32(&val32);
bob@3202
    70
   printf("IncrementThenFetch32 ret=%d val=%d\n", ret32, val32);
bob@3202
    71
bob@3201
    72
   ret32 = SDL_AtomicDecrementThenFetch32(&val32);
bob@3202
    73
   printf("DecrementThenFetch32 ret=%d val=%d\n", ret32, val32);
bob@3202
    74
bob@3201
    75
   ret32 = SDL_AtomicAddThenFetch32(&val32, 10);
bob@3202
    76
   printf("AddThenFetch32       ret=%d val=%d\n", ret32, val32);
bob@3202
    77
bob@3201
    78
   ret32 = SDL_AtomicSubtractThenFetch32(&val32, 10);
bob@3202
    79
   printf("SubtractThenFetch32  ret=%d val=%d\n", ret32, val32);
slouken@3186
    80
bob@3202
    81
#ifdef SDL_HAS_64BIT_TYPE
bob@3202
    82
   printf("64 bit -----------------------------------------\n\n");
slouken@3186
    83
bob@3201
    84
   ret64 = SDL_AtomicExchange64(&val64, 10);
bob@3202
    85
   printf("Exchange64           ret=%lld val=%lld\n", ret64, val64);
bob@3202
    86
   ret64 = SDL_AtomicExchange64(&val64, 0);
bob@3202
    87
   printf("Exchange64           ret=%lld val=%lld\n", ret64, val64);
bob@3202
    88
bob@3202
    89
   val64 = 10;
bob@3202
    90
   tfret = SDL_AtomicCompareThenSet64(&val64, 10, 20);
bob@3202
    91
   printf("CompareThenSet64     tfret=%s val=%lld\n", tf(tfret), val64);
bob@3202
    92
   val64 = 10;
bob@3202
    93
   tfret = SDL_AtomicCompareThenSet64(&val64, 0, 20);
bob@3202
    94
   printf("CompareThenSet64     tfret=%s val=%lld\n", tf(tfret), val64);
bob@3202
    95
bob@3202
    96
   val64 = 0;
bob@3202
    97
   tfret = SDL_AtomicTestThenSet64(&val64);
bob@3202
    98
   printf("TestThenSet64        tfret=%s val=%lld\n", tf(tfret), val64);
bob@3202
    99
   tfret = SDL_AtomicTestThenSet64(&val64);
bob@3202
   100
   printf("TestThenSet64        tfret=%s val=%lld\n", tf(tfret), val64);
bob@3202
   101
bob@3201
   102
   SDL_AtomicClear64(&val64);
bob@3202
   103
   printf("Clear64              val=%lld\n", val64);
bob@3202
   104
bob@3201
   105
   ret64 = SDL_AtomicFetchThenIncrement64(&val64);
bob@3202
   106
   printf("FetchThenIncrement64 ret=%lld val=%lld\n", ret64, val64);
bob@3202
   107
bob@3201
   108
   ret64 = SDL_AtomicFetchThenDecrement64(&val64);
bob@3202
   109
   printf("FetchThenDecrement64 ret=%lld val=%lld\n", ret64, val64);
bob@3202
   110
bob@3201
   111
   ret64 = SDL_AtomicFetchThenAdd64(&val64, 10);
bob@3202
   112
   printf("FetchThenAdd64       ret=%lld val=%lld\n", ret64, val64);
bob@3202
   113
bob@3201
   114
   ret64 = SDL_AtomicFetchThenSubtract64(&val64, 10);
bob@3202
   115
   printf("FetchThenSubtract64  ret=%lld val=%lld\n", ret64, val64);
bob@3202
   116
bob@3201
   117
   ret64 = SDL_AtomicIncrementThenFetch64(&val64);
bob@3202
   118
   printf("IncrementThenFetch64 ret=%lld val=%lld\n", ret64, val64);
bob@3202
   119
bob@3201
   120
   ret64 = SDL_AtomicDecrementThenFetch64(&val64);
bob@3202
   121
   printf("DecrementThenFetch64 ret=%lld val=%lld\n", ret64, val64);
bob@3202
   122
bob@3201
   123
   ret64 = SDL_AtomicAddThenFetch64(&val64, 10);
bob@3202
   124
   printf("AddThenFetch64       ret=%lld val=%lld\n", ret64, val64);
bob@3202
   125
bob@3201
   126
   ret64 = SDL_AtomicSubtractThenFetch64(&val64, 10);
bob@3202
   127
   printf("SubtractThenFetch64  ret=%lld val=%lld\n", ret64, val64);
bob@3201
   128
#endif
slouken@3186
   129
bob@3201
   130
   return 0;
bob@3201
   131
   }