diff options
Diffstat (limited to 'src/mbgl/util/atomic.hpp')
-rw-r--r-- | src/mbgl/util/atomic.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/mbgl/util/atomic.hpp b/src/mbgl/util/atomic.hpp new file mode 100644 index 0000000000..3f68bf46a5 --- /dev/null +++ b/src/mbgl/util/atomic.hpp @@ -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 |