On Apple platforms, use std::atomic with MacOS 10.12 or iOS 10 SDK.

This commit is contained in:
Guenter Obiltschnig
2016-12-05 22:19:45 +01:00
parent 8572c2d8c9
commit 19c0b38bf8
2 changed files with 102 additions and 4 deletions

View File

@@ -24,7 +24,13 @@
#if POCO_OS == POCO_OS_WINDOWS_NT
#include "Poco/UnWindows.h"
#elif POCO_OS == POCO_OS_MAC_OS_X
#include <libkern/OSAtomic.h>
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_12 || __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 || __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_10_0 || defined(__WATCH_OS_VERSION_MAX_ALLOWED)
#ifndef POCO_HAVE_STD_ATOMICS
#define POCO_HAVE_STD_ATOMICS
#endif
#else
#include <libkern/OSAtomic.h>
#endif
#elif ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2) || __GNUC__ > 4) && (defined(__x86_64__) || defined(__i386__))
#if !defined(POCO_HAVE_GCC_ATOMICS) && !defined(POCO_NO_GCC_ATOMICS)
#define POCO_HAVE_GCC_ATOMICS
@@ -35,6 +41,9 @@
#endif
#endif // POCO_OS
#include "Poco/Mutex.h"
#ifdef POCO_HAVE_STD_ATOMICS
#include <atomic>
#endif
namespace Poco {
@@ -104,7 +113,9 @@ public:
/// Returns true if the counter is zero, false otherwise.
private:
#if POCO_OS == POCO_OS_WINDOWS_NT
#if defined(POCO_HAVE_STD_ATOMICS)
typedef std::atomic<int> ImplType;
#elif POCO_OS == POCO_OS_WINDOWS_NT
typedef volatile LONG ImplType;
#elif POCO_OS == POCO_OS_MAC_OS_X
typedef int32_t ImplType;
@@ -127,7 +138,53 @@ private:
//
#if POCO_OS == POCO_OS_WINDOWS_NT
#if defined(POCO_HAVE_STD_ATOMICS)
//
// C++11 atomics
//
inline AtomicCounter::operator AtomicCounter::ValueType () const
{
return _counter.load();
}
inline AtomicCounter::ValueType AtomicCounter::value() const
{
return _counter.load();
}
inline AtomicCounter::ValueType AtomicCounter::operator ++ () // prefix
{
return ++_counter;
}
inline AtomicCounter::ValueType AtomicCounter::operator ++ (int) // postfix
{
return _counter++;
}
inline AtomicCounter::ValueType AtomicCounter::operator -- () // prefix
{
return --_counter;
}
inline AtomicCounter::ValueType AtomicCounter::operator -- (int) // postfix
{
return _counter--;
}
inline bool AtomicCounter::operator ! () const
{
return _counter.load() == 0;
}
#elif POCO_OS == POCO_OS_WINDOWS_NT
//
// Windows
//