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

Conflicts:
	Foundation/include/Poco/AtomicCounter.h
This commit is contained in:
Guenter Obiltschnig 2016-12-05 22:19:45 +01:00
parent feedbbbea5
commit 955f409177
2 changed files with 95 additions and 7 deletions

View File

@ -24,9 +24,6 @@
#if POCO_OS == POCO_OS_WINDOWS_NT
#include "Poco/UnWindows.h"
#elif POCO_OS == POCO_OS_MAC_OS_X
<<<<<<< HEAD
#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 || __WATCH_OS_VERSION_MAX_ALLOWED >= __WATCHOS_3_0
#ifndef POCO_HAVE_STD_ATOMICS
#define POCO_HAVE_STD_ATOMICS
@ -34,7 +31,6 @@
#else
#include <libkern/OSAtomic.h>
#endif
>>>>>>> c8aa273... more fixes related to GH #1453
#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
@ -45,6 +41,9 @@
#endif
#endif // POCO_OS
#include "Poco/Mutex.h"
#ifdef POCO_HAVE_STD_ATOMICS
#include <atomic>
#endif
namespace Poco {
@ -114,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;
@ -137,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
//

View File

@ -20,7 +20,48 @@
namespace Poco {
#if POCO_OS == POCO_OS_WINDOWS_NT
#if defined(POCO_HAVE_STD_ATOMICS)
//
// C++11 atomics
//
AtomicCounter::AtomicCounter():
_counter(0)
{
}
AtomicCounter::AtomicCounter(AtomicCounter::ValueType initialValue):
_counter(initialValue)
{
}
AtomicCounter::AtomicCounter(const AtomicCounter& counter):
_counter(counter.value())
{
}
AtomicCounter::~AtomicCounter()
{
}
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
{
_counter.store(counter._counter.load());
return *this;
}
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
{
_counter.store(value);
return *this;
}
#elif POCO_OS == POCO_OS_WINDOWS_NT
//
// Windows
//