diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2018-06-12 19:17:16 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2018-06-13 17:13:13 +0300 |
commit | caecdc8482fee16694b3b7d5ba5cd963c07fceb0 (patch) | |
tree | 03378c1a61b39aa0be58357d74b4579bb59bcd4a /src/mbgl | |
parent | a8e79631684ac81181253089d78b5922b10903ec (diff) | |
download | qtlocation-mapboxgl-caecdc8482fee16694b3b7d5ba5cd963c07fceb0.tar.gz |
[core] Use a getter for the BackendScope static variable
Fix a static variable initialization issue when dynamic loading
Mapbox GL Native.
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/renderer/backend_scope.cpp | 22 |
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 |