Bug 1798651 Part 1: Make SynchronousTask accept a wait interval, and return result. r=gfx-reviewers,nical

This change preserves the existing looping behavior for the indefinite
wait.

Differential Revision: https://phabricator.services.mozilla.com/D161194
This commit is contained in:
Brad Werth 2022-11-08 15:53:35 +00:00
parent 68cd95c000
commit 9a1afee97e

View File

@ -20,10 +20,21 @@ class MOZ_STACK_CLASS SynchronousTask {
explicit SynchronousTask(const char* name)
: mMonitor(name), mAutoEnter(mMonitor), mDone(false) {}
void Wait() {
while (!mDone) {
nsresult Wait(PRIntervalTime aInterval = PR_INTERVAL_NO_TIMEOUT) {
// For indefinite timeouts, wait in a while loop to handle spurious
// wakeups.
while (aInterval == PR_INTERVAL_NO_TIMEOUT && !mDone) {
mMonitor.Wait();
}
// For finite timeouts, we only check once for completion, and otherwise
// rely on the ReentrantMonitor to manage the interval. If the monitor
// returns too early, we'll never know.
if (!mDone) {
return mMonitor.Wait(aInterval);
}
return NS_OK;
}
private: