From 66841bf7eb0d85b5f7c38092e17b9cc16a1dc18a Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Sun, 15 Mar 2015 01:55:11 +0200 Subject: [PATCH] Add an ID to Environment Environment will now have an incremental unique ID to that will help distinguish between threads scoped to different Environments when logging. --- src/mbgl/map/environment.cpp | 13 ++++++++++++- src/mbgl/map/environment.hpp | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mbgl/map/environment.cpp b/src/mbgl/map/environment.cpp index 07bfab089..1aea5aa0c 100644 --- a/src/mbgl/map/environment.cpp +++ b/src/mbgl/map/environment.cpp @@ -3,6 +3,7 @@ #include +#include #include #include #include @@ -66,6 +67,11 @@ private: mutable std::mutex mtx; }; +unsigned makeEnvironmentID() { + static std::atomic id(0); + return id++; +} + ThreadInfoStore threadInfoStore; } // namespace @@ -80,7 +86,8 @@ Environment::Scope::~Scope() { threadInfoStore.unregisterThread(); } -Environment::Environment(FileSource& fs) : fileSource(fs), loop(uv_loop_new()) { +Environment::Environment(FileSource& fs) + : id(makeEnvironmentID()), fileSource(fs), loop(uv_loop_new()) { } Environment& Environment::Get() { @@ -102,6 +109,10 @@ std::string Environment::threadName() { return threadInfoStore.getThreadInfo().name; } +unsigned Environment::getID() const { + return id; +} + void Environment::requestAsync(const Resource& resource, std::function callback) { fileSource.request(resource, *this, std::move(callback)); diff --git a/src/mbgl/map/environment.hpp b/src/mbgl/map/environment.hpp index e5d5f6e8b..b631abf13 100644 --- a/src/mbgl/map/environment.hpp +++ b/src/mbgl/map/environment.hpp @@ -41,6 +41,7 @@ public: static bool currentlyOn(ThreadType); static std::string threadName(); + unsigned getID() const; void requestAsync(const Resource&, std::function); Request* request(const Resource&, std::function); void cancelRequest(Request*); @@ -49,6 +50,7 @@ public: void terminate(); private: + unsigned id; FileSource& fileSource; public: