-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
100 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Node data-structure | ||
|
||
struct Node { | ||
var next: Node; | ||
var lock: Bool; | ||
var val: Int; | ||
} | ||
|
||
|
||
// List segment definitions | ||
|
||
predicate lseg(x: Node, y: Node) { | ||
acc({ z: Node :: Btwn(next, x, z, y) && z != y }) &*& Reach(next, x, y) | ||
} | ||
|
||
predicate lseg_upperbound(ub: Int, FP: Set<Node>) | ||
requires acc(FP) | ||
{ | ||
forall z: Node :: (z in FP && z.next != null) ==> z.val <= ub | ||
} | ||
|
||
predicate lseg_sentinel (head: Node, ub: Int, FP: Set<Node>) | ||
requires acc(FP) | ||
{ | ||
exists z: Node :: | ||
z in FP && z.next == null && z.val == ub && z != head | ||
} | ||
|
||
predicate llseg(h: Node, y: Node, ub: Int) { | ||
lseg(h, y) && | ||
(exists X: Set<Node> :: | ||
acc(X) &*& lseg_upperbound(ub, X) &*& lseg_sentinel(h,ub,X)) | ||
} | ||
|
||
predicate nodeUnlocked(x: Node, y: Node) { | ||
x.next == y &*& x.lock == false | ||
} | ||
|
||
predicate nodeLocked(x: Node, y: Node) { | ||
x.next == y &*& x.lock == true | ||
} | ||
|
||
|
||
// Calls to helper procedures | ||
|
||
procedure takeLock(x: Node) | ||
requires acc(x); | ||
ensures acc(x) &*& nodeLocked(x,x.next); | ||
{ | ||
while (x.lock == true) {} | ||
x.lock := true; | ||
} | ||
|
||
procedure releaseLock(x: Node) | ||
requires acc(x) &*& nodeLocked(x,x.next); | ||
ensures acc(x) &*& nodeUnlocked(x,x.next); | ||
{ | ||
x.lock := false; | ||
} | ||
|
||
predicate endNode(x: Node, ub: Int) { | ||
acc(x) &*& x.next == null &*& x.val == ub | ||
} | ||
|
||
procedure disposeNode(x: Node) | ||
requires acc(x); | ||
ensures emp; | ||
{ | ||
free(x); | ||
} | ||
|
||
|
||
// Equivalents to Starling predicates. | ||
|
||
predicate isListG (head: Node, ub: Int, v: Int) { | ||
llseg(head, null, ub) &*& head != null &*& v < ub | ||
} | ||
|
||
predicate has1LockG(head: Node, a: Node, b: Node) | ||
{ | ||
exists X: Set<Node> :: acc(X) &*& a in X &*& nodeLocked(a, b) | ||
} | ||
|
||
predicate has2LockG(head: Node, a: Node, b: Node) { | ||
exists X: Set<Node>, c: Node :: | ||
acc(X) &*& a in X &*& b in X &*& nodeLocked(a, b) &*& nodeLocked(b,c) | ||
} | ||
|
||
predicate dangleNodeG(x: Node) | ||
{ | ||
acc(x) | ||
} | ||
|
||
predicate isValG(head: Node, n: Node, v: Int) | ||
requires acc(n) | ||
{ | ||
exists X: Set<Node> :: acc(X) &*& n.val == v | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters