diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 14d15e1ba8e..7ec9f6dfc4f 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -2840,26 +2840,34 @@ WatchdogMain(void *arg) PR_Lock(gWatchdogLock); while (gWatchdogThread) { - int64_t now = PRMJ_Now(); - if (gWatchdogHasTimeout && !IsBefore(now, gWatchdogTimeout)) { - /* - * The timeout has just expired. Trigger the operation callback - * outside the lock. - */ - gWatchdogHasTimeout = false; - PR_Unlock(gWatchdogLock); - CancelExecution(rt); - PR_Lock(gWatchdogLock); + int64_t now = PRMJ_Now(); + if (gWatchdogHasTimeout && !IsBefore(now, gWatchdogTimeout)) { + /* + * The timeout has just expired. Trigger the operation callback + * outside the lock. + */ + gWatchdogHasTimeout = false; + PR_Unlock(gWatchdogLock); + CancelExecution(rt); + PR_Lock(gWatchdogLock); - /* Wake up any threads doing sleep. */ - PR_NotifyAllCondVar(gSleepWakeup); + /* Wake up any threads doing sleep. */ + PR_NotifyAllCondVar(gSleepWakeup); } else { - uint64_t sleepDuration = PR_INTERVAL_NO_TIMEOUT; - if (gWatchdogHasTimeout) - sleepDuration = (gWatchdogTimeout - now) / PRMJ_USEC_PER_SEC * PR_TicksPerSecond(); - mozilla::DebugOnly status = - PR_WaitCondVar(gWatchdogWakeup, sleepDuration); - JS_ASSERT(status == PR_SUCCESS); + if (gWatchdogHasTimeout) { + /* + * Time hasn't expired yet. Simulate an operation callback + * which doesn't abort execution. + */ + JS_TriggerOperationCallback(rt); + } + + uint64_t sleepDuration = PR_INTERVAL_NO_TIMEOUT; + if (gWatchdogHasTimeout) + sleepDuration = PR_TicksPerSecond() / 10; + mozilla::DebugOnly status = + PR_WaitCondVar(gWatchdogWakeup, sleepDuration); + JS_ASSERT(status == PR_SUCCESS); } } PR_Unlock(gWatchdogLock);