summaryrefslogtreecommitdiff
path: root/lock.ur
diff options
context:
space:
mode:
Diffstat (limited to 'lock.ur')
-rw-r--r--lock.ur27
1 files changed, 27 insertions, 0 deletions
diff --git a/lock.ur b/lock.ur
new file mode 100644
index 0000000..9accf81
--- /dev/null
+++ b/lock.ur
@@ -0,0 +1,27 @@
+(* Copyright 2015 the Massachusetts Institute of Technology
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+this file except in compliance with the License. You may obtain a copy of the
+License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software distributed
+under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+CONDITIONS OF ANY KIND, either express or implied. See the License for the
+specific language governing permissions and limitations under the License. *)
+
+table lock : { Title : string,
+ Holder : client }
+ PRIMARY KEY Title
+
+fun take page_title =
+ new_holder <- self;
+ result <- tryDml (INSERT INTO lock (Title, Holder)
+ VALUES ({[page_title]}, {[new_holder]}));
+ return (Option.isNone result)
+
+fun release page_title =
+ requestor <- self;
+ dml (DELETE FROM lock
+ WHERE Holder = {[requestor]})