[core] Naive atomic type for ARMv5
std::atomic<bool> is implemented lock free which doesn't work on ARMv5 and seems like the compiler is generating bogus code. This workaround is a naive implementation using regular mutexes.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
|
||||
@@ -26,7 +27,7 @@ public:
|
||||
static void Unsubscribe(util::AsyncTask* async);
|
||||
|
||||
private:
|
||||
static std::atomic<bool> online;
|
||||
static util::Atomic<bool> online;
|
||||
static std::mutex mtx;
|
||||
static std::set<util::AsyncTask*> observers;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/util.hpp>
|
||||
#include <mbgl/util/work_task.hpp>
|
||||
@@ -9,7 +10,6 @@
|
||||
#include <utility>
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
template <class Fn, class... Args>
|
||||
std::unique_ptr<AsyncRequest>
|
||||
invokeCancellable(Fn&& fn, Args&&... args) {
|
||||
auto flag = std::make_shared<std::atomic<bool>>();
|
||||
auto flag = std::make_shared<util::Atomic<bool>>();
|
||||
*flag = false;
|
||||
|
||||
auto tuple = std::make_tuple(std::move(args)...);
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
template <class Fn, class Cb, class... Args>
|
||||
std::unique_ptr<AsyncRequest>
|
||||
invokeWithCallback(Fn&& fn, Cb&& callback, Args&&... args) {
|
||||
auto flag = std::make_shared<std::atomic<bool>>();
|
||||
auto flag = std::make_shared<util::Atomic<bool>>();
|
||||
*flag = false;
|
||||
|
||||
// Create a lambda L1 that invokes another lambda L2 on the current RunLoop R, that calls
|
||||
@@ -114,7 +114,7 @@ private:
|
||||
template <class F, class P>
|
||||
class Invoker : public WorkTask {
|
||||
public:
|
||||
Invoker(F&& f, P&& p, std::shared_ptr<std::atomic<bool>> canceled_ = nullptr)
|
||||
Invoker(F&& f, P&& p, std::shared_ptr<util::Atomic<bool>> canceled_ = nullptr)
|
||||
: canceled(std::move(canceled_)),
|
||||
func(std::move(f)),
|
||||
params(std::move(p)) {
|
||||
@@ -148,7 +148,7 @@ private:
|
||||
}
|
||||
|
||||
std::recursive_mutex mutex;
|
||||
std::shared_ptr<std::atomic<bool>> canceled;
|
||||
std::shared_ptr<util::Atomic<bool>> canceled;
|
||||
|
||||
F func;
|
||||
P params;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "run_loop_impl.hpp"
|
||||
|
||||
#include <mbgl/util/async_task.hpp>
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -45,7 +45,7 @@ private:
|
||||
|
||||
// TODO: Use std::atomic_flag if we ever drop
|
||||
// support for ARMv5
|
||||
std::atomic<bool> queued;
|
||||
util::Atomic<bool> queued;
|
||||
std::function<void()> task;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
#include "jni.hpp"
|
||||
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
bool detach = false;
|
||||
|
||||
ALooper* loop = nullptr;
|
||||
std::atomic<bool> running;
|
||||
util::Atomic<bool> running;
|
||||
|
||||
std::recursive_mutex mtx;
|
||||
std::list<Runnable*> runnables;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <mbgl/geometry/binpack.hpp>
|
||||
#include <mbgl/text/glyph_store.hpp>
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
@@ -11,7 +12,6 @@
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
BinPack<uint16_t> bin;
|
||||
std::unordered_map<FontStack, std::map<uint32_t, GlyphValue>, FontStackHash> index;
|
||||
const std::unique_ptr<uint8_t[]> data;
|
||||
std::atomic<bool> dirty;
|
||||
util::Atomic<bool> dirty;
|
||||
mbgl::optional<gl::UniqueTexture> texture;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
#include <mbgl/renderer/render_pass.hpp>
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/mat4.hpp>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#define BUFFER_OFFSET_0 ((GLbyte*)nullptr)
|
||||
#define BUFFER_OFFSET(i) ((BUFFER_OFFSET_0) + (i))
|
||||
|
||||
@@ -50,7 +49,7 @@ public:
|
||||
virtual void swapRenderData() {}
|
||||
|
||||
protected:
|
||||
std::atomic<bool> uploaded;
|
||||
util::Atomic<bool> uploaded;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <mbgl/geometry/binpack.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
#include <mbgl/gl/object_store.hpp>
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
@@ -10,7 +11,6 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <set>
|
||||
#include <array>
|
||||
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
std::map<Key, Holder> images;
|
||||
std::set<std::string> uninitialized;
|
||||
std::unique_ptr<uint32_t[]> data;
|
||||
std::atomic<bool> dirty;
|
||||
util::Atomic<bool> dirty;
|
||||
bool fullUploadRequired = true;
|
||||
mbgl::optional<gl::UniqueTexture> texture;
|
||||
uint32_t filter = 0;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
std::atomic<bool> NetworkStatus::online(true);
|
||||
util::Atomic<bool> NetworkStatus::online(true);
|
||||
std::mutex NetworkStatus::mtx;
|
||||
std::set<util::AsyncTask *> NetworkStatus::observers;
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include <mbgl/map/mode.hpp>
|
||||
#include <mbgl/tile/tile_id.hpp>
|
||||
#include <mbgl/style/filter.hpp>
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -24,7 +24,7 @@ class BucketParameters {
|
||||
public:
|
||||
BucketParameters(const OverscaledTileID& tileID_,
|
||||
const GeometryTileLayer& layer_,
|
||||
const std::atomic<bool>& obsolete_,
|
||||
const util::Atomic<bool>& obsolete_,
|
||||
uintptr_t tileUID_,
|
||||
bool& partialParse_,
|
||||
SpriteStore& spriteStore_,
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
|
||||
const OverscaledTileID& tileID;
|
||||
const GeometryTileLayer& layer;
|
||||
const std::atomic<bool>& obsolete;
|
||||
const util::Atomic<bool>& obsolete;
|
||||
uintptr_t tileUID;
|
||||
bool& partialParse;
|
||||
SpriteStore& spriteStore;
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/text/glyph_store.hpp>
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/font_stack.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<bool> parsed;
|
||||
util::Atomic<bool> parsed;
|
||||
std::unique_ptr<AsyncRequest> req;
|
||||
GlyphStoreObserver* observer = nullptr;
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ TileWorker::TileWorker(const OverscaledTileID& id_,
|
||||
SpriteStore& spriteStore_,
|
||||
GlyphAtlas& glyphAtlas_,
|
||||
GlyphStore& glyphStore_,
|
||||
const std::atomic<bool>& obsolete_,
|
||||
const util::Atomic<bool>& obsolete_,
|
||||
const MapMode mode_)
|
||||
: id(id_),
|
||||
sourceID(std::move(sourceID_)),
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <mbgl/map/mode.hpp>
|
||||
#include <mbgl/tile/tile_id.hpp>
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/variant.hpp>
|
||||
#include <mbgl/util/ptr.hpp>
|
||||
@@ -12,7 +13,6 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <list>
|
||||
#include <atomic>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
SpriteStore&,
|
||||
GlyphAtlas&,
|
||||
GlyphStore&,
|
||||
const std::atomic<bool>&,
|
||||
const util::Atomic<bool>&,
|
||||
const MapMode);
|
||||
~TileWorker();
|
||||
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
SpriteStore& spriteStore;
|
||||
GlyphAtlas& glyphAtlas;
|
||||
GlyphStore& glyphStore;
|
||||
const std::atomic<bool>& obsolete;
|
||||
const util::Atomic<bool>& obsolete;
|
||||
const MapMode mode;
|
||||
|
||||
bool partialParse = false;
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include <mbgl/tile/tile_data.hpp>
|
||||
#include <mbgl/tile/tile_worker.hpp>
|
||||
#include <mbgl/text/placement_config.hpp>
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/feature.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -69,7 +69,7 @@ private:
|
||||
PlacementConfig targetConfig;
|
||||
|
||||
// Used to signal the worker that it should abandon parsing this tile as soon as possible.
|
||||
std::atomic<bool> obsolete { false };
|
||||
util::Atomic<bool> obsolete { false };
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
45
src/mbgl/util/atomic.hpp
Normal file
45
src/mbgl/util/atomic.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
// std::atomic<bool> is implemented lock free which
|
||||
// is not supported by ARMv5 but the code generated
|
||||
// seems to be using that and not working at all,
|
||||
// thus, this naive implementation using mutexes.
|
||||
#if defined(__ANDROID__) && defined(__ARM_ARCH_5TE__)
|
||||
|
||||
template <typename T>
|
||||
class Atomic {
|
||||
public:
|
||||
Atomic() = default;
|
||||
explicit Atomic(const T& data_) : data(data_) {}
|
||||
|
||||
void operator=(const T& other) {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
data = other;
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private:
|
||||
T data;
|
||||
mutable std::mutex mtx;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
template <typename T>
|
||||
using Atomic = std::atomic<T>;
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
|
||||
#include <mbgl/util/atomic.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/thread_context.hpp>
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
Reference in New Issue
Block a user