summaryrefslogtreecommitdiff
path: root/src/mbgl/map/backend_scope.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/map/backend_scope.cpp')
-rw-r--r--src/mbgl/map/backend_scope.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/mbgl/map/backend_scope.cpp b/src/mbgl/map/backend_scope.cpp
index 302dfd70cf..98775ceadb 100644
--- a/src/mbgl/map/backend_scope.cpp
+++ b/src/mbgl/map/backend_scope.cpp
@@ -2,24 +2,34 @@
#include <mbgl/map/backend.hpp>
#include <mbgl/util/thread_local.hpp>
+#include <cassert>
+
namespace mbgl {
-static util::ThreadLocal<Backend> currentBackend;
+static util::ThreadLocal<BackendScope> currentScope;
BackendScope::BackendScope(Backend& backend_)
- : priorBackend(currentBackend.get()),
+ : priorScope(currentScope.get()),
+ nextScope(nullptr),
backend(backend_) {
+ if (priorScope) {
+ assert(priorScope->nextScope == nullptr);
+ priorScope->nextScope = this;
+ }
backend.activate();
- currentBackend.set(&backend);
+ currentScope.set(this);
}
BackendScope::~BackendScope() {
- if (priorBackend) {
- priorBackend->activate();
- currentBackend.set(priorBackend);
+ assert(nextScope == nullptr);
+ if (priorScope) {
+ priorScope->backend.activate();
+ currentScope.set(priorScope);
+ assert(priorScope->nextScope == this);
+ priorScope->nextScope = nullptr;
} else {
backend.deactivate();
- currentBackend.set(nullptr);
+ currentScope.set(nullptr);
}
}