From 7d3c9338c99fb52cd9ec25867c9c4f45a24e7d32 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 20 Feb 2017 10:22:54 -0800 Subject: [core] Link BackendScopes in a list for additional assertions --- include/mbgl/map/backend_scope.hpp | 3 ++- src/mbgl/map/backend_scope.cpp | 24 +++++++++++++++++------- 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 #include +#include + namespace mbgl { -static util::ThreadLocal currentBackend; +static util::ThreadLocal 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); } } -- cgit v1.2.1