Commit a40973f2 authored by Alexandre Julliard's avatar Alexandre Julliard

include: Add a number of 64-bit interlocked functions.

parent 71bef6c9
......@@ -193,22 +193,6 @@ static void spin_wait(int *counter)
}
}
#ifdef _WIN64
static size_t InterlockedIncrementSizeT(size_t volatile *dest)
{
size_t v;
do
{
v = *dest;
} while(InterlockedCompareExchange64((LONGLONG*)dest, v+1, v) != v);
return v+1;
}
#else
#define InterlockedIncrementSizeT(dest) InterlockedIncrement((LONG*)dest)
#endif
static void CALLBACK queue_push_finally(BOOL normal, void *ctx)
{
threadsafe_queue *queue = ctx;
......
......@@ -207,22 +207,6 @@ static void spin_wait(int *counter)
}
}
#ifdef _WIN64
static size_t InterlockedIncrementSizeT(size_t volatile *dest)
{
size_t v;
do
{
v = *dest;
} while(InterlockedCompareExchange64((LONGLONG*)dest, v+1, v) != v);
return v+1;
}
#else
#define InterlockedIncrementSizeT(dest) InterlockedIncrement((LONG*)dest)
#endif
static void CALLBACK queue_push_finally(BOOL normal, void *ctx)
{
threadsafe_queue *queue = ctx;
......
......@@ -6361,19 +6361,24 @@ typedef enum _PROCESS_MITIGATION_POLICY
#define BitScanReverse _BitScanReverse
#define InterlockedAdd _InlineInterlockedAdd
#define InterlockedAnd _InterlockedAnd
#define InterlockedAnd64 _InterlockedAnd64
#define InterlockedCompareExchange _InterlockedCompareExchange
#define InterlockedCompareExchange64 _InterlockedCompareExchange64
#define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
#define InterlockedDecrement _InterlockedDecrement
#define InterlockedDecrement16 _InterlockedDecrement16
#define InterlockedDecrement64 _InterlockedDecrement64
#define InterlockedExchange _InterlockedExchange
#define InterlockedExchangeAdd _InterlockedExchangeAdd
#define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
#define InterlockedExchangePointer _InterlockedExchangePointer
#define InterlockedIncrement _InterlockedIncrement
#define InterlockedIncrement16 _InterlockedIncrement16
#define InterlockedIncrement64 _InterlockedIncrement64
#define InterlockedOr _InterlockedOr
#define InterlockedOr64 _InterlockedOr64
#define InterlockedXor _InterlockedXor
#define InterlockedXor64 _InterlockedXor64
#ifdef _MSC_VER
......@@ -6407,33 +6412,88 @@ long _InterlockedOr(long volatile *,long);
long _InterlockedXor(long volatile *,long);
DECLSPEC_NORETURN void __fastfail(unsigned int);
static FORCEINLINE long InterlockedAdd( long volatile *dest, long val )
{
return InterlockedExchangeAdd( dest, val ) + val;
}
#if !defined(__i386__) || _MSC_VER >= 1600
#ifndef __i386__
#pragma intrinsic(_InterlockedAnd64)
#pragma intrinsic(_InterlockedCompareExchangePointer)
#pragma intrinsic(_InterlockedDecrement64)
#pragma intrinsic(_InterlockedExchangeAdd64)
#pragma intrinsic(_InterlockedExchangePointer)
void *_InterlockedCompareExchangePointer(void *volatile*,void*,void*);
void *_InterlockedExchangePointer(void *volatile*,void*);
#pragma intrinsic(_InterlockedIncrement64)
#pragma intrinsic(_InterlockedOr64)
#pragma intrinsic(_InterlockedXord64)
__int64 _InterlockedAnd64(__int64 volatile *, __int64);
void * _InterlockedCompareExchangePointer(void *volatile*,void*,void*);
__int64 _InterlockedDecrement64(__int64 volatile *);
__int64 _InterlockedExchangeAdd64(__int64 volatile *, __int64);
void * _InterlockedExchangePointer(void *volatile*,void*);
__int64 _InterlockedIncrement64(__int64 volatile *);
__int64 _InterlockedOr64(__int64 volatile *, __int64);
__int64 _InterlockedXor64(__int64 volatile *, __int64);
#else
static FORCEINLINE __int64 InterlockedAnd64( __int64 volatile *dest, __int64 val )
{
__int64 prev;
do prev = *dest; while (InterlockedCompareExchange64( dest, prev & val, prev ) != prev);
return prev;
}
static FORCEINLINE void * WINAPI InterlockedCompareExchangePointer( void *volatile *dest, void *xchg, void *compare )
{
return (void *)_InterlockedCompareExchange( (long volatile*)dest, (long)xchg, (long)compare );
}
static FORCEINLINE __int64 InterlockedExchangeAdd64( __int64 volatile *dest, __int64 val )
{
__int64 prev;
do prev = *dest; while (InterlockedCompareExchange64( dest, prev + val, prev ) != prev);
return prev;
}
static FORCEINLINE void * WINAPI InterlockedExchangePointer( void *volatile *dest, void *val )
{
return (void *)_InterlockedExchange( (long volatile*)dest, (long)val );
}
static FORCEINLINE __int64 InterlockedIncrement64( __int64 volatile *dest )
{
return InterlockedExchangeAdd64( dest, 1 ) + 1;
}
static FORCEINLINE __int64 InterlockedDecrement64( __int64 volatile *dest )
{
return InterlockedExchangeAdd64( dest, -1 ) - 1;
}
static FORCEINLINE __int64 InterlockedOr64( __int64 volatile *dest, __int64 val )
{
__int64 prev;
do prev = *dest; while (InterlockedCompareExchange64( dest, prev | val, prev ) != prev);
return prev;
}
static FORCEINLINE __int64 InterlockedXor64( __int64 volatile *dest, __int64 val )
{
__int64 prev;
do prev = *dest; while (InterlockedCompareExchange64( dest, prev ^ val, prev ) != prev);
return prev;
}
#endif /* __i386__ */
static FORCEINLINE long InterlockedAdd( long volatile *dest, long val )
{
return InterlockedExchangeAdd( dest, val ) + val;
}
static FORCEINLINE __int64 InterlockedAdd64( __int64 volatile *dest, __int64 val )
{
return InterlockedExchangeAdd64( dest, val ) + val;
}
#ifdef __i386__
static FORCEINLINE void MemoryBarrier(void)
......@@ -6444,10 +6504,7 @@ static FORCEINLINE void MemoryBarrier(void)
#elif defined(__x86_64__)
#pragma intrinsic(_InterlockedExchangeAdd64)
#pragma intrinsic(__faststorefence)
long long _InterlockedExchangeAdd64(long long volatile *, long long);
void __faststorefence(void);
static FORCEINLINE void MemoryBarrier(void)
......@@ -6464,10 +6521,6 @@ static FORCEINLINE void MemoryBarrier(void)
#elif defined(__aarch64__)
#pragma intrinsic(_InterlockedExchangeAdd64)
long long _InterlockedExchangeAdd64(long long volatile *, long long);
static FORCEINLINE void MemoryBarrier(void)
{
__dmb(_ARM64_BARRIER_SY);
......@@ -6494,11 +6547,21 @@ static FORCEINLINE LONG WINAPI InterlockedAdd( LONG volatile *dest, LONG val )
return __sync_add_and_fetch( dest, val );
}
static FORCEINLINE LONGLONG WINAPI InterlockedAdd64( LONGLONG volatile *dest, LONGLONG val )
{
return __sync_add_and_fetch( dest, val );
}
static FORCEINLINE LONG WINAPI InterlockedAnd( LONG volatile *dest, LONG val )
{
return __sync_fetch_and_and( dest, val );
}
static FORCEINLINE LONGLONG WINAPI InterlockedAnd64( LONGLONG volatile *dest, LONGLONG val )
{
return __sync_fetch_and_and( dest, val );
}
static FORCEINLINE LONG WINAPI InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
{
return __sync_val_compare_and_swap( dest, compare, xchg );
......@@ -6548,6 +6611,11 @@ static FORCEINLINE short WINAPI InterlockedIncrement16( short volatile *dest )
return __sync_add_and_fetch( dest, 1 );
}
static FORCEINLINE LONGLONG WINAPI InterlockedIncrement64( LONGLONG volatile *dest )
{
return __sync_add_and_fetch( dest, 1 );
}
static FORCEINLINE LONG WINAPI InterlockedDecrement( LONG volatile *dest )
{
return __sync_add_and_fetch( dest, -1 );
......@@ -6558,6 +6626,11 @@ static FORCEINLINE short WINAPI InterlockedDecrement16( short volatile *dest )
return __sync_add_and_fetch( dest, -1 );
}
static FORCEINLINE LONGLONG WINAPI InterlockedDecrement64( LONGLONG volatile *dest )
{
return __sync_add_and_fetch( dest, -1 );
}
static FORCEINLINE void * WINAPI InterlockedExchangePointer( void *volatile *dest, void *val )
{
void *ret;
......@@ -6578,11 +6651,21 @@ static FORCEINLINE LONG WINAPI InterlockedOr( LONG volatile *dest, LONG val )
return __sync_fetch_and_or( dest, val );
}
static FORCEINLINE LONGLONG WINAPI InterlockedOr64( LONGLONG volatile *dest, LONGLONG val )
{
return __sync_fetch_and_or( dest, val );
}
static FORCEINLINE LONG WINAPI InterlockedXor( LONG volatile *dest, LONG val )
{
return __sync_fetch_and_xor( dest, val );
}
static FORCEINLINE LONGLONG WINAPI InterlockedXor64( LONGLONG volatile *dest, LONGLONG val )
{
return __sync_fetch_and_xor( dest, val );
}
static FORCEINLINE void MemoryBarrier(void)
{
__sync_synchronize();
......@@ -6631,11 +6714,15 @@ static FORCEINLINE unsigned char InterlockedCompareExchange128( volatile __int64
#endif
#define InterlockedDecrementSizeT(a) InterlockeDecrement64((LONGLONG *)(a))
#define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)(a), (b))
#define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)(a))
#else /* _WIN64 */
#define InterlockedDecrementSizeT(a) InterlockeDecrement((LONG *)(a))
#define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)(a), (b))
#define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)(a))
#endif /* _WIN64 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment