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.
This commit is contained in:
committed by
Konstantin Käfer
parent
aa9adbb8f8
commit
66841bf7eb
@@ -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));
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user