mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Move sync_barrier to only used place
to remove `#include <windows.h>` from header file preventing compiling on windows
This commit is contained in:
parent
5893913922
commit
81e5bb924c
|
@ -3,64 +3,6 @@
|
|||
|
||||
#include "../system.h"
|
||||
|
||||
/*
|
||||
atomic_inc - should return the value after increment
|
||||
atomic_dec - should return the value after decrement
|
||||
atomic_compswap - should return the value before the eventual swap
|
||||
sync_barrier - creates a full hardware fence
|
||||
*/
|
||||
|
||||
#if defined(__GNUC__)
|
||||
|
||||
inline unsigned atomic_inc(volatile unsigned *pValue)
|
||||
{
|
||||
return __sync_add_and_fetch(pValue, 1);
|
||||
}
|
||||
|
||||
inline unsigned atomic_dec(volatile unsigned *pValue)
|
||||
{
|
||||
return __sync_add_and_fetch(pValue, -1);
|
||||
}
|
||||
|
||||
inline unsigned atomic_compswap(volatile unsigned *pValue, unsigned comperand, unsigned value)
|
||||
{
|
||||
return __sync_val_compare_and_swap(pValue, comperand, value);
|
||||
}
|
||||
|
||||
inline void sync_barrier()
|
||||
{
|
||||
__sync_synchronize();
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
inline unsigned atomic_inc(volatile unsigned *pValue)
|
||||
{
|
||||
return _InterlockedIncrement((volatile long *)pValue);
|
||||
}
|
||||
|
||||
inline unsigned atomic_dec(volatile unsigned *pValue)
|
||||
{
|
||||
return _InterlockedDecrement((volatile long *)pValue);
|
||||
}
|
||||
|
||||
inline unsigned atomic_compswap(volatile unsigned *pValue, unsigned comperand, unsigned value)
|
||||
{
|
||||
return _InterlockedCompareExchange((volatile long *)pValue, (long)value, (long)comperand);
|
||||
}
|
||||
|
||||
inline void sync_barrier()
|
||||
{
|
||||
MemoryBarrier();
|
||||
}
|
||||
#else
|
||||
#error missing atomic implementation for this compiler
|
||||
#endif
|
||||
|
||||
class semaphore
|
||||
{
|
||||
SEMAPHORE sem;
|
||||
|
|
|
@ -43,6 +43,25 @@ extern "C"
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
sync_barrier - creates a full hardware fence
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
inline void sync_barrier()
|
||||
{
|
||||
__sync_synchronize();
|
||||
}
|
||||
#elif defined(_MSC_VER)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
inline void sync_barrier()
|
||||
{
|
||||
MemoryBarrier();
|
||||
}
|
||||
#else
|
||||
#error missing atomic implementation for this compiler
|
||||
#endif
|
||||
|
||||
// ------------ CGraphicsBackend_Threaded
|
||||
|
||||
void CGraphicsBackend_Threaded::ThreadFunc(void *pUser)
|
||||
|
|
Loading…
Reference in a new issue