From aa9adbb8f89e5ea573b8a494a25c769f7784f40b Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Fri, 13 Mar 2015 19:04:55 +0200 Subject: Scope the Tile worker thread to an Environment We are also removing the code that is passing the Environment around and instead, we get now the Environment in the TileData using Environment::Get(). When processing the job, the work will be temporally registered to the Environment as "TileWorker_0/0/0" which can be used for logging in the future. At the end of the job, it gets unregistered automatically from the Environment. --- .clang-format | 4 ++-- src/mbgl/map/environment.cpp | 12 +++++++----- src/mbgl/map/environment.hpp | 13 +++++++------ src/mbgl/map/live_tile_data.cpp | 5 ++--- src/mbgl/map/live_tile_data.hpp | 3 +-- src/mbgl/map/map.cpp | 2 +- src/mbgl/map/raster_tile_data.cpp | 4 ++-- src/mbgl/map/raster_tile_data.hpp | 2 +- src/mbgl/map/source.cpp | 23 +++++++++-------------- src/mbgl/map/source.hpp | 4 ++-- src/mbgl/map/tile_data.cpp | 7 ++++--- src/mbgl/map/tile_data.hpp | 4 ++-- src/mbgl/map/vector_tile_data.cpp | 5 ++--- src/mbgl/map/vector_tile_data.hpp | 3 +-- 14 files changed, 43 insertions(+), 48 deletions(-) diff --git a/.clang-format b/.clang-format index 109b562b59..ff0f39e73b 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,7 @@ Standard: Cpp11 IndentWidth: 4 AccessModifierOffset: -4 UseTab: Never -BinPackParameters: true +BinPackParameters: false AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AllowShortBlocksOnASingleLine: false @@ -10,7 +10,7 @@ AllowShortFunctionsOnASingleLine: false ConstructorInitializerAllOnOneLineOrOnePerLine: true AlwaysBreakTemplateDeclarations: true NamespaceIndentation: None -PointerBindsToType: false +PointerBindsToType: true SpacesInParentheses: false BreakBeforeBraces: Attach ColumnLimit: 100 diff --git a/src/mbgl/map/environment.cpp b/src/mbgl/map/environment.cpp index 98cf2d353e..07bfab089c 100644 --- a/src/mbgl/map/environment.cpp +++ b/src/mbgl/map/environment.cpp @@ -35,7 +35,7 @@ public: // FIXME: We should never need to overwrite a thread here and we only allow // this today because on the Static mode, the Map thread and the Main thread // are same. Replace this with emplace() when this gets fixed. - threadSet[std::this_thread::get_id()] = ThreadInfo{env, type, name}; + threadSet[std::this_thread::get_id()] = ThreadInfo{ env, type, name }; } void unregisterThread() { @@ -80,7 +80,7 @@ Environment::Scope::~Scope() { threadInfoStore.unregisterThread(); } -Environment::Environment(FileSource &fs) : fileSource(fs), loop(uv_loop_new()) { +Environment::Environment(FileSource& fs) : fileSource(fs), loop(uv_loop_new()) { } Environment& Environment::Get() { @@ -102,16 +102,18 @@ std::string Environment::threadName() { return threadInfoStore.getThreadInfo().name; } -void Environment::requestAsync(const Resource &resource, std::function callback) { +void Environment::requestAsync(const Resource& resource, + std::function callback) { fileSource.request(resource, *this, std::move(callback)); } -Request *Environment::request(const Resource &resource, std::function callback) { +Request* Environment::request(const Resource& resource, + std::function callback) { assert(currentlyOn(ThreadType::Map)); return fileSource.request(resource, loop, *this, std::move(callback)); } -void Environment::cancelRequest(Request *req) { +void Environment::cancelRequest(Request* req) { assert(currentlyOn(ThreadType::Map)); fileSource.cancel(req); } diff --git a/src/mbgl/map/environment.hpp b/src/mbgl/map/environment.hpp index 97813d3589..e5d5f6e8b8 100644 --- a/src/mbgl/map/environment.hpp +++ b/src/mbgl/map/environment.hpp @@ -20,6 +20,7 @@ enum class ThreadType : uint8_t { Unknown = 0, Main = 1 << 0, Map = 1 << 1, + TileWorker = 1 << 2, }; class Environment final : private util::noncopyable { @@ -33,25 +34,25 @@ public: std::thread::id id; }; - Environment(FileSource &); + Environment(FileSource&); static Environment& Get(); static bool inScope(); static bool currentlyOn(ThreadType); static std::string threadName(); - void requestAsync(const Resource &, std::function); - Request *request(const Resource &, std::function); - void cancelRequest(Request *); + void requestAsync(const Resource&, std::function); + Request* request(const Resource&, std::function); + void cancelRequest(Request*); // Request to terminate the environment. void terminate(); private: - FileSource &fileSource; + FileSource& fileSource; public: - uv_loop_t *const loop; + uv_loop_t* const loop; }; } diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp index 92777f67f0..192efb7dcf 100644 --- a/src/mbgl/map/live_tile_data.cpp +++ b/src/mbgl/map/live_tile_data.cpp @@ -15,10 +15,9 @@ LiveTileData::LiveTileData(Tile::ID const& id_, GlyphStore& glyphStore_, SpriteAtlas& spriteAtlas_, util::ptr sprite_, - const SourceInfo& source_, - Environment& env_) + const SourceInfo& source_) : VectorTileData::VectorTileData(id_, mapMaxZoom, style_, glyphAtlas_, glyphStore_, - spriteAtlas_, sprite_, source_, env_), + spriteAtlas_, sprite_, source_), annotationManager(annotationManager_) { // live features are always ready state = State::loaded; diff --git a/src/mbgl/map/live_tile_data.hpp b/src/mbgl/map/live_tile_data.hpp index 6b9d0a047a..7874d6ff55 100644 --- a/src/mbgl/map/live_tile_data.hpp +++ b/src/mbgl/map/live_tile_data.hpp @@ -17,8 +17,7 @@ public: GlyphStore&, SpriteAtlas&, util::ptr, - const SourceInfo&, - Environment&); + const SourceInfo&); ~LiveTileData(); void parse() override; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 7af3b54ded..22e6cbcebb 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -694,7 +694,7 @@ void Map::updateSources(const util::ptr &group) { void Map::updateTiles() { assert(Environment::currentlyOn(ThreadType::Map)); for (const auto &source : activeSources) { - source->source->update(*this, *env, getWorker(), style, *glyphAtlas, *glyphStore, + source->source->update(*this, getWorker(), style, *glyphAtlas, *glyphStore, *spriteAtlas, getSprite(), *texturePool, [this]() { assert(Environment::currentlyOn(ThreadType::Map)); triggerUpdate(); diff --git a/src/mbgl/map/raster_tile_data.cpp b/src/mbgl/map/raster_tile_data.cpp index 4cd7fc2b5e..b8862e6dd8 100644 --- a/src/mbgl/map/raster_tile_data.cpp +++ b/src/mbgl/map/raster_tile_data.cpp @@ -5,8 +5,8 @@ using namespace mbgl; RasterTileData::RasterTileData(Tile::ID const &id_, TexturePool &texturePool, - const SourceInfo &source_, Environment &env_) - : TileData(id_, source_, env_), bucket(texturePool, layout) { + const SourceInfo &source_) + : TileData(id_, source_), bucket(texturePool, layout) { } RasterTileData::~RasterTileData() { diff --git a/src/mbgl/map/raster_tile_data.hpp b/src/mbgl/map/raster_tile_data.hpp index 2413e13fb0..76bc1bb5aa 100644 --- a/src/mbgl/map/raster_tile_data.hpp +++ b/src/mbgl/map/raster_tile_data.hpp @@ -17,7 +17,7 @@ class RasterTileData : public TileData { friend class TileParser; public: - RasterTileData(Tile::ID const &id, TexturePool &, const SourceInfo &, Environment &); + RasterTileData(Tile::ID const &id, TexturePool &, const SourceInfo &); ~RasterTileData(); void parse() override; diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index b13a76c205..3036342d78 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -155,7 +155,7 @@ TileData::State Source::hasTile(const Tile::ID& id) { return TileData::State::invalid; } -TileData::State Source::addTile(Map &map, Environment &env, uv::worker &worker, +TileData::State Source::addTile(Map &map, uv::worker &worker, util::ptr