summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-02-20 10:22:54 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-20 12:04:21 -0800
commit7d3c9338c99fb52cd9ec25867c9c4f45a24e7d32 (patch)
tree2031c4afca8936ff5cc0ad68872516304377a2f1
parent773f330774db50ea82d2eb2e59b4250d67d7e4dc (diff)
downloadqtlocation-mapboxgl-7d3c9338c99fb52cd9ec25867c9c4f45a24e7d32.tar.gz
[core] Link BackendScopes in a list for additional assertions
-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);
}
}