Add CachingHTTPFileSource::clearLoop()

So loop state can be cleaned up in the appropriate thread.
This is a hack; loop needs to be externalized from Map.

Fixes #686
This commit is contained in:
John Firebaugh
2014-12-04 12:09:27 -08:00
parent 16fe8e64c4
commit 36500b9f95
4 changed files with 27 additions and 19 deletions

View File

@@ -13,21 +13,6 @@ CachingHTTPFileSource::CachingHTTPFileSource(const std::string &path_)
: path(path_) {}
CachingHTTPFileSource::~CachingHTTPFileSource() {
if (hasLoop()) {
assert(thread_id == std::this_thread::get_id());
uv_messenger_stop(queue, [](uv_messenger_t *msgr) {
delete msgr;
});
util::ptr<BaseRequest> req;
// Send a cancel() message to all requests that we are still holding.
for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) {
if ((req = pair.second.lock())) {
req->cancel();
}
}
}
}
void CachingHTTPFileSource::setLoop(uv_loop_t* loop_) {
@@ -47,6 +32,26 @@ bool CachingHTTPFileSource::hasLoop() {
return loop;
}
void CachingHTTPFileSource::clearLoop() {
assert(thread_id == std::this_thread::get_id());
assert(loop);
uv_messenger_stop(queue, [](uv_messenger_t *msgr) {
delete msgr;
});
util::ptr<BaseRequest> req;
// Send a cancel() message to all requests that we are still holding.
for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) {
if ((req = pair.second.lock())) {
req->cancel();
}
}
store.reset();
}
void CachingHTTPFileSource::setBase(const std::string &value) {
assert(thread_id == std::this_thread::get_id());
base = value;