Make subscribe and unsubscribe parallel

This commit is contained in:
John Firebaugh
2015-04-16 17:57:41 -07:00
parent ea73c99faa
commit b61cc6433b
2 changed files with 10 additions and 12 deletions

View File

@@ -119,6 +119,15 @@ void DefaultFileSource::Impl::cancel(Request* req) {
// unsubscribe callback triggers the removal of the SharedRequestBase pointer from the list
// of pending requests and initiates cancelation.
sharedRequest->unsubscribe(req);
if (sharedRequest->abandoned()) {
// There are no observers anymore. We are initiating cancelation.
// First, remove this SharedRequestBase from the source.
pending.erase(sharedRequest->resource);
// Then, initiate cancelation of this request
sharedRequest->cancel();
}
} else {
// There is no request for this URL anymore. Likely, the request already completed
// before we got around to process the cancelation request.
@@ -189,7 +198,7 @@ void DefaultFileSource::Impl::notify(SharedRequestBase *sharedRequest,
assert(find(sharedRequest->resource) == sharedRequest);
pending.erase(sharedRequest->resource);
if (response && cache) {
if (cache) {
// Store response in database
cache->put(sharedRequest->resource, response, hint);
}

View File

@@ -46,23 +46,12 @@ public:
void subscribe(Request *request) {
MBGL_VERIFY_THREAD(tid);
observers.insert(request);
}
void unsubscribe(Request *request) {
MBGL_VERIFY_THREAD(tid);
observers.erase(request);
if (abandoned()) {
// There are no observers anymore. We are initiating cancelation.
// First, remove this SharedRequestBase from the source.
source.notify(this, nullptr, FileCache::Hint::No);
// Then, initiate cancelation of this request
cancel();
}
}
bool abandoned() const {