-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmylock.h
49 lines (36 loc) · 1.29 KB
/
mylock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/****************************************************************
* Mutex-like lock that supports static allocation instead
* of heap allocation.
*
* Copyright Alastair Reid 2020
* SPDX-Licence-Identifier: BSD-3-Clause
****************************************************************/
#include <stdint.h>
struct mylock {
volatile uint32_t v;
};
/*@
// Use this for uninitialized locks
predicate mylock_raw(struct mylock *l;) =
l->v |-> _
// &*& struct_mylock_padding(l)
;
predicate mylock(struct mylock *l; predicate() p);
predicate mylock_held(struct mylock *l, predicate() p, int threadId, real frac);
predicate create_mylock_ghost_arg(predicate() p) = true;
@*/
void mylock_init(struct mylock *l);
//@ requires mylock_raw(l) &*& create_mylock_ghost_arg(?p) &*& p();
//@ ensures mylock(l, p);
void mylock_fini(struct mylock *l);
//@ requires mylock(l, ?p);
//@ ensures p() &*& mylock_raw(l);
void mylock_acquire(struct mylock *l);
//@ requires [?f]mylock(l, ?p);
//@ ensures mylock_held(l, p, currentThread, f) &*& p();
void mylock_release(struct mylock *l);
//@ requires mylock_held(l, ?p, currentThread, ?f) &*& p();
//@ ensures [f]mylock(l, p);
/****************************************************************
* End
****************************************************************/