Scope the Map thread to an Environment

Also, replace manual thread type checks with Environment::currentlyOn().
This commit is contained in:
Thiago Marcos P. Santos
2015-03-13 15:03:33 +02:00
committed by Konstantin Käfer
parent b52aab5f7c
commit b5facd35bc
4 changed files with 35 additions and 59 deletions

View File

@@ -102,25 +102,17 @@ std::string Environment::threadName() {
return threadInfoStore.getThreadInfo().name;
}
void Environment::setup() {
mapThread = std::this_thread::get_id();
}
bool Environment::inMapThread() const {
return std::this_thread::get_id() == mapThread;
}
void Environment::requestAsync(const Resource &resource, std::function<void(const Response &)> callback) {
fileSource.request(resource, *this, std::move(callback));
}
Request *Environment::request(const Resource &resource, std::function<void(const Response &)> callback) {
assert(inMapThread());
assert(currentlyOn(ThreadType::Map));
return fileSource.request(resource, loop, *this, std::move(callback));
}
void Environment::cancelRequest(Request *req) {
assert(inMapThread());
assert(currentlyOn(ThreadType::Map));
fileSource.cancel(req);
}