2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

Move AtomicAdd/AtomicSet to hsUtils.

This commit is contained in:
Darryl Pogue
2012-03-10 17:49:22 -08:00
parent 26dc1fa120
commit 251cf02bd7
3 changed files with 28 additions and 37 deletions

View File

@ -250,3 +250,31 @@ void DebugMsg(const char fmt[], ...);
#else
#define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); break;
#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
}

View File

@ -314,20 +314,3 @@ void CLock::LeaveWrite () {
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);
}

View File

@ -50,26 +50,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#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