24#ifndef _OD_INTERLOCKED_INCREMENT_H_
25#define _OD_INTERLOCKED_INCREMENT_H_
28#ifdef OD_POSIX_THREADS
35#ifndef TD_SINGLE_THREAD
38 #define __has_feature(x) 0
41#if defined(_MSC_VER) && (_M_IX86) && (_M_IX86 >= 400) && !defined(_WIN32_WCE)
44#pragma warning(disable:4035)
45#pragma warning(disable:4793)
46inline int OdInterlockedIncrement(
volatile int* dest)
56inline int OdInterlockedDecrement(
volatile int* dest)
68#elif (defined(_WIN32) || defined(_WIN64)) && !defined(ODA_WINDOWS_GCC)
70#define OdInterlockedIncrement(dest) InterlockedIncrement((LONG*)(dest))
71#define OdInterlockedDecrement(dest) InterlockedDecrement((LONG*)(dest))
72#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(ANDROID)
74inline int OdInterlockedExchangeAdd(
volatile int* dest,
int incr)
78 "lock; xaddl %0, (%1)"
80 :
"r" (dest),
"0" (incr)
84inline int OdInterlockedIncrement(
volatile int* dest)
86 return OdInterlockedExchangeAdd(dest, 1) + 1;
88inline int OdInterlockedDecrement(
volatile int* dest)
90 return OdInterlockedExchangeAdd(dest, -1) - 1;
92#elif defined(__GNUC__) && defined(__POWERPC__)
94inline int OdInterlockedExchangeAdd(
volatile int* dest,
int incr)
100 __asm__ __volatile__(
101 "0: lwarx %0, %3, %1\n"
103 " stwcx. %0, %3, %1\n"
107 :
"r"(dest),
"r"(incr),
"r"(zero)
108 :
"cr0",
"memory",
"r0");
112inline int OdInterlockedIncrement(
volatile int* dest)
114 return OdInterlockedExchangeAdd(dest, 1) + 1;
116inline int OdInterlockedDecrement(
volatile int* dest)
118 return OdInterlockedExchangeAdd(dest, -1) - 1;
120#elif defined(__APPLE__)
122#include <libkern/OSAtomic.h>
123inline int OdInterlockedIncrement(
volatile int* dest)
125 return OSAtomicIncrement32Barrier(dest);
127inline int OdInterlockedDecrement(
volatile int* dest)
129 return OSAtomicDecrement32Barrier(dest);
145#elif ( (defined(__GNUC__) && defined(__aarch64__)) || defined(__llvm__) || (defined(__clang__) && __has_feature(c_atomic)) ) && (__cplusplus >= 201103L)
151inline int OdInterlockedIncrement(
volatile int* dest)
153 return __atomic_fetch_add(dest, 1, std::memory_order_relaxed) + 1;
155inline int OdInterlockedDecrement(
volatile int* dest)
157 return __atomic_fetch_sub(dest, 1, std::memory_order_relaxed) - 1;
162#define TD_SINGLE_THREAD