mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 19:25:53 +02:00
On Apple platforms, use std::atomic with MacOS 10.12 or iOS 10 SDK.
This commit is contained in:
@@ -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
|
||||
//
|
||||
|
Reference in New Issue
Block a user