Skip to content

Commit f56615c

Browse files
author
Nathan Memmott
committed
Simplify take lock and release lock.
1 parent e4e3c3c commit f56615c

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

index.bs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ A <dfn export id=file>file entry</dfn> additionally consists of
128128
<dfn for="file entry" export>binary data</dfn> (a [=byte sequence=]), a
129129
<dfn for="file entry">modification timestamp</dfn> (a number representing the number of milliseconds since the <a spec=FileAPI>Unix Epoch</a>),
130130
a <dfn for="file entry">lock</dfn> (a string that may exclusively be "`open`", "`taken-exclusive`" or "`taken-shared`")
131-
and a <dfn for="file entry">shared lock count</dfn> (a number representing the number of shared locks that are taken at a given point in time).
131+
and a <dfn for="file entry">lock count</dfn> (a number representing the number of locks that are taken at a given point in time).
132132

133133
A user agent has an associated <dfn>file system queue</dfn> which is the
134134
result of [=starting a new parallel queue=]. This queue is to be used for all
@@ -139,35 +139,33 @@ To <dfn for="file entry" id=file-entry-lock-take>take a lock</dfn> with a |value
139139
"`exclusive`" or "`shared`" on a given [=file entry=] |file|:
140140

141141
1. Let |lock| be the |file|'s [=file entry/lock=].
142-
1. Let |count| be the |file|'s [=file entry/shared lock count=].
142+
1. Let |count| be the |file|'s [=file entry/lock count=].
143+
1. If |lock| is not "`open`":
144+
1. If |value| is "`exclusive`" or |lock| is "`taken-exclusive`":
145+
1. Return "`failure`".
143146
1. If |value| is "`exclusive`":
144-
1. If |lock| is "`open`":
145-
1. Set lock to "`taken-exclusive`".
146-
1. Return "`success`".
147-
1. If |value| is "`shared`":
148-
1. If |lock| is "`open`":
149-
1. Set |lock| to "`taken-shared`".
150-
1. Set |count| to 1.
151-
1. Return "`success`".
152-
1. Otherwise, if |lock| is "`taken-shared`":
153-
1. Increase |count| by 1.
154-
1. Return "`success`".
155-
1. Return "`failure`".
147+
1. [=Assert=]: |lock| is "`open`".
148+
1. [=Assert=]: |count| is 0.
149+
1. Set |lock| to "`taken-exclusive`".
150+
1. Otherwise:
151+
1. Set |lock| to "`taken-shared`".
152+
1. Increase |count| by 1.
153+
1. Return "`success`".
156154

157155
Note: These steps have to be run on the [=file system queue=].
158156

159157
</div>
160158

161159
<div algorithm>
162160
To <dfn for="file entry/lock">release</dfn> a [=file entry/lock=] on a given
163-
[=file entry=] |file|:
161+
[=/file entry=] |file|:
164162

165163
1. Let |lock| be the |file|'s associated [=file entry/lock=].
166-
1. Let |count| be the |file|'s [=file entry/shared lock count=].
167-
1. If |lock| is "`taken-shared`":
168-
1. Decrease |count| by 1.
169-
1. If |count| is 0, set |lock| to "`open`".
170-
1. Otherwise, set |lock| to "`open`".
164+
1. [=Assert=]: |lock| is not "`open`".
165+
1. Let |count| be the |file|'s [=file entry/lock count=].
166+
1. [=Assert=]: |count| is greater than 0.
167+
1. Decrease |count| by 1.
168+
1. If |count| is 0, set |lock| to "`open`".
171169

172170
Note: These steps have to be run on the [=file system queue=].
173171

0 commit comments

Comments
 (0)