Skip to content

Commit c329716

Browse files
authored
Move queue map and held lock set to lock manager (#90)
Replace lock set and request queue associations with an origin with a lock manager instead. This doesn't change normative behavior, just moves conceptual ownership off the origin. This paves the way for future work towards #74 to enable partitioning, and coincidentally matches implementations.
1 parent 05d7966 commit c329716

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

index.bs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ A [=lock-concept|lock=] has an <dfn>agent</dfn> which is an [=/agent=].
208208

209209
A [=lock-concept|lock=] has a <dfn>clientId</dfn> which is an opaque string.
210210

211-
A [=lock-concept|lock=] has an <dfn>origin</dfn> which is an [=/origin=].
211+
A [=lock-concept|lock=] has a <dfn>manager</dfn> which is a [=/lock manager=].
212212

213213
A [=lock-concept|lock=] has a <dfn>name</dfn> which is a [=resource name=].
214214

@@ -246,7 +246,7 @@ The [=lock-concept/waiting promise=] is not named in the above code, but is stil
246246
Further note that if the callback is not `async` and returns a non-promise, the return value is wrapped in a promise that is immediately resolved; the lock will be released in an upcoming microtask, and the [=lock-concept/released promise=] will also resolve in a subsequent microtask.
247247
</aside>
248248

249-
Each origin has a <dfn>held lock set</dfn> which is a [=/set=] of [=lock-concept|locks=].
249+
Each [=/lock manager=] has a <dfn for="lock manager">held lock set</dfn> which is a [=/set=] of [=lock-concept|locks=].
250250

251251
<div algorithm="waiting promise settles">
252252

@@ -267,17 +267,17 @@ A <dfn>lock request</dfn> represents a pending request for a [=lock-concept|lock
267267

268268
<div dfn-for="lock request">
269269

270-
A [=lock request=] is a [=/struct=] with [=struct/items=] <dfn>agent</dfn>, <dfn>clientId</dfn>, <dfn>origin</dfn>, <dfn>name</dfn>, <dfn>mode</dfn>, <dfn>callback</dfn>, <dfn>promise</dfn>, and <dfn>signal</dfn>.
270+
A [=lock request=] is a [=/struct=] with [=struct/items=] <dfn>agent</dfn>, <dfn>clientId</dfn>, <dfn>manager</dfn>, <dfn>name</dfn>, <dfn>mode</dfn>, <dfn>callback</dfn>, <dfn>promise</dfn>, and <dfn>signal</dfn>.
271271

272272
</div>
273273

274274
A <dfn>lock request queue</dfn> is a [=/queue=] of [=/lock requests=].
275275

276-
Each origin has a <dfn>lock request queue map</dfn>, which is a [=map=] of [=resource names=] to [=/lock request queues=].
276+
Each [=/lock manager=] has a <dfn for="lock manager">lock request queue map</dfn>, which is a [=map=] of [=resource names=] to [=/lock request queues=].
277277

278278
<div algorithm>
279279

280-
To <dfn>get the lock request queue</dfn> from [=/lock request queue map=] |queueMap| from [=/resource name=] |name|, run these steps:
280+
To <dfn>get the lock request queue</dfn> from [=lock manager/lock request queue map=] |queueMap| from [=/resource name=] |name|, run these steps:
281281

282282
1. If |queueMap|[|name|] does not [=map/exist=], [=map/set=] |queueMap|[|name|] to a new empty [=/lock request queue=].
283283
1. Return |queueMap|[|name|].
@@ -289,11 +289,11 @@ To <dfn>get the lock request queue</dfn> from [=/lock request queue map=] |queue
289289

290290
A [=lock request=] |request| is said to be <dfn>grantable</dfn> if the following steps return true:
291291

292-
1. Let |origin| be |request|'s [=lock request/origin=].
293-
1. Let |queueMap| be |origin|'s [=lock request queue map=].
292+
1. Let |manager| be |request|'s [=lock request/manager=].
293+
1. Let |queueMap| be |manager|'s [=lock manager/lock request queue map=].
294294
1. Let |name| be |request|'s [=lock request/name=].
295295
1. Let |queue| be the result of [=/getting the lock request queue=] from |queueMap| for |name|.
296-
1. Let |held| be |origin|'s [=held lock set=]
296+
1. Let |held| be |manager|'s [=lock manager/held lock set=]
297297
1. Let |mode| be |request|'s [=lock request/mode=]
298298
1. If |queue| [=queue/is empty|is not empty=] and |request| is not the first [=queue/item=] in |queue|, then return false.
299299
1. If |mode| is "{{exclusive}}", then return true if no [=lock-concept|lock=] in |held| has [=lock-concept/name=] equal to |name|, and false otherwise.
@@ -495,7 +495,7 @@ The <dfn method for=LockManager>request(|name|, |callback|)</dfn> and
495495
<dfn method for=LockManager>request(|name|, |options|, |callback|)</dfn> method steps are:
496496

497497
1. If |options| was not passed, then let |options| be a new {{LockOptions}} dictionary with default members.
498-
1. Let |environment| be [=/this=]'s [=relevant settings object=].
498+
1. Let |environment| be [=/this=]'s [=/relevant settings object=].
499499
1. If |environment|'s [=responsible document=] is not [=fully active=], then return [=a promise rejected with=] a "{{InvalidStateError}}" {{DOMException}}.
500500
1. Let |origin| be |environment|'s [=/origin=].
501501
1. If |origin| is an [=opaque origin=], then return [=a promise rejected with=] a "{{SecurityError}}" {{DOMException}}.
@@ -505,7 +505,7 @@ The <dfn method for=LockManager>request(|name|, |callback|)</dfn> and
505505
1. If |options|["`signal`"] [=map/exists=], and either of |options|["`steal`"] or |options|["`ifAvailable`"] is true, then return [=a promise rejected with=] a "{{NotSupportedError}}" {{DOMException}}.
506506
1. If |options|["`signal`"] [=map/exists=] and its [=AbortSignal/aborted flag=] is set, then return [=a promise rejected with=] an "{{AbortError}}" {{DOMException}.
507507
1. Let |promise| be [=a new promise=].
508-
1. [=Request a lock=] with |promise|, the current [=/agent=], |environment|'s [=environment/id=], |origin|, |callback|, |name|, |options|["`mode`"], |options|["`ifAvailable`"], |options|["`steal`"], and |options|["`signal`"].
508+
1. [=Request a lock=] with |promise|, the current [=/agent=], |environment|'s [=environment/id=], |origin|'s [=/lock manager=], |callback|, |name|, |options|["`mode`"], |options|["`ifAvailable`"], |options|["`steal`"], and |options|["`signal`"].
509509
1. Return |promise|.
510510
511511
</div>
@@ -559,7 +559,7 @@ The <dfn method for=LockManager>query()</dfn> method steps are:
559559
1. Let |origin| be |environment|'s [=/origin=].
560560
1. If |origin| is an [=opaque origin=], then return [=a promise rejected with=] a "{{SecurityError}}" {{DOMException}}.
561561
1. Let |promise| be [=a new promise=].
562-
1. [=enqueue the following steps|Enqueue the steps=] to [=snapshot the lock state=] for |origin| with |promise| to the [=lock task queue=].
562+
1. [=enqueue the following steps|Enqueue the steps=] to [=snapshot the lock state=] for |origin|'s [=/lock manager=] with |promise| to the [=lock task queue=].
563563
1. Return |promise|.
564564

565565
</div>
@@ -591,14 +591,14 @@ The <dfn attribute for=Lock>mode</dfn> getter's steps are to return the associat
591591
<!-- ====================================================================== -->
592592

593593
<div algorithm>
594-
To <dfn>request a lock</dfn> with |promise|, |agent|, |clientId|, |origin|, |callback|, |name|, |mode|, |ifAvailable|, |steal|, and |signal|:
594+
To <dfn>request a lock</dfn> with |promise|, |agent|, |clientId|, |manager|, |callback|, |name|, |mode|, |ifAvailable|, |steal|, and |signal|:
595595

596-
1. Let |request| be a new [=lock request=] (|agent|, |clientId|, |origin|, |name|, |mode|, |callback|, |promise|, |signal|).
596+
1. Let |request| be a new [=lock request=] (|agent|, |clientId|, |manager|, |name|, |mode|, |callback|, |promise|, |signal|).
597597
1. If |signal| is present, then [=AbortSignal/add=] the algorithm [=signal to abort the request=] |request| to |signal|.
598598
1. [=Enqueue the following steps=] to the [=lock task queue=]:
599-
1. Let |queueMap| be |origin|'s [=lock request queue map=].
599+
1. Let |queueMap| be |manager|'s [=lock manager/lock request queue map=].
600600
1. Let |queue| be the result of [=/getting the lock request queue=] from |queueMap| for |name|.
601-
1. Let |held| be |origin|'s [=held lock set=].
601+
1. Let |held| be |manager|'s [=lock manager/held lock set=].
602602
1. If |steal| is true, then run these steps:
603603
1. [=list/For each=] |lock| of |held|:
604604
1. If |lock|'s [=lock-concept/name=] is |name|, then run these steps:
@@ -624,11 +624,11 @@ To <dfn>request a lock</dfn> with |promise|, |agent|, |clientId|, |origin|, |cal
624624
To <dfn>release the lock</dfn> |lock|:
625625

626626
1. [=Assert=]: these steps are running on the [=lock task queue=].
627-
1. Let |origin| be |lock|'s [=lock-concept/origin=].
628-
1. Let |queueMap| be |origin|'s [=lock request queue map=].
627+
1. Let |manager| be |lock|'s [=lock-concept/manager=].
628+
1. Let |queueMap| be |manager|'s [=lock manager/lock request queue map=].
629629
1. Let |name| be |lock|'s [=resource name=].
630630
1. Let |queue| be the result of [=/getting the lock request queue=] from |queueMap| for |name|.
631-
1. [=list/Remove=] [=lock-concept|lock=] from the |origin|'s [=held lock set=].
631+
1. [=list/Remove=] [=lock-concept|lock=] from the |manager|'s [=lock manager/held lock set=].
632632
1. [=Process the lock request queue=] |queue|.
633633

634634
</div>
@@ -641,9 +641,9 @@ To <dfn>release the lock</dfn> |lock|:
641641
To <dfn>abort the request</dfn> |request|:
642642

643643
1. [=Assert=]: these steps are running on the [=lock task queue=].
644-
1. Let |origin| be |request|'s [=lock request/origin=].
644+
1. Let |manager| be |request|'s [=lock request/manager=].
645645
1. Let |name| be |request|'s [=lock request/name=].
646-
1. Let |queueMap| be |origin|'s [=lock request queue map=].
646+
1. Let |queueMap| be |manager|'s [=lock manager/lock request queue map=].
647647
1. Let |queue| be the result of [=/getting the lock request queue=] from |queueMap| for |name|.
648648
1. [=list/Remove=] |request| from |queue|.
649649
1. [=Process the lock request queue=] |queue|.
@@ -672,16 +672,17 @@ To <dfn>process the lock request queue</dfn> |queue|:
672672
Note: Only the first item in a queue is grantable. Therefore, if something is not grantable then all the following items are automatically not grantable.
673673

674674
1. [=list/Remove=] |request| from |queue|.
675-
1. Let |agent| be |request|'s [=lock-concept/agent=]
675+
1. Let |agent| be |request|'s [=lock-concept/agent=].
676+
1. Let |manager| be |request|'s [=lock request/manager=].
676677
1. Let |clientId| be |request|'s [=lock request/clientId=].
677678
1. Let |name| be |request|'s [=lock request/name=].
678679
1. Let |mode| be |request|'s [=lock request/mode=].
679680
1. Let |callback| be |request|'s [=lock request/callback=].
680681
1. Let |p| be |request|'s [=lock request/promise=].
681682
1. Let |signal| be |request|'s [=lock request/signal=].
682683
1. Let |waiting| be [=a new promise=].
683-
1. Let |lock| be a new [=lock-concept|lock=] with [=lock-concept/agent=] |agent|, [=lock-concept/clientId=] |clientId|, [=lock-concept/origin=] |origin|, [=lock-concept/mode=] |mode|, [=lock-concept/name=] |name|, [=lock-concept/released promise=] |p|, and [=lock-concept/waiting promise=] |waiting|.
684-
1. [=set/Append=] |lock| to |origin|'s [=held lock set=].
684+
1. Let |lock| be a new [=lock-concept|lock=] with [=lock-concept/agent=] |agent|, [=lock-concept/clientId=] |clientId|, [=lock-concept/manager=] |manager|, [=lock-concept/mode=] |mode|, [=lock-concept/name=] |name|, [=lock-concept/released promise=] |p|, and [=lock-concept/waiting promise=] |waiting|.
685+
1. [=set/Append=] |lock| to |manager|'s [=lock manager/held lock set=].
685686
1. [=Enqueue the following steps=] on |callback|'s [=relevant settings object=]'s [=responsible event loop=]:
686687
1. If |signal| is present, then run these steps:
687688
1. If |signal|'s [=AbortSignal/aborted flag=] is set, then run these steps:
@@ -699,15 +700,15 @@ To <dfn>process the lock request queue</dfn> |queue|:
699700
<!-- ====================================================================== -->
700701

701702
<div algorithm>
702-
To <dfn>snapshot the lock state</dfn> for |origin| with |promise|:
703+
To <dfn>snapshot the lock state</dfn> for |manager| with |promise|:
703704

704705
1. [=Assert=]: these steps are running on the [=lock task queue=].
705706
1. Let |pending| be a new [=/list=].
706-
1. [=map/For each=] |queue| of |origin|'s [=lock request queue map=]'s [=map/values=]:
707+
1. [=map/For each=] |queue| of |manager|'s [=lock manager/lock request queue map=]'s [=map/values=]:
707708
1. [=list/For each=] |request| of |queue|:
708709
1. [=list/Append=] «[ "name" → |request|'s [=lock request/name=], "mode" → |request|'s [=lock request/mode=], "clientId" → |request|'s [=lock request/clientId=] ]» to |pending|.
709710
1. Let |held| be a new [=/list=].
710-
1. [=list/For each=] |lock| of |origin|'s [=held lock set=]:
711+
1. [=list/For each=] |lock| of |manager|'s [=lock manager/held lock set=]:
711712
1. [=list/Append=] «[ "name" → |lock|'s [=lock-concept/name=], "mode" → |lock|'s [=lock-concept/mode=], "clientId" → |lock|'s [=lock-concept/clientId=] ]» to |held|.
712713
1. [=/Resolve=] |promise| with «[ "held" → |held|, "pending" → |pending| ]».
713714

0 commit comments

Comments
 (0)