Skip to content

Commit 340fa17

Browse files
committed
Fix bug in LockMutex and refactor to make critical section clearer
1 parent a60bb1a commit 340fa17

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

spec/index.html

+26-24
Original file line numberDiff line numberDiff line change
@@ -2288,31 +2288,33 @@ <h1>
22882288
1. Perform EnterCriticalSection(_WL_).
22892289
1. If _mutex_.[[IsLockedBy]] is ~empty~, then
22902290
1. Set _mutex_.[[IsLockedBy]] to _thisAgent_.
2291-
1. Perform LeaveCriticalSection(_WL_).
2292-
1. Return ~acquired~.
2293-
1. If _mutex_.[[IsLockedBy]] is _thisAgent_, then
2294-
1. Return ~deadlock~.
2295-
1. If _tMillis_ is 0, return ~timed-out~.
2296-
1. Let _now_ be the time value (UTC) identifying the current time.
2297-
1. Let _additionalTimeout_ be an implementation-defined non-negative mathematical value.
2298-
1. Let _timeoutTime_ be ℝ(_now_) + _tMillis_ + _additionalTimeout_.
2299-
1. NOTE: When _tMillis_ is +∞, _timeoutTime_ is also +∞.
2300-
1. Let _done_ be *false*.
2301-
1. Repeat, while _done_ is *false*,
2302-
1. Let _waiterRecord_ be a new Waiter Record { [[AgentSignifier]]: _thisAgent_, [[PromiseCapability]]: ~blocking~, [[TimeoutTime]]: _timeoutTime_, [[Result]]: *"ok"* }.
2303-
1. Perform AddWaiter(_WL_, _waiterRecord_).
2304-
1. Perform SuspendThisAgent(_WL_, _waiterRecord_).
2305-
1. If _mutex_.[[IsLockedBy]] is ~empty~, then
2306-
1. Set _mutex_.[[IsLockedBy]] to _thisAgent_.
2307-
1. Set _waiterRecord_.[[Result]] to *"ok"*.
2308-
1. Set _done_ to *true*.
2309-
1. Else if _waiterRecord_.[[Result]] is *"timed-out"*, then
2310-
1. Set _done_ to *true*.
2291+
1. Let _result_ be ~acquired~.
2292+
1. Else if _mutex_.[[IsLockedBy]] is _thisAgent_, then
2293+
1. Let _result_ be ~deadlock~.
2294+
1. Else,
2295+
1. If _tMillis_ is 0, return ~timed-out~.
2296+
1. Let _now_ be the time value (UTC) identifying the current time.
2297+
1. Let _additionalTimeout_ be an implementation-defined non-negative mathematical value.
2298+
1. Let _timeoutTime_ be ℝ(_now_) + _tMillis_ + _additionalTimeout_.
2299+
1. NOTE: When _tMillis_ is +∞, _timeoutTime_ is also +∞.
2300+
1. Let _done_ be *false*.
2301+
1. Repeat, while _done_ is *false*,
2302+
1. Let _waiterRecord_ be a new Waiter Record { [[AgentSignifier]]: _thisAgent_, [[PromiseCapability]]: ~blocking~, [[TimeoutTime]]: _timeoutTime_, [[Result]]: *"ok"* }.
2303+
1. Perform AddWaiter(_WL_, _waiterRecord_).
2304+
1. Perform SuspendThisAgent(_WL_, _waiterRecord_).
2305+
1. If _mutex_.[[IsLockedBy]] is ~empty~, then
2306+
1. Set _mutex_.[[IsLockedBy]] to _thisAgent_.
2307+
1. Set _waiterRecord_.[[Result]] to *"ok"*.
2308+
1. Set _done_ to *true*.
2309+
1. Else if _waiterRecord_.[[Result]] is *"timed-out"*, then
2310+
1. Set _done_ to *true*.
2311+
1. If _waiterRecord_.[[Result]] is *"ok"*, then
2312+
1. Let _result_ be ~acquired~.
2313+
1. Else,
2314+
1. Assert: _waiterRecord_.[[Result]] is *"timed-out"*.
2315+
1. Let _result_ be ~timed-out~.
23112316
1. Perform LeaveCriticalSection(_WL_).
2312-
1. If _waiterRecord_.[[Result]] is *"ok"*, then
2313-
1. Return ~acquired~.
2314-
1. Assert: _waiterRecord_.[[Result]] is *"timed-out"*.
2315-
1. Return ~timed-out~.
2317+
1. Return _result_.
23162318
</emu-alg>
23172319
</emu-clause>
23182320

0 commit comments

Comments
 (0)