summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-03-15 01:55:11 +0200
committerKonstantin Käfer <mail@kkaefer.com>2015-03-18 12:51:33 +0100
commit66841bf7eb0d85b5f7c38092e17b9cc16a1dc18a (patch)
treed79d229bce8cf1dd32d62a4e0e5e8c08b71d635e /src
parentaa9adbb8f89e5ea573b8a494a25c769f7784f40b (diff)
downloadqtlocation-mapboxgl-66841bf7eb0d85b5f7c38092e17b9cc16a1dc18a.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/environment.cpp13
-rw-r--r--src/mbgl/map/environment.hpp2
2 files changed, 14 insertions, 1 deletions
diff --git a/src/mbgl/map/environment.cpp b/src/mbgl/map/environment.cpp
index 07bfab089c..1aea5aa0c9 100644
--- a/src/mbgl/map/environment.cpp
+++ b/src/mbgl/map/environment.cpp
@@ -3,6 +3,7 @@
#include <uv.h>
+#include <atomic>
#include <cassert>
#include <mutex>
#include <unordered_map>
@@ -66,6 +67,11 @@ private:
mutable std::mutex mtx;
};
+unsigned makeEnvironmentID() {
+ static std::atomic<unsigned> 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<void(const Response&)> callback) {
fileSource.request(resource, *this, std::move(callback));
diff --git a/src/mbgl/map/environment.hpp b/src/mbgl/map/environment.hpp
index e5d5f6e8b8..b631abf13d 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<void(const Response&)>);
Request* request(const Resource&, std::function<void(const Response&)>);
void cancelRequest(Request*);
@@ -49,6 +50,7 @@ public:
void terminate();
private:
+ unsigned id;
FileSource& fileSource;
public: