summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-11-13 14:00:13 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-11-16 12:25:46 -0800
commit2eb0203bf43e635b756bbf1322c53b8d299d4b37 (patch)
treea1f5570959168cf04e6c2ab366313494f8834827
parent6f881977eb2e8e15ffa6edc1b4eed4dda9b6fe71 (diff)
downloadqtlocation-mapboxgl-2eb0203bf43e635b756bbf1322c53b8d299d4b37.tar.gz
[core] Cancelled flag needs to be atomic; it is read from multiple threads
-rw-r--r--src/mbgl/util/run_loop.hpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/mbgl/util/run_loop.hpp b/src/mbgl/util/run_loop.hpp
index 5bf3551e57..6113ac2215 100644
--- a/src/mbgl/util/run_loop.hpp
+++ b/src/mbgl/util/run_loop.hpp
@@ -10,6 +10,7 @@
#include <utility>
#include <queue>
#include <mutex>
+#include <atomic>
namespace mbgl {
namespace util {
@@ -45,7 +46,7 @@ public:
template <class Fn, class... Args>
std::unique_ptr<WorkRequest>
invokeCancellable(Fn&& fn, Args&&... args) {
- auto flag = std::make_shared<bool>();
+ auto flag = std::make_shared<std::atomic<bool>>();
*flag = false;
auto tuple = std::make_tuple(std::move(args)...);
@@ -64,7 +65,7 @@ public:
template <class Fn, class Cb, class... Args>
std::unique_ptr<WorkRequest>
invokeWithCallback(Fn&& fn, Cb&& callback, Args&&... args) {
- auto flag = std::make_shared<bool>();
+ auto flag = std::make_shared<std::atomic<bool>>();
*flag = false;
// Create a lambda L1 that invokes another lambda L2 on the current RunLoop R, that calls
@@ -100,7 +101,7 @@ private:
template <class F, class P>
class Invoker : public WorkTask {
public:
- Invoker(F&& f, P&& p, std::shared_ptr<bool> canceled_ = nullptr)
+ Invoker(F&& f, P&& p, std::shared_ptr<std::atomic<bool>> canceled_ = nullptr)
: canceled(canceled_),
func(std::move(f)),
params(std::move(p)) {
@@ -134,7 +135,7 @@ private:
}
std::recursive_mutex mutex;
- std::shared_ptr<bool> canceled;
+ std::shared_ptr<std::atomic<bool>> canceled;
F func;
P params;