Skip to content

Commit

Permalink
Merge pull request #80 from r-lib/fix-atomic
Browse files Browse the repository at this point in the history
Use std::atomic if available
  • Loading branch information
wch authored Jan 24, 2019
2 parents 7dc879a + 974df74 commit 5e3a07c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Use C++11 if available
CXX_STD=CXX11

PKG_CPPFLAGS = -pthread
PKG_LIBS = -pthread

Expand Down
12 changes: 10 additions & 2 deletions src/callback_registry.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#include <boost/atomic.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <vector>
#include "callback_registry.h"
#include "debug.h"

boost::atomic<uint64_t> nextCallbackNum(0);
#if __cplusplus >= 201103L
#include <atomic>
std::atomic<uint64_t> 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.hpp>
boost::atomic<uint64_t> nextCallbackNum(0);
#endif

Callback::Callback(Timestamp when, Task func) : when(when), func(func) {
this->callbackNum = nextCallbackNum++;
Expand Down

0 comments on commit 5e3a07c

Please sign in to comment.