8 #ifndef _INC_cInterlockedVal_H
9 #define _INC_cInterlockedVal_H
10 #ifndef NO_PRAGMA_ONCE
21 #if defined(USE_64BIT) && defined(__GNUC__)
22 #define _SIZEOF_LONG 8
24 #define _SIZEOF_LONG 4
27 #if defined(_M_IX86) && (_MSC_VER >= 1000)
28 #pragma warning(disable:4035)
47 #define __synch_xg(x) ((struct __synch_xchg_INT32 *)(x))
69 :
"r" (pDest),
"r" (nValNew),
"a" (nValComp)
83 :
"q"(nValNew),
"m"(*
__synch_xg(pDest)),
"0"(nValComp)
87 #elif defined(_M_IX86)
90 MOV ecx, dword ptr[pDest]
91 MOV edx, dword ptr[nValNew]
92 MOV eax, dword ptr[nValComp]
93 LOCK CMPXCHG dword ptr[ecx], edx
97 INT32 nValPrev = *pDest;
98 if (nValPrev == nValComp)
104 #error "No implementation of InterlockedCompareExchange"
118 #if defined(__GNUC__)
119 __asm__ __volatile__(
"lock; xaddl %0, %1"
120 :
"=r" (lValNew),
"=m" (*pDest)
121 :
"0" (1),
"m" (*pDest));
128 lValNew = nValComp + 1;
136 #if defined(__GNUC__)
137 __asm__ __volatile__(
"lock; xaddl %0, %1"
138 :
"=r" (lValNew),
"=m" (*pDest)
139 :
"0" (-1),
"m" (*pDest));
146 lValNew = nValComp - 1;
200 "lock; cmpxchgq %1,%2"
202 :
"q"(nValNew),
"m"(*
__synch_xg(pDest)),
"0"(nValComp)
206 "lock; cmpxchg8b %2;"
214 INT64 nValPrev = *pDest;
215 if (nValPrev == nValComp)
221 #elif defined(_MSC_VER) && !defined(USE_64BIT)
240 INT64 nValPrev = *pDest;
241 if (nValPrev == nValComp)
247 #error "No implementation of InterlockedCompareExchange64"
257 #if defined(_MSC_VER) && !defined(USE_64BIT)
287 nValNew = nValComp + 1;
298 nValNew = nValComp - 1;
323 #pragma warning(default:4035)
328 namespace InterlockedN
338 template<
typename TYPE >
340 template<
typename TYPE >
342 template<
typename TYPE >
344 template<
typename TYPE >
346 template<
typename TYPE >
394 #define INTERLOCK_REMAP(T,TI) \
395 template<> inline T Increment<T>( T VOLATILE* pnValue ) noexcept \
396 { return (T) Increment<TI>( (TI VOLATILE*) pnValue); } \
397 template<> inline T Decrement<T>( T VOLATILE* pnValue ) noexcept \
398 { return (T) Decrement<TI>( (TI VOLATILE*) pnValue); } \
399 template<> inline T ExchangeAdd<T>( T VOLATILE* pnValue, T nValue ) noexcept \
400 { return (T) ExchangeAdd<TI>( (TI VOLATILE*) pnValue, (TI) nValue ); } \
401 template<> inline T Exchange<T>( T VOLATILE* pnValue, T nValue ) noexcept \
402 { return (T) Exchange<TI>( (TI VOLATILE*) pnValue,(TI)nValue); } \
403 template<> inline T CompareExchange<T>( T VOLATILE* pnValue, T nValue, T lComparand ) noexcept \
404 { return (T) CompareExchange<TI>( (TI VOLATILE*) pnValue, (TI)nValue, (TI)lComparand); }
415 #if ! defined(USE_INT64)
426 template<
typename TYPE = INTER32_t >
444 ASSERT((((UINT_PTR)&m_nValue) %
sizeof(
TYPE)) == 0);
485 inline TYPE operator ++() noexcept
490 inline TYPE operator --() noexcept
503 operator TYPE () const noexcept
532 template< typename
TYPE =
void >
543 operator TYPE* () noexcept
545 return (
TYPE*)(this->m_nValue);
547 operator const TYPE* ()
const noexcept
549 return (
const TYPE*)(this->m_nValue);
552 const cInterlockedPtr<TYPE>& operator = (
TYPE* pValNew)
571 cInterlockedInt& m_rCount;
576 , m_nCount(count.Inc())
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define _SIZEOF_PTR
bytes = sizeof(void*) for __DECL_ALIGN macro. Can't do sizeof(x). uintptr_t
Definition: Index.h:22
#define TYPE
Definition: StrT.cpp:38
#define VOLATILE
Definition: SysTypes.h:429
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define _SIZEOF_LONG
Definition: cInterlockedVal.h:24
#define _SIZEOF_INT
Definition: cInterlockedVal.h:20
#define INTERLOCK_REMAP(T, TI)
Definition: cInterlockedVal.h:394
#define __synch_xg(x)
Definition: cInterlockedVal.h:47
#define UNITTEST_FRIEND(n)
Define this in the class body to be unit tested. Allow the unit test to access private/protected stuf...
Definition: cUnitTestDecl.h:17
Definition: cInterlockedVal.h:565
cInterlockedInc(cInterlockedInt &count) noexcept
Definition: cInterlockedVal.h:574
int get_Count() const noexcept
Definition: cInterlockedVal.h:584
~cInterlockedInc() noexcept
Definition: cInterlockedVal.h:579
Definition: cInterlockedVal.h:428
bool SetIfEqual(TYPE nValue, TYPE lComparand=0) noexcept
Definition: cInterlockedVal.h:480
TYPE CompareExchange(TYPE nValue, TYPE lComparand=0) noexcept
Definition: cInterlockedVal.h:474
TYPE AddX(TYPE nValue) noexcept
Definition: cInterlockedVal.h:464
void IncV() noexcept
Definition: cInterlockedVal.h:451
TYPE Exchange(TYPE nValue) noexcept
Definition: cInterlockedVal.h:469
void DecV() noexcept
Definition: cInterlockedVal.h:459
void put_Value(TYPE nVal) noexcept
Definition: cInterlockedVal.h:499
cInterlockedVal(TYPE nValue=0) noexcept
Definition: cInterlockedVal.h:441
TYPE get_Value() const noexcept
Definition: cInterlockedVal.h:495
TYPE Inc() noexcept
Definition: cInterlockedVal.h:447
TYPE volatile m_nValue
This MUST be sizeof(TYPE) aligned?! __DECL_ALIGN(sizeof(TYPE)).
Definition: cInterlockedVal.h:438
TYPE Dec() noexcept
Definition: cInterlockedVal.h:455
INTER32_t CompareExchange< INTER32_t >(INTER32_t volatile *pnValue, INTER32_t nValue, INTER32_t lComparand) noexcept
Definition: cInterlockedVal.h:366
INT64 Decrement< INT64 >(INT64 volatile *pnValue) noexcept
Definition: cInterlockedVal.h:376
__DECL_IMPORT TYPE Decrement(TYPE volatile *pnValue) noexcept
__DECL_IMPORT TYPE Increment(TYPE volatile *pnValue) noexcept
INTER32_t Decrement< INTER32_t >(INTER32_t volatile *pnValue) noexcept
Definition: cInterlockedVal.h:354
INT64 Exchange< INT64 >(INT64 volatile *pnValue, INT64 nValue) noexcept
Definition: cInterlockedVal.h:384
__DECL_IMPORT TYPE ExchangeAdd(TYPE volatile *pnValue, TYPE nValue) noexcept
INTER32_t Exchange< INTER32_t >(INTER32_t volatile *pnValue, INTER32_t nValue) noexcept
Definition: cInterlockedVal.h:362
INT64 ExchangeAdd< INT64 >(INT64 volatile *pnValue, INT64 nValue) noexcept
Definition: cInterlockedVal.h:380
INTER32_t Increment< INTER32_t >(INTER32_t volatile *pnValue) noexcept
Definition: cInterlockedVal.h:350
__DECL_IMPORT TYPE Exchange(TYPE volatile *pnValue, TYPE nValue) noexcept
INT64 Increment< INT64 >(INT64 volatile *pnValue) noexcept
Definition: cInterlockedVal.h:372
__DECL_IMPORT TYPE CompareExchange(TYPE volatile *pnValue, TYPE nValue, TYPE lComparand) noexcept
INTER32_t ExchangeAdd< INTER32_t >(INTER32_t volatile *pnValue, INTER32_t nValue) noexcept
Definition: cInterlockedVal.h:358
INT64 CompareExchange< INT64 >(INT64 volatile *pnValue, INT64 nValue, INT64 lComparand) noexcept
Definition: cInterlockedVal.h:388
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
INT64 __cdecl _InterlockedExchange64(_Inout_ INT64 volatile *pDest, IN INT64 Value) noexcept
Definition: cInterlockedVal.h:302
INT32 INTER32_t
Interlock intrinsic type as INT32.
Definition: cInterlockedVal.h:44
INT64 __cdecl _InterlockedCompareExchange64(_Inout_ INT64 volatile *pDest, IN INT64 nValNew, IN INT64 nValComp) noexcept
Definition: cInterlockedVal.h:188
class __DECL_IMPORT __DECL_ALIGN(4) cInterlockedPtr typedef cInterlockedPtr cInterlockedPtrV
Definition: cInterlockedVal.h:533
INT64 __cdecl _InterlockedExchangeAdd64(_Inout_ INT64 volatile *pDest, IN INT64 Value) noexcept
Definition: cInterlockedVal.h:311
INT32 __cdecl InterlockedExchangeAdd(INT32 volatile *pDest, INT32 Value) noexcept
Definition: cInterlockedVal.h:160
typedef __DECL_ALIGN(4) cInterlockedVal< INT32 > cInterlockedInt32
INT32 __cdecl InterlockedDecrement(INT32 volatile *pDest) noexcept
Definition: cInterlockedVal.h:133
INT32 __cdecl InterlockedCompareExchange(INT32 volatile *pDest, INT32 nValNew, INT32 nValComp) noexcept
Definition: cInterlockedVal.h:49
bool InterlockedSetIfEqual(_Inout_ INT32 volatile *pDest, INT32 nValNew, INT32 nValComp) noexcept
Definition: cInterlockedVal.h:108
template class __DECL_IMPORT cInterlockedPtr< >
Definition: cInterlockedVal.h:593
INT32 __cdecl InterlockedIncrement(INT32 volatile *pDest) noexcept
Definition: cInterlockedVal.h:115
bool _InterlockedSetIfEqual64(_Inout_ INT64 volatile *pDest, INT64 nValNew, INT64 nValComp) noexcept
Definition: cInterlockedVal.h:251
INT64 __cdecl _InterlockedDecrement64(_Inout_ INT64 volatile *pDest) noexcept
Definition: cInterlockedVal.h:291
INT64 __cdecl _InterlockedIncrement64(_Inout_ INT64 volatile *pDest) noexcept
Definition: cInterlockedVal.h:280
INT32 __cdecl InterlockedExchange(INT32 volatile *pDest, INT32 Value) noexcept
Definition: cInterlockedVal.h:151
Definition: cInterlockedVal.h:46
INT32 a[4]
Definition: cInterlockedVal.h:46