Bug 1323155 - fix data race in mCompletionPromise. r=gerald

MozReview-Commit-ID: J2TVNWvx9pb

--HG--
extra : rebase_source : 64b4f60500eafd24660141103a22693ce37dfd2b
This commit is contained in:
JW Wang 2016-12-13 16:55:14 +08:00
Родитель 5011f3b7eb
Коммит 52ec68d60c
1 изменённых файлов: 10 добавлений и 4 удалений

Просмотреть файл

@ -628,10 +628,13 @@ public:
RefPtr<ThenValueBase> thenValue = new ThenType(
aResponseThread, aThisVal, aResolveMethod, aRejectMethod, aCallSite);
// mCompletionPromise must be created before ThenInternal() to avoid race.
thenValue->mCompletionPromise = new MozPromise::Private(
RefPtr<MozPromise> p = new MozPromise::Private(
"<completion promise>", true /* aIsCompletionPromise */);
thenValue->mCompletionPromise = p;
// Note ThenInternal() might nullify mCompletionPromise before return.
// So we need to return p instead of mCompletionPromise.
ThenInternal(aResponseThread, thenValue, aCallSite);
return thenValue->mCompletionPromise;
return p;
}
template<typename ResolveFunction, typename RejectFunction>
@ -643,10 +646,13 @@ public:
RefPtr<ThenValueBase> thenValue = new ThenType(
aResponseThread, Move(aResolveFunction), Move(aRejectFunction), aCallSite);
// mCompletionPromise must be created before ThenInternal() to avoid race.
thenValue->mCompletionPromise = new MozPromise::Private(
RefPtr<MozPromise> p = new MozPromise::Private(
"<completion promise>", true /* aIsCompletionPromise */);
thenValue->mCompletionPromise = p;
// Note ThenInternal() might nullify mCompletionPromise before return.
// So we need to return p instead of mCompletionPromise.
ThenInternal(aResponseThread, thenValue, aCallSite);
return thenValue->mCompletionPromise;
return p;
}
void ChainTo(already_AddRefed<Private> aChainedPromise, const char* aCallSite)