From a8b6b67dfeb79a2e7904a2aec6354161c4eb1b16 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Tue, 23 Jun 2015 20:08:30 +0300 Subject: [PATCH] Introduce the ThreadContext mbgl::Thread will keep a ThreadContext for each running instance in a thread_local so we don't need to lookup a man in the Environment every time we need some info about the current thread. This patch is moving the ::currentlyOn check used on Debug build from the Environment class to the ThreadContext. --- platform/default/sqlite_cache.cpp | 2 +- src/mbgl/map/map.cpp | 2 +- src/mbgl/map/map_context.cpp | 22 +++++----- src/mbgl/storage/default_file_source.cpp | 2 +- src/mbgl/style/style.cpp | 6 +-- src/mbgl/util/thread.hpp | 26 ++++++----- src/mbgl/util/thread_context.cpp | 34 +++++++++++++++ src/mbgl/util/thread_context.hpp | 55 ++++++++++++++++++++++++ src/mbgl/util/uv_detail.hpp | 4 ++ src/mbgl/util/worker.cpp | 3 +- test/miscellaneous/map_context.cpp | 2 +- test/miscellaneous/thread.cpp | 2 +- test/style/mock_file_source.cpp | 2 +- test/style/resource_loading.cpp | 2 +- 14 files changed, 128 insertions(+), 36 deletions(-) create mode 100644 src/mbgl/util/thread_context.cpp create mode 100644 src/mbgl/util/thread_context.hpp diff --git a/platform/default/sqlite_cache.cpp b/platform/default/sqlite_cache.cpp index 06d168ce4..a2d2c6815 100644 --- a/platform/default/sqlite_cache.cpp +++ b/platform/default/sqlite_cache.cpp @@ -62,7 +62,7 @@ std::string unifyMapboxURLs(const std::string &url) { using namespace mapbox::sqlite; SQLiteCache::SQLiteCache(const std::string& path_) - : thread(std::make_unique>("SQLite Cache", util::ThreadPriority::Low, path_)) { + : thread(std::make_unique>(util::ThreadContext{"SQLite Cache", util::ThreadType::Unknown, util::ThreadPriority::Low}, path_)) { } SQLiteCache::~SQLiteCache() = default; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 17bcd2989..c25d307c6 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -12,7 +12,7 @@ namespace mbgl { Map::Map(View& view, FileSource& fileSource, MapMode mode) : data(std::make_unique(view, mode)), - context(std::make_unique>("Map", util::ThreadPriority::Regular, view, fileSource, *data)) + context(std::make_unique>(util::ThreadContext{"Map", util::ThreadType::Map, util::ThreadPriority::Regular}, view, fileSource, *data)) { view.initialize(this); } diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 69d3c7e21..ecb9d8463 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -33,7 +33,7 @@ MapContext::MapContext(uv_loop_t* loop, View& view_, FileSource& fileSource, Map updated(static_cast(Update::Nothing)), asyncUpdate(std::make_unique(loop, [this] { update(); })), texturePool(std::make_unique()) { - assert(Environment::currentlyOn(ThreadType::Map)); + assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); asyncUpdate->unref(); @@ -108,7 +108,7 @@ void MapContext::setStyleJSON(const std::string& json, const std::string& base) } void MapContext::loadStyleJSON(const std::string& json, const std::string& base) { - assert(Environment::currentlyOn(ThreadType::Map)); + assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); style.reset(); style = std::make_unique