Mercurial > sdl-ios-xcode
changeset 3200:ef2c029a3a9d
First draft of atomic operations code for GCC and linux.
author | Bob Pendleton <bob@pendleton.com> |
---|---|
date | Wed, 24 Jun 2009 20:20:57 +0000 |
parents | 3e1bf2b8bd81 |
children | c297230efc75 |
files | src/atomic/linux/SDL_atomic.c |
diffstat | 1 files changed, 25 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/atomic/linux/SDL_atomic.c Wed Jun 24 20:04:08 2009 +0000 +++ b/src/atomic/linux/SDL_atomic.c Wed Jun 24 20:20:57 2009 +0000 @@ -29,148 +29,147 @@ Uint32 SDL_AtomicExchange32(Uint32 * ptr, Uint32 value) { - return 0; + return __sync_lock_test_and_set(ptr, value); } SDL_bool SDL_AtomicCompareThenSet32(Uint32 * ptr, Uint32 oldvalue, Uint32 newvalue) { - return SDL_false; + return (SDL_bool)__sync_bool_compare_and_swap(ptr, oldvalue, newvalue); } SDL_bool SDL_AtomicTestThenSet32(Uint32 * ptr) { - return SDL_false; + return (SDL_bool)(0 == __sync_lock_test_and_set(ptr, 1)); } void SDL_AtomicClear32(Uint32 * ptr) { + __sync_lock_release(ptr); } Uint32 SDL_AtomicFetchThenIncrement32(Uint32 * ptr) { - return 0; + return __sync_fetch_and_add(ptr, 1); } Uint32 SDL_AtomicFetchThenDecrement32(Uint32 * ptr) { - return 0; + return __sync_fetch_and_sub(ptr, 1); } Uint32 SDL_AtomicFetchThenAdd32(Uint32 * ptr, Uint32 value) { - return 0; + return __sync_fetch_and_add(ptr, value); } Uint32 SDL_AtomicFetchThenSubtract32(Uint32 * ptr, Uint32 value) { - return 0; + return __sync_fetch_and_sub(ptr, value); } Uint32 SDL_AtomicIncrementThenFetch32(Uint32 * ptr) { - return 0; + return __sync_add_and_fetch(ptr, 1); } Uint32 SDL_AtomicDecrementThenFetch32(Uint32 * ptr) { - return 0; + return __sync_sub_and_fetch(ptr, 1); } Uint32 SDL_AtomicAddThenFetch32(Uint32 * ptr, Uint32 value) { - return 0; + return __sync_add_and_fetch(ptr, value); } Uint32 SDL_AtomicSubtractThenFetch32(Uint32 * ptr, Uint32 value) { - return 0; + return __sync_sub_and_fetch(ptr, value); } - #ifdef SDL_HAS_64BIT_TYPE Uint64 SDL_AtomicExchange64(Uint64 * ptr, Uint64 value) { - return 0; + return __sync_lock_test_and_set(ptr, value); } SDL_bool -SDL_AtomicCompareThenSet64(Uint64 * ptr, -Uint64 oldvalue, Uint64 newvalue) +SDL_AtomicCompareThenSet64(Uint64 * ptr, Uint64 oldvalue, Uint64 newvalue) { - return SDL_false; + return (SDL_bool)__sync_bool_compare_and_swap(ptr, oldvalue, newvalue); } SDL_bool SDL_AtomicTestThenSet64(Uint64 * ptr) { - return SDL_false; + return (SDL_bool)(0 == __sync_lock_test_and_set(ptr, 1)); } void SDL_AtomicClear64(Uint64 * ptr) { + __sync_lock_release(ptr); } Uint64 SDL_AtomicFetchThenIncrement64(Uint64 * ptr) { - return 0; + return __sync_fetch_and_add(ptr, 1); } Uint64 SDL_AtomicFetchThenDecrement64(Uint64 * ptr) { - return 0; + return __sync_fetch_and_sub(ptr, 1); } Uint64 SDL_AtomicFetchThenAdd64(Uint64 * ptr, Uint64 value) { - return 0; + return __sync_fetch_and_add(ptr, value); } Uint64 SDL_AtomicFetchThenSubtract64(Uint64 * ptr, Uint64 value) { - return 0; + return __sync_fetch_and_sub(ptr, value); } Uint64 SDL_AtomicIncrementThenFetch64(Uint64 * ptr) { - return 0; + return __sync_add_and_fetch(ptr, 1); } Uint64 SDL_AtomicDecrementThenFetch64(Uint64 * ptr) { - return 0; + return __sync_sub_and_fetch(ptr, 1); } Uint64 SDL_AtomicAddThenFetch64(Uint64 * ptr, Uint64 value) { - return 0; + return __sync_add_and_fetch(ptr, value); } Uint64 SDL_AtomicSubtractThenFetch64(Uint64 * ptr, Uint64 value) { - return 0; + return __sync_sub_and_fetch(ptr, value); } - #endif #endif