From 974df74e0bca10a4a5168396161cb3beebae4206 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Wed, 23 Jan 2019 10:43:28 -0600 Subject: [PATCH] Use std::atomic if available --- NEWS.md | 2 ++ src/Makevars | 3 +++ src/callback_registry.cpp | 12 ++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 97cc6509..e8f55508 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,8 @@ * Fixed [issue #74](https://github.com/r-lib/later/issues/74): Using later with R at the terminal on POSIX could cause 100% CPU. This was caused by later accidentally provoking R to call its input handler continuously. [PR #76](https://github.com/r-lib/later/pull/76) +* Fixed [issue #73](https://github.com/r-lib/later/issues/73): Linking later on ARM failed because `boost::atomic` requires the `-lboost_atomic` flag. Now later tries to use `std::atomic` when available (when the compiler supports C++11), and falls back to `boost::atomic` if not. [PR #80](https://github.com/r-lib/later/pull/80) + ## later 0.7.5 * Fixed issue where the order of callbacks scheduled by native later::later could be nondeterministic if they are scheduled too quickly. This was because callbacks were sorted by the time at which they come due, which could be identical. Later now uses the order of insertion as a tiebreaker. [PR #69](https://github.com/r-lib/later/pull/69) diff --git a/src/Makevars b/src/Makevars index 21798bca..a379db1b 100644 --- a/src/Makevars +++ b/src/Makevars @@ -1,3 +1,6 @@ +# Use C++11 if available +CXX_STD=CXX11 + PKG_CPPFLAGS = -pthread PKG_LIBS = -pthread diff --git a/src/callback_registry.cpp b/src/callback_registry.cpp index c2263cdf..973f757b 100644 --- a/src/callback_registry.cpp +++ b/src/callback_registry.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -6,7 +5,16 @@ #include "callback_registry.h" #include "debug.h" -boost::atomic nextCallbackNum(0); +#if __cplusplus >= 201103L + #include + std::atomic nextCallbackNum(0); +#else + // Fall back to boost::atomic if std::atomic isn't available. We want to + // avoid boost::atomic when possible because on ARM, it requires the + // -lboost_atomic linker flag. (https://github.com/r-lib/later/issues/73) + #include + boost::atomic nextCallbackNum(0); +#endif Callback::Callback(Timestamp when, Task func) : when(when), func(func) { this->callbackNum = nextCallbackNum++;