diff options
author | Sam Lantinga <slouken@libsdl.org> | 2013-05-18 14:17:52 -0700 |
---|---|---|
committer | Sam Lantinga <slouken@libsdl.org> | 2013-05-18 14:17:52 -0700 |
commit | b80d20fb1100c64799769dbc0ef67582dcf29e31 (patch) | |
tree | 351258ecef703d638c01d1e629af4adc22a31994 /test/testatomic.c | |
parent | 220d178aad1719aabbf6e2dd0bebcedba0abc951 (diff) | |
download | sdl-b80d20fb1100c64799769dbc0ef67582dcf29e31.tar.gz |
File style cleanup for the SDL 2.0 release
Diffstat (limited to 'test/testatomic.c')
-rw-r--r-- | test/testatomic.c | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/test/testatomic.c b/test/testatomic.c index 7bcceb559..143d707c0 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -53,7 +53,7 @@ void RunBasicTest() printf("AtomicUnlock lock=%d\n", lock); printf("\natomic -----------------------------------------\n\n"); - + SDL_AtomicSet(&v, 0); tfret = SDL_AtomicSet(&v, 10) == 0; printf("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); @@ -95,27 +95,27 @@ void RunBasicTest() * at the end the value is compared with the expected * and with a non-atomic counter. */ - + /* Number of concurrent incrementers */ #define NThreads 2 #define CountInc 100 #define VALBITS (sizeof(atomicValue)*8) - + #define atomicValue int #define CountTo ((atomicValue)((unsigned int)(1<<(VALBITS-1))-1)) #define NInter (CountTo/CountInc/NThreads) #define Expect (CountTo-NInter*CountInc*NThreads) - + SDL_COMPILE_TIME_ASSERT(size, CountTo>0); /* check for rollover */ - + static SDL_atomic_t good = { 42 }; - + static atomicValue bad = 42; - + static SDL_atomic_t threadsRunning; static SDL_sem *threadDone; - + static int adder(void* junk) { @@ -129,111 +129,111 @@ int adder(void* junk) SDL_SemPost(threadDone); return 0; } - + static void runAdder(void) { Uint32 start, end; int T=NThreads; - + start = SDL_GetTicks(); - + threadDone = SDL_CreateSemaphore(0); SDL_AtomicSet(&threadsRunning, NThreads); while (T--) SDL_CreateThread(adder, "Adder", NULL); - + while (SDL_AtomicGet(&threadsRunning) > 0) SDL_SemWait(threadDone); - + SDL_DestroySemaphore(threadDone); end = SDL_GetTicks(); - + printf("Finished in %f sec\n", (end - start) / 1000.f); } - + static void RunEpicTest() { int b; atomicValue v; - + printf("\nepic test---------------------------------------\n\n"); printf("Size asserted to be >= 32-bit\n"); SDL_assert(sizeof(atomicValue)>=4); - + printf("Check static initializer\n"); v=SDL_AtomicGet(&good); SDL_assert(v==42); - + SDL_assert(bad==42); - + printf("Test negative values\n"); SDL_AtomicSet(&good, -5); v=SDL_AtomicGet(&good); SDL_assert(v==-5); - + printf("Verify maximum value\n"); SDL_AtomicSet(&good, CountTo); v=SDL_AtomicGet(&good); SDL_assert(v==CountTo); - + printf("Test compare and exchange\n"); - + b=SDL_AtomicCAS(&good, 500, 43); SDL_assert(!b); /* no swap since CountTo!=500 */ v=SDL_AtomicGet(&good); SDL_assert(v==CountTo); /* ensure no swap */ - + b=SDL_AtomicCAS(&good, CountTo, 44); SDL_assert(!!b); /* will swap */ v=SDL_AtomicGet(&good); SDL_assert(v==44); - + printf("Test Add\n"); - + v=SDL_AtomicAdd(&good, 1); SDL_assert(v==44); v=SDL_AtomicGet(&good); SDL_assert(v==45); - + v=SDL_AtomicAdd(&good, 10); SDL_assert(v==45); v=SDL_AtomicGet(&good); SDL_assert(v==55); - + printf("Test Add (Negative values)\n"); - + v=SDL_AtomicAdd(&good, -20); SDL_assert(v==55); v=SDL_AtomicGet(&good); SDL_assert(v==35); - + v=SDL_AtomicAdd(&good, -50); /* crossing zero down */ SDL_assert(v==35); v=SDL_AtomicGet(&good); SDL_assert(v==-15); - + v=SDL_AtomicAdd(&good, 30); /* crossing zero up */ SDL_assert(v==-15); v=SDL_AtomicGet(&good); SDL_assert(v==15); - + printf("Reset before count down test\n"); SDL_AtomicSet(&good, CountTo); v=SDL_AtomicGet(&good); SDL_assert(v==CountTo); - + bad=CountTo; SDL_assert(bad==CountTo); - + printf("Counting down from %d, Expect %d remaining\n",CountTo,Expect); runAdder(); - + v=SDL_AtomicGet(&good); printf("Atomic %d Non-Atomic %d\n",v,bad); SDL_assert(v==Expect); @@ -599,7 +599,7 @@ static void RunFIFOTest(SDL_bool lock_free) Uint32 start, end; int i, j; int grand_total; - + printf("\nFIFO test---------------------------------------\n\n"); printf("Mode: %s\n", lock_free ? "LockFree" : "Mutex"); @@ -614,7 +614,7 @@ static void RunFIFOTest(SDL_bool lock_free) } start = SDL_GetTicks(); - + #ifdef TEST_SPINLOCK_FIFO /* Start a monitoring thread */ if (lock_free) { @@ -646,12 +646,12 @@ static void RunFIFOTest(SDL_bool lock_free) writerData[i].lock_free = lock_free; SDL_CreateThread(FIFO_Writer, name, &writerData[i]); } - + /* Wait for the writers */ while (SDL_AtomicGet(&writersRunning) > 0) { SDL_SemWait(writersDone); } - + /* Shut down the queue so readers exit */ queue.active = SDL_FALSE; @@ -661,14 +661,14 @@ static void RunFIFOTest(SDL_bool lock_free) } end = SDL_GetTicks(); - + SDL_DestroySemaphore(readersDone); SDL_DestroySemaphore(writersDone); if (!lock_free) { SDL_DestroyMutex(queue.mutex); } - + printf("Finished in %f sec\n", (end - start) / 1000.f); printf("\n"); |