diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-08-19 18:03:44 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-08-19 18:03:44 +0400 |
commit | cbfd2a8e62835544db750d8be834096e4e4f3a9d (patch) | |
tree | a976e520e00ba0e32e9d71a20a790be9f2564fd5 | |
parent | c79e175d9b4206183cb969442210e4be1dba40b2 (diff) |
Apparently sizeof(unsigned) is 4 bytes on both 32 and 64 bit platforms
For now assume sizeof(int) == 4 for all supported platforms, could be
changed in the future.
Added an assert to functions which depends on this this, so we'll
easily notice bad things happening.
-rw-r--r-- | intern/atomic/atomic_ops.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/intern/atomic/atomic_ops.h b/intern/atomic/atomic_ops.h index 0df5e0c4cb1..c064d92d260 100644 --- a/intern/atomic/atomic_ops.h +++ b/intern/atomic/atomic_ops.h @@ -29,6 +29,8 @@ #ifndef ATOMIC_OPS_H__ #define ATOMIC_OPS_H__ +#include <assert.h> + #if defined (__APPLE__) # include <libkern/OSAtomic.h> #elif defined(_MSC_VER) @@ -52,7 +54,7 @@ #if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) # define LG_SIZEOF_PTR 3 -# define LG_SIZEOF_INT 3 +# define LG_SIZEOF_INT 2 #else # define LG_SIZEOF_PTR 2 # define LG_SIZEOF_INT 2 @@ -251,6 +253,8 @@ atomic_sub_uint32(uint32_t *p, uint32_t x) ATOMIC_INLINE size_t atomic_add_z(size_t *p, size_t x) { + assert(sizeof(size_t) == 1 << LG_SIZEOF_PTR); + #if (LG_SIZEOF_PTR == 3) return ((size_t)atomic_add_uint64((uint64_t *)p, (uint64_t)x)); #elif (LG_SIZEOF_PTR == 2) @@ -261,6 +265,8 @@ atomic_add_z(size_t *p, size_t x) ATOMIC_INLINE size_t atomic_sub_z(size_t *p, size_t x) { + assert(sizeof(size_t) == 1 << LG_SIZEOF_PTR); + #if (LG_SIZEOF_PTR == 3) return ((size_t)atomic_add_uint64((uint64_t *)p, (uint64_t)-((int64_t)x))); @@ -275,6 +281,8 @@ atomic_sub_z(size_t *p, size_t x) ATOMIC_INLINE unsigned atomic_add_u(unsigned *p, unsigned x) { + assert(sizeof(unsigned) == 1 << LG_SIZEOF_INT); + #if (LG_SIZEOF_INT == 3) return ((unsigned)atomic_add_uint64((uint64_t *)p, (uint64_t)x)); #elif (LG_SIZEOF_INT == 2) @@ -285,6 +293,8 @@ atomic_add_u(unsigned *p, unsigned x) ATOMIC_INLINE unsigned atomic_sub_u(unsigned *p, unsigned x) { + assert(sizeof(unsigned) == 1 << LG_SIZEOF_INT); + #if (LG_SIZEOF_INT == 3) return ((unsigned)atomic_add_uint64((uint64_t *)p, (uint64_t)-((int64_t)x))); |