/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
if ((mExecutionQueue.size() + (mMainThreadAwaitingExecution ? 1 : 0)) <
size_t(mMaxRunning - mRunning)) { // There's slots ready for things to run, execute right away.
workerPrivate->SetExecutionGranted(true);
workerPrivate->ScheduleTimeSliceExpiration(kTimeSliceExpirationMS);
mRunning++; return RequestState::Granted;
}
mExecutionQueue.push_back(workerPrivate);
TimeStamp waitStart = TimeStamp::Now();
while (mRunning >= mMaxRunning || (workerPrivate != mExecutionQueue.front() ||
mMainThreadAwaitingExecution)) { // If there is no slots available, the main thread is awaiting permission // or we are not first in line for execution, wait until notified.
mExecutionQueueCondVar.Wait(TimeDuration::FromMilliseconds(500)); if ((TimeStamp::Now() - waitStart) > TimeDuration::FromSeconds(20)) { // Crash so that these types of situations are actually caught in the // crash reporter.
MOZ_CRASH();
}
}
mExecutionQueue.pop_front();
mRunning++; if (mRunning < mMaxRunning) { // If a thread woke up before that wasn't first in line it will have gone // back to sleep, if there's more slots available, wake it now.
mExecutionQueueCondVar.NotifyAll();
}
return RequestState::Granted;
}
void JSExecutionManager::YieldJSThreadExecution() { if (NS_IsMainThread()) {
MOZ_ASSERT(mMainThreadIsExecuting);
mMainThreadIsExecuting = false;
if ((mMaxRunning - mRunning) > 0) { // If there's any slots available run, the main thread always takes // precedence over any worker threads.
mRunning++;
mMainThreadIsExecuting = true; return RequestState::Granted;
}
mMainThreadAwaitingExecution = true;
TimeStamp waitStart = TimeStamp::Now();
while (mRunning >= mMaxRunning) { if ((TimeStamp::Now() - waitStart) > TimeDuration::FromSeconds(20)) { // Crash so that these types of situations are actually caught in the // crash reporter.
MOZ_CRASH();
}
mExecutionQueueCondVar.Wait(TimeDuration::FromMilliseconds(500));
}
mRunning++; if (mRunning < mMaxRunning) { // If a thread woke up before that wasn't first in line it will have gone // back to sleep, if there's more slots available, wake it now.
mExecutionQueueCondVar.NotifyAll();
}
if (workerPrivate) {
manager = workerPrivate->GetExecutionManager();
}
}
if (manager &&
(manager->RequestJSThreadExecution() == RequestState::Granted)) { if (NS_IsMainThread()) { // Make sure we restore permission on destruction if needed.
JSExecutionManager::mCurrentMTManager = manager;
}
mExecutionGrantingManager = std::move(manager);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.