Browse Source

Move AtomicAdd/AtomicSet to hsUtils.

Darryl Pogue 13 years ago
parent
commit
251cf02bd7
  1. 28
      Sources/Plasma/CoreLib/hsUtils.h
  2. 17
      Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp
  3. 20
      Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h

28
Sources/Plasma/CoreLib/hsUtils.h

@ -250,3 +250,31 @@ void DebugMsg(const char fmt[], ...);
#else #else
#define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); break; #define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); break;
#endif #endif
/*****************************************************************************
*
* Atomic Operations
*
***/
// *value += increment; return original value of *value; thread safe
long AtomicAdd(long* value, long increment) {
#ifdef HS_BUILD_FOR_WIN32
return InterlockedExchangeAdd(value, increment);
#elif HS_BUILD_FOR_UNIX
return __sync_fetch_and_add(value, increment);
#else
#error "No Atomic Set support on this architecture"
#endif
}
// *value = value; return original value of *value; thread safe
long AtomicSet(long* value, long set) {
#ifdef HS_BUILD_FOR_WIN32
return InterlockedExchange(value, set);
#elif HS_BUILD_FOR_UNIX
return __sync_lock_test_and_set(value, set);
#else
#error "No Atomic Set support on this architecture"
#endif
}

17
Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp

@ -314,20 +314,3 @@ void CLock::LeaveWrite () {
LeaveSpinLock(&m_spinLock); LeaveSpinLock(&m_spinLock);
} }
/****************************************************************************
*
* Exported functions
*
***/
//===========================================================================
long AtomicAdd (long * value, long increment) {
return InterlockedExchangeAdd(value, increment);
}
//===========================================================================
long AtomicSet (long * value, long set) {
return InterlockedExchange(value, set);
}

20
Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h

@ -50,26 +50,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "Pch.h" #include "Pch.h"
/****************************************************************************
*
* Atomic operations
*
***/
// *value += increment; return original value of *value; thread safe
long AtomicAdd (long * value, long increment);
// *value = value; return original value of *value; thread safe
long AtomicSet (long * value, long set);
#define ATOMIC_ONCE(code) { \
static long s_count = 1; \
if (AtomicSet(&s_count, 0)) \
code; \
} //
/**************************************************************************** /****************************************************************************
* *
* CLock * CLock

Loading…
Cancel
Save