Intern/atomic: Adding atomic_load/store_ptr support.
We need to provide _ptr ones with _z ones on the API level. Reviewed By: Sergey Sharybin (sergey) Ref D15076
This commit is contained in:
parent
4669178fc3
commit
e37027634b
|
@ -124,6 +124,8 @@ ATOMIC_INLINE unsigned int atomic_fetch_and_sub_u(unsigned int *p, unsigned int
|
|||
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);
|
||||
ATOMIC_INLINE void *atomic_load_ptr(const void **v);
|
||||
ATOMIC_INLINE void atomic_store_ptr(void **p, void *v);
|
||||
|
||||
ATOMIC_INLINE float atomic_cas_float(float *v, float old, float _new);
|
||||
|
||||
|
|
|
@ -205,6 +205,24 @@ ATOMIC_INLINE void *atomic_cas_ptr(void **v, void *old, void *_new)
|
|||
#endif
|
||||
}
|
||||
|
||||
ATOMIC_INLINE void *atomic_load_ptr(const void **v)
|
||||
{
|
||||
#if (LG_SIZEOF_PTR == 8)
|
||||
return (void *)atomic_load_uint64((const uint64_t *)v);
|
||||
#elif (LG_SIZEOF_PTR == 4)
|
||||
return (void *)atomic_load_uint32((const uint32_t *)v);
|
||||
#endif
|
||||
}
|
||||
|
||||
ATOMIC_INLINE void atomic_store_ptr(void **p, void *v)
|
||||
{
|
||||
#if (LG_SIZEOF_PTR == 8)
|
||||
atomic_store_uint64((uint64_t *)p, (uint64_t)v);
|
||||
#elif (LG_SIZEOF_PTR == 4)
|
||||
atomic_store_uint32((uint32_t *)p, (uint32_t)v);
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* float operations. */
|
||||
ATOMIC_STATIC_ASSERT(sizeof(float) == sizeof(uint32_t), "sizeof(float) != sizeof(uint32_t)");
|
||||
|
|
|
@ -1060,6 +1060,25 @@ TEST(atomic, atomic_cas_ptr)
|
|||
}
|
||||
}
|
||||
|
||||
TEST(atomic, atomic_load_ptr)
|
||||
{
|
||||
{
|
||||
void *value = INT_AS_PTR(0x7f);
|
||||
void *dest = atomic_load_ptr(&value);
|
||||
EXPECT_EQ(dest, INT_AS_PTR(0x7f));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(atomic, atomic_store_ptr)
|
||||
{
|
||||
{
|
||||
void *value = INT_AS_PTR(0x7f);
|
||||
void *dest = nullptr;
|
||||
atomic_store_ptr(&dest, value);
|
||||
EXPECT_EQ(dest, INT_AS_PTR(0x7f));
|
||||
}
|
||||
}
|
||||
|
||||
#undef INT_AS_PTR
|
||||
|
||||
/** \} */
|
||||
|
|
Loading…
Reference in New Issue