DescriptionIssue #4692, #3595 - Stop sleeping in the implementation of `SetTimeout`
New source files "Timeout.{cpp,h}" for implementation of timeout. Some code
had been in "GlobalJsObject.{cpp,h}".
Add class `DelayedExecutor`, which has member function `RunWithDelay()`. This
has much the same effect as `sleep_for()` but is interruptible. The essence of
the new mechanism is a call to `wait_for` on a condition variable, which can
emerge from waiting either after it times out or upon notice.
Implement `DelayedExecutor` as an aspected class that allows structured white-
box testing. Implement unit tests that ensure particular execution paths both
with and without interruption. Add support classes `PausePoint` and `AntiLock`
to support this testing.
In the timeout task class, replace its `JsEnginePtr` member with a pointer to
`JsEngineInternal`. Schedule it with the engine instead of making a thread for
itself. Add member of type `DelayedExecutor`, and replace the call to
`sleep_for()` with a call to `RunWithDelay`.
For #3595, the present change prepares to eliminate as-if detached threads
that arise from long delays in JS "SetTimeout". Although this does not itself
end the timeout early, the member function `ForestallExecution` is available
to do so in a subsequent change.
Remove dead code. `StartImmediatelyInSingleUseDetachedThread`, `HeapFunction`,
`MakeHeapFunction`. Timeout was the last remaining use of these transitional
facilities.
Patch Set 1 : #
MessagesTotal messages: 1
|