version 1.2, 2015/04/20 18:10:13
|
version 1.3, 2015/04/20 18:19:52
|
|
|
*/ | */ |
| |
#include "atomic.h" | #include "atomic.h" |
#include <base/atomic.h> |
#include <pal/atomic.h> |
| |
MI_BEGIN_NAMESPACE | MI_BEGIN_NAMESPACE |
| |
|
|
// | // |
//============================================================================== | //============================================================================== |
| |
inline AtomicInt& AtomicRef(AtomicType& x) |
|
{ |
|
return *((AtomicInt*)&x); |
|
} |
|
|
|
inline const AtomicInt& AtomicRef(const AtomicType& x) |
|
{ |
|
return *((const AtomicInt*)&x); |
|
} |
|
|
|
unsigned int AtomicGet(const AtomicType& x) | unsigned int AtomicGet(const AtomicType& x) |
{ | { |
return AtomicRef(x); |
return (unsigned int)Atomic_Read((ptrdiff_t*)&x.__opaque); |
} | } |
| |
void AtomicSet(AtomicType& x, unsigned int n) | void AtomicSet(AtomicType& x, unsigned int n) |
{ | { |
AtomicRef(x) = n; |
*((ptrdiff_t*)&x.__opaque) = (ptrdiff_t)n; |
} | } |
| |
void AtomicInc(AtomicType& x) | void AtomicInc(AtomicType& x) |
{ | { |
::AtomicInc(&AtomicRef(x)); |
Atomic_Inc((ptrdiff_t*)&x.__opaque); |
} | } |
| |
bool AtomicDec(AtomicType& x) | bool AtomicDec(AtomicType& x) |
{ | { |
return ::AtomicDec(&AtomicRef(x)) ? true : false; |
return Atomic_Dec((ptrdiff_t*)&x.__opaque) == 0 ? true : false; |
} | } |
| |
MI_END_NAMESPACE | MI_END_NAMESPACE |