diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2017-09-25 11:40:50 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2017-09-25 11:40:50 +0300 |
commit | 1d8aebaa096fd5afc758a88f99862e74b5d6c7e0 (patch) | |
tree | 54a8549fdf4087664aeaea27de1b58479205fb2f /intern/atomic | |
parent | 01a3c6b204bfbe149dc2cc2278dd58f206af7ae2 (diff) |
Add an 'atomic cas' wrapper for pointers.
Avoids having to repeat obfuscating castings everywhere...
Diffstat (limited to 'intern/atomic')
-rw-r--r-- | intern/atomic/atomic_ops.h | 2 | ||||
-rw-r--r-- | intern/atomic/intern/atomic_ops_ext.h | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/intern/atomic/atomic_ops.h b/intern/atomic/atomic_ops.h index 72813c39ac2..38670be56fd 100644 --- a/intern/atomic/atomic_ops.h +++ b/intern/atomic/atomic_ops.h @@ -108,6 +108,8 @@ ATOMIC_INLINE unsigned int atomic_fetch_and_add_u(unsigned int *p, unsigned int ATOMIC_INLINE unsigned int atomic_fetch_and_sub_u(unsigned int *p, unsigned int x); ATOMIC_INLINE unsigned int atomic_cas_u(unsigned int *v, unsigned int old, unsigned int _new); +ATOMIC_INLINE void *atomic_cas_ptr(void **v, void *old, void *_new); + /* WARNING! Float 'atomics' are really faked ones, those are actually closer to some kind of spinlock-sync'ed operation, * which means they are only efficient if collisions are highly unlikely (i.e. if probability of two threads * working on the same pointer at the same time is very low). */ diff --git a/intern/atomic/intern/atomic_ops_ext.h b/intern/atomic/intern/atomic_ops_ext.h index 8d5f2e5dad7..34158a0b45e 100644 --- a/intern/atomic/intern/atomic_ops_ext.h +++ b/intern/atomic/intern/atomic_ops_ext.h @@ -180,6 +180,18 @@ ATOMIC_INLINE unsigned int atomic_cas_u(unsigned int *v, unsigned int old, unsig } /******************************************************************************/ +/* Pointer operations. */ + +ATOMIC_INLINE void *atomic_cas_ptr(void **v, void *old, void *_new) +{ +#if (LG_SIZEOF_PTR == 8) + return (void *)atomic_cas_uint64((uint64_t *)v, *(uint64_t *)&old, *(uint64_t *)&_new); +#elif (LG_SIZEOF_PTR == 4) + return (void *)atomic_cas_uint32((uint32_t *)v, *(uint32_t *)&old, *(uint32_t *)&_new); +#endif +} + +/******************************************************************************/ /* float operations. */ ATOMIC_INLINE float atomic_add_and_fetch_fl(float *p, const float x) |