diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2013-04-25 11:52:17 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2013-04-25 12:40:33 -0500 |
commit | eb63fda2e24d007e31742587984a30e086249d43 (patch) | |
tree | 79d98a9ec5fae1586ab777c80e3d4f164f03a578 /src/thread-utils.h | |
parent | b4117e19b7a968f8e6b878d81c58a462093cf1b3 (diff) | |
download | libgit2-eb63fda2e24d007e31742587984a30e086249d43.tar.gz |
git_atomic_ssize for 64-bit atomics only on 64-bit platforms
Diffstat (limited to 'src/thread-utils.h')
-rw-r--r-- | src/thread-utils.h | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/thread-utils.h b/src/thread-utils.h index 28ecd297e..49b5f3b5e 100644 --- a/src/thread-utils.h +++ b/src/thread-utils.h @@ -18,6 +18,8 @@ typedef struct { #endif } git_atomic; +#ifdef GIT_ARCH_64 + typedef struct { #if defined(GIT_WIN32) __int64 val; @@ -26,6 +28,18 @@ typedef struct { #endif } git_atomic64; +typedef git_atomic64 git_atomic_ssize; + +#define git_atomic_ssize_add git_atomic64_add + +#else + +typedef git_atomic git_atomic_ssize; + +#define git_atomic_ssize_add git_atomic_add + +#endif + GIT_INLINE(void) git_atomic_set(git_atomic *a, int val) { a->val = val; @@ -68,7 +82,7 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a) GIT_INLINE(int) git_atomic_add(git_atomic *a, int32_t addend) { #if defined(GIT_WIN32) - return _InterlockedExchangeAdd(&a->val, addend); + return InterlockedExchangeAdd(&a->val, addend); #elif defined(__GNUC__) return __sync_add_and_fetch(&a->val, addend); #else @@ -101,10 +115,12 @@ GIT_INLINE(void *) git___compare_and_swap( return (foundval == oldval) ? oldval : newval; } -GIT_INLINE(int) git_atomic64_add(git_atomic64 *a, int64_t addend) +#ifdef GIT_ARCH_64 + +GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend) { #if defined(GIT_WIN32) - return _InterlockedExchangeAdd64(&a->val, addend); + return InterlockedExchangeAdd64(&a->val, addend); #elif defined(__GNUC__) return __sync_add_and_fetch(&a->val, addend); #else @@ -112,6 +128,8 @@ GIT_INLINE(int) git_atomic64_add(git_atomic64 *a, int64_t addend) #endif } +#endif + #else #define git_thread unsigned int @@ -161,7 +179,9 @@ GIT_INLINE(void *) git___compare_and_swap( return oldval; } -GIT_INLINE(int) git_atomic64_add(git_atomic64 *a, int64_t addend) +#ifdef GIT_ARCH_64 + +GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend) { a->val += addend; return a->val; @@ -169,6 +189,8 @@ GIT_INLINE(int) git_atomic64_add(git_atomic64 *a, int64_t addend) #endif +#endif + /* Atomically replace oldval with newval * @return oldval if it was replaced or newval if it was not */ |