Files
MapLibreParticleLab/src/mbgl/util/atomic.hpp
Thiago Marcos P. Santos b711979e32 [android] #5254 - fix ARMv5 support
Backported patches fixing ARMv5 support for issue #3985.
2016-06-06 23:31:51 +03:00

46 lines
846 B
C++

#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