(** Actions that require a [Readable] permission*)
Inductive raction ev : Prop :=
| read: action ev = Read ->
raction ev
| acq: action ev = Acquire ->
raction ev
| rel: action ev = Release ->
raction ev
| facq: action ev = Failacq ->
raction ev.
(** Actions that require a [Writable] permission*)
Inductive waction ev : Prop:=
| write: action ev = Write ->
waction ev
| mk: action ev = Mklock ->
waction ev
| fl: action ev = Freelock ->
waction ev.

(* Specifications: *)
Lemma compete_cases:
forall evi evj
(Hcompetes: competes evi evj),
(raction evi /\ waction evj) \/
(waction evi /\ caction evj).
Lemma fstep_ev_perm:
forall U tr tp m U' tr_pre tr_post tp' m' ev
(Hstep: fstep (U, tr, tp) m (U', tr ++ tr_pre ++ [:: ev] ++ tr_post , tp') m'),
(waction ev ->
forall (cnt: containsThread tp (thread_id ev)) (cnt': containsThread tp' (thread_id ev)),
match location ev with
| Some (b, ofs, sz) =>
forall ofs', Intv.In ofs' (ofs, ofs + Z.of_nat sz)%Z ->
(Mem.valid_block m b ->
Mem.perm_order'' ((getThreadR cnt).1 !! b ofs') (Some Writable) \/
Mem.perm_order'' ((getThreadR cnt).2 !! b ofs') (Some Writable)) /\
((Mem.perm_order'' ((getThreadR cnt').1 !! b ofs') (Some Writable) \/
Mem.perm_order'' ((getThreadR cnt').2 !! b ofs') (Some Writable)) \/
deadLocation tp' m' b ofs')
| None => False
end) /\
(caction ev ->
forall (cnt: containsThread tp (thread_id ev)) (cnt': containsThread tp' (thread_id ev)),
match location ev with
| Some (b, ofs, sz) =>
forall ofs', Intv.In ofs' (ofs, ofs + Z.of_nat sz)%Z ->
(Mem.valid_block m b ->
Mem.perm_order'' ((getThreadR cnt).1 !! b ofs') (Some Readable) \/
Mem.perm_order'' ((getThreadR cnt).2 !! b ofs') (Some Readable)) /\
((Mem.perm_order'' ((getThreadR cnt').1 !! b ofs') (Some Readable) \/
Mem.perm_order'' ((getThreadR cnt').2 !! b ofs') (Some Readable)) \/
(tr_pre = [::] /\ tr_post = [::] /\ action ev = Release /\
(exists rmap, sz = lksize.LKSIZE_nat /\
lockRes tp' (b, ofs) = Some rmap /\
(Mem.perm_order'' (rmap.1 !! b ofs') (Some Readable) \/
Mem.perm_order'' (rmap.2 !! b ofs') (Some Readable)))) \/
deadLocation tp' m' b ofs')
| None => False
end).
Lemma waction_caction:
forall ev,
waction ev -> caction ev.
Lemma raction_caction:
forall ev,
raction ev -> caction ev.
Lemma raction_waction:
forall ev,
raction ev -> ~ waction ev.
Lemma waction_raction:
forall ev,
waction ev -> ~ raction ev.
Lemma caction_location:
forall ev,
caction ev ->
exists b ofs sz, location ev = Some (b, ofs, sz).