comparison test/testatomic.c @ 5013:9d6b527e0912

Fixed compiler errors
author Sam Lantinga <slouken@libsdl.org>
date Mon, 17 Jan 2011 13:54:13 -0800
parents 8e8876e4aec6
children 342b158efbbe
comparison
equal deleted inserted replaced
5012:2e282002bac3 5013:9d6b527e0912
28 void RunBasicTest() 28 void RunBasicTest()
29 { 29 {
30 int value; 30 int value;
31 SDL_SpinLock lock = 0; 31 SDL_SpinLock lock = 0;
32 32
33 SDL_atomic_t v;
33 SDL_bool tfret = SDL_FALSE; 34 SDL_bool tfret = SDL_FALSE;
34 35
35 printf("\nspin lock---------------------------------------\n\n"); 36 printf("\nspin lock---------------------------------------\n\n");
36 37
37 SDL_AtomicLock(&lock); 38 SDL_AtomicLock(&lock);
38 printf("AtomicLock lock=%d\n", lock); 39 printf("AtomicLock lock=%d\n", lock);
39 SDL_AtomicUnlock(&lock); 40 SDL_AtomicUnlock(&lock);
40 printf("AtomicUnlock lock=%d\n", lock); 41 printf("AtomicUnlock lock=%d\n", lock);
41 42
42 printf("\natomic -----------------------------------------\n\n"); 43 printf("\natomic -----------------------------------------\n\n");
43
44 SDL_atomic_t v;
45 44
46 SDL_AtomicSet(&v, 0); 45 SDL_AtomicSet(&v, 0);
47 tfret = SDL_AtomicSet(&v, 10) == 0; 46 tfret = SDL_AtomicSet(&v, 10) == 0;
48 printf("AtomicSet(10) tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); 47 printf("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
49 tfret = SDL_AtomicAdd(&v, 10) == 10; 48 tfret = SDL_AtomicAdd(&v, 10) == 10;
50 printf("AtomicAdd(10) tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); 49 printf("AtomicAdd(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
51 50
52 SDL_AtomicSet(&v, 0); 51 SDL_AtomicSet(&v, 0);
53 SDL_AtomicIncRef(&v); 52 SDL_AtomicIncRef(&v);
54 tfret = (SDL_AtomicGet(&v) == 1); 53 tfret = (SDL_AtomicGet(&v) == 1);
55 printf("AtomicIncRef() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); 54 printf("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
56 SDL_AtomicIncRef(&v); 55 SDL_AtomicIncRef(&v);
57 tfret = (SDL_AtomicGet(&v) == 2); 56 tfret = (SDL_AtomicGet(&v) == 2);
58 printf("AtomicIncRef() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); 57 printf("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
59 tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE); 58 tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE);
60 printf("AtomicDecRef() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); 59 printf("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
61 tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE); 60 tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE);
62 printf("AtomicDecRef() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); 61 printf("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
63 62
64 SDL_AtomicSet(&v, 10); 63 SDL_AtomicSet(&v, 10);
65 tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE); 64 tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE);
66 printf("AtomicCAS() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); 65 printf("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
67 value = SDL_AtomicGet(&v); 66 value = SDL_AtomicGet(&v);
68 tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE); 67 tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE);
69 printf("AtomicCAS() tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v)); 68 printf("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
70 } 69 }
71 70
72 /* Atomic operation test, adapted from code by Michael Davidsaver at: 71 /* Atomic operation test, adapted from code by Michael Davidsaver at:
73 http://bazaar.launchpad.net/~mdavidsaver/epics-base/atomic/revision/12105#src/libCom/test/epicsAtomicTest.c 72 http://bazaar.launchpad.net/~mdavidsaver/epics-base/atomic/revision/12105#src/libCom/test/epicsAtomicTest.c
74 */ 73 */