blob: 3f68bf46a57dc9da2161bdc174b9569774e460de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
|