Commit 432fbfb5 authored by jselbie's avatar jselbie

quick fix clang

parent fa01c48a
......@@ -20,9 +20,14 @@
#ifdef ATOMICS_ARE_DEFINED
#if defined(i386) || defined(__i386) || defined(__i386__)
#define ATOMICS_USE_XADD
#endif
extern "C" unsigned int xadd_4(volatile void* pVal, unsigned int inc)
#ifdef ATOMICS_USE_XADD
unsigned int xadd_4(volatile void* pVal, unsigned int inc)
{
unsigned int result;
unsigned int* pValInt = (unsigned int*)pVal;
......@@ -34,36 +39,24 @@ extern "C" unsigned int xadd_4(volatile void* pVal, unsigned int inc)
:"memory" );
return (result);
}
extern "C" unsigned int __sync_add_and_fetch_4(volatile void* pVal, unsigned int inc)
{
return (xadd_4(pVal, inc) + inc);
}
extern "C" unsigned int __sync_sub_and_fetch_4(volatile void* pVal, unsigned int inc)
{
return (xadd_4(pVal, -inc) - inc);
}
extern "C" unsigned int __sync_fetch_and_add_4(volatile void* pVal, unsigned int inc)
int AtomicIncrement(int* pInt)
{
return xadd_4(pVal, inc);
COMPILE_TIME_ASSERT(sizeof(int)==4);
// InterlockedIncrement
unsigned int result = xadd_4(pInt, 1) + 1;
return (int)result;
}
extern "C" unsigned int __sync_fetch_and_sub_4(volatile void* pVal, unsigned int inc)
int AtomicDecrement(int* pInt)
{
return xadd_4(pVal, -inc);
// InterlockedDecrement
unsigned int result = xadd_4(pInt, -1) - 1;
return (int)result;
}
#ifdef __GNUC__
#pragma message "atomichelpers.cpp: Defining sync_add_and_fetch helpers for i386 compile"
#endif
#endif
#else
int AtomicIncrement(int* pInt)
{
......@@ -78,3 +71,9 @@ int AtomicDecrement(int* pInt)
return __sync_sub_and_fetch(pInt, 1);
}
#endif
......@@ -18,20 +18,6 @@
#ifndef ATOMICHELPERS_H
#define ATOMICHELPERS_H
typedef unsigned int (*xaddFunctionType)(volatile void*, unsigned int);
#if defined(i386) || defined(__i386__) || defined(__i386)
#define ATOMICS_ARE_DEFINED
extern "C" unsigned int xadd_4(volatile void* pVal, unsigned int inc);
extern "C" unsigned int __sync_add_and_fetch_4(volatile void* pVal, unsigned int inc);
extern "C" unsigned int __sync_sub_and_fetch_4(volatile void* pVal, unsigned int inc);
extern "C" unsigned int __sync_fetch_and_add_4(volatile void* pVal, unsigned int inc);
extern "C" unsigned int __sync_fetch_and_sub_4(volatile void* pVal, unsigned int inc);
#endif
int AtomicIncrement(int* pInt);
int AtomicDecrement(int* pInt);
......
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