Skip to content

Commit dfc6d46

Browse files
committed
run task if lock taken - sketch
1 parent e576b15 commit dfc6d46

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

index.bs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,42 +90,51 @@ A <dfn export id=file>file entry</dfn> additionally consists of
9090
a <dfn for="file entry">lock</dfn> (a string that may exclusively be "`open`", "`taken-exclusive`" or "`taken-shared`")
9191
and a <dfn for="file entry">shared lock count</dfn> (a number representing the number shared locks that are taken at a given point in time).
9292

93-
The <dfn id="file-system-lock-queue">file system lock queue</dfn> is a
94-
[=parallel queue=] to be used for all [=tasks=] involving a [=file entry/lock=].
93+
A user agent has an associated <dfn>file system lock queue</dfn> which is the
94+
result of [=starting a new parallel queue=]. This queue is to be used for all
95+
[=tasks=] involving a [=file entry/lock=].
9596

9697
<div algorithm>
97-
To <dfn for="file entry/lock">take</dfn> a [=file entry/lock=] with a |value| of "`exclusive`" or "`shared`" on a given [=file entry=] |file|:
98+
To <dfn for="file entry/lock">take</dfn> a [=file entry/lock=] with a |value| of
99+
"`exclusive`" or "`shared`" on a given [=file entry=] |file|, with promise |p|,
100+
algorithm |onLockTakenAlgorithm|, and [=task source=] |replyTaskSource|:
98101

99-
1. Let |lock| be the |file|'s [=file entry/lock=].
100102
1. [=Enqueue the following steps=] to the [=file system lock queue=]:
103+
1. Let |lock| be the |file|'s [=file entry/lock=].
101104
1. Let |count| be the |file|'s [=file entry/shared lock count=].
102105
1. If |value| is "`exclusive`":
103106
1. If |lock| is "`open`":
104107
1. Set lock to "`taken-exclusive`".
105-
1. Return true.
108+
1. [=Queue a task=] to |replyTaskSource| to run |onLockTakenAlgorithm|
109+
and return.
106110
1. If |value| is "`shared`":
107111
1. If |lock| is "`open`":
108112
1. Set |lock| to "`taken-shared`".
109113
1. Set |count| to 1.
110-
1. Return true.
114+
1. [=Queue a task=] to |replyTaskSource| to run |onLockTakenAlgorithm|
115+
and return.
111116
1. Otherwise, if |lock| is "`taken-shared`":
112117
1. Increase |count| by one.
113-
1. Return true.
114-
1. Return false.
118+
1. [=Queue a task=] to |replyTaskSource| to run |onLockTakenAlgorithm|
119+
and return.
120+
1. [=Reject=] |p| with a "{{NoModificationAllowedError}}" {{DOMException}}.
115121

116122
</div>
117123

118124
<div algorithm>
119-
To <dfn for="file entry/lock">release</dfn> a [=file entry/lock=] on a given [=file entry=] |file|,
120-
run these steps:
125+
To <dfn for="file entry/lock">release</dfn> a [=file entry/lock=] on a given
126+
[=file entry=] |file| with algorithm |onLockReleasedAlgorithm| and
127+
[=task source=] |replyTaskSource|:
121128

122-
1. Let |lock| be the |file|'s associated [=file entry/lock=].
123129
1. [=Enqueue the following steps=] to the [=file system lock queue=]:
130+
1. Let |lock| be the |file|'s associated [=file entry/lock=].
124131
1. Let |count| be the |file|'s [=file entry/shared lock count=].
125132
1. If |lock| is "`taken-shared`":
126133
1. Decrease |count| by one.
127134
1. If |count| is 0, set |lock| to "`open`".
128135
1. Otherwise, set |lock| to "`open`".
136+
1. [=Queue a task=] to |replyTaskSource| to run |onLockReleasedAlgorithm|
137+
and return.
129138

130139
</div>
131140

@@ -358,13 +367,14 @@ The <dfn method for=FileSystemFileHandle>createWritable(|options|)</dfn> method
358367
1. If |access| is not "{{PermissionState/granted}}",
359368
[=reject=] |result| with a "{{NotAllowedError}}" {{DOMException}} and abort.
360369
1. Let |entry| be [=this=]'s [=FileSystemHandle/entry=].
361-
1. Let |lockResult| be the result of [=file entry/lock/take|taking a lock=] with "`shared`" on |entry|.
362-
1. If |lockResult| is false, [=reject=] |result| with a "{{NoModificationAllowedError}}" {{DOMException}} and abort.
363-
1. Let |stream| be the result of [=create a new FileSystemWritableFileStream|creating a new FileSystemWritableFileStream=]
364-
for |entry| in [=this=]'s [=relevant realm=].
365-
1. If |options|.{{FileSystemCreateWritableOptions/keepExistingData}} is true:
366-
1. Set |stream|.[=[[buffer]]=] to a copy of |entry|'s [=file entry/binary data=].
367-
1. [=/Resolve=] |result| with |stream|.
370+
1. Let |onLockTakenAlgorithm| be these steps:
371+
1. Let |stream| be the result of [=create a new FileSystemWritableFileStream|creating a new FileSystemWritableFileStream=]
372+
for |entry| in [=this=]'s [=relevant realm=].
373+
1. If |options|.{{FileSystemCreateWritableOptions/keepExistingData}} is true:
374+
1. Set |stream|.[=[[buffer]]=] to a copy of |entry|'s [=file entry/binary data=].
375+
1. [=/Resolve=] |result| with |stream|.
376+
1. [=file entry/lock/take|Take a lock=] with "`shared`" on |entry| with
377+
|result|, |onLockTakenAlgorithm|, and [=storage task source=].
368378
1. Return |result|.
369379

370380
</div>
@@ -815,8 +825,9 @@ in a [=/Realm=] |realm|, run these steps:
815825
Note: It is expected that this atomically updates the contents of the file on disk
816826
being written to.
817827

818-
1. [=file entry/lock/release|Release the lock=] on |stream|.[=FileSystemWritableFileStream/[[file]]=].
819-
1. [=/Resolve=] |closeResult| with `undefined`.
828+
1. Let |onLockReleasedAlgorithm| be this step: [=/Resolve=] |closeResult| with `undefined`.
829+
1. [=file entry/lock/release|Release the lock=] on |stream|'s [=FileSystemWritableFileStream/[[file]]=]
830+
with |onLockReleasedAlgorithm|, and the currently running [=task=]'s' [=task source|source=].
820831
1. Return |closeResult|.
821832
1. Let |abortAlgorithm| be this step: [=file entry/lock/release|release the lock=] on
822833
|stream|.[=FileSystemWritableFileStream/[[file]]=].

0 commit comments

Comments
 (0)