summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2018-06-12 19:17:16 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2018-06-12 19:22:14 +0300
commit313281454d553570cb1676bb4342cb183fb28150 (patch)
tree788864898a843891170a0281daa6547b36e83f77
parent9af5172f98a4319ba4d8d9d4cb7a24ac8bd9ea12 (diff)
downloadqtlocation-mapboxgl-upstream/tmpsantos-backend_scope_function.tar.gz
[core] Use a getter for the BackendScope static variableupstream/tmpsantos-backend_scope_function
Fix a static variable initialization issue when dynamic loading Mapbox GL Native.
-rw-r--r--src/mbgl/renderer/backend_scope.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/mbgl/renderer/backend_scope.cpp b/src/mbgl/renderer/backend_scope.cpp
index fafeaabb39..ad430961aa 100644
--- a/src/mbgl/renderer/backend_scope.cpp
+++ b/src/mbgl/renderer/backend_scope.cpp
@@ -4,12 +4,20 @@
#include <cassert>
-namespace mbgl {
+namespace {
+
+mbgl::util::ThreadLocal<mbgl::BackendScope>& currentScope() {
+ static mbgl::util::ThreadLocal<mbgl::BackendScope> backendScope;
+
+ return backendScope;
+}
+
+} // namespace
-static util::ThreadLocal<BackendScope> currentScope;
+namespace mbgl {
BackendScope::BackendScope(RendererBackend& backend_, ScopeType scopeType_)
- : priorScope(currentScope.get()),
+ : priorScope(currentScope().get()),
nextScope(nullptr),
backend(backend_),
scopeType(scopeType_) {
@@ -21,7 +29,7 @@ BackendScope::BackendScope(RendererBackend& backend_, ScopeType scopeType_)
activate();
- currentScope.set(this);
+ currentScope().set(this);
}
BackendScope::~BackendScope() {
@@ -30,11 +38,11 @@ BackendScope::~BackendScope() {
if (priorScope) {
priorScope->activate();
- currentScope.set(priorScope);
+ currentScope().set(priorScope);
assert(priorScope->nextScope == this);
priorScope->nextScope = nullptr;
} else {
- currentScope.set(nullptr);
+ currentScope().set(nullptr);
}
}
@@ -60,7 +68,7 @@ void BackendScope::deactivate() {
}
bool BackendScope::exists() {
- return currentScope.get();
+ return currentScope().get();
}
} // namespace mbgl