summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/map/backend_scope.hpp3
-rw-r--r--src/mbgl/map/backend_scope.cpp24
2 files changed, 19 insertions, 8 deletions
diff --git a/include/mbgl/map/backend_scope.hpp b/include/mbgl/map/backend_scope.hpp
index c13fb88ded..5a207e6ac4 100644
--- a/include/mbgl/map/backend_scope.hpp
+++ b/include/mbgl/map/backend_scope.hpp
@@ -10,7 +10,8 @@ public:
~BackendScope();
private:
- Backend* priorBackend;
+ BackendScope* priorScope;
+ BackendScope* nextScope;
Backend& backend;
};
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);
}
}