(* Copyright 2013 IMDEA Software Institute 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. *)
(******************************************************************************)
(* This file defines the generalized mutex type.                              *)
(* We need a notion of mutex where the options are not just nown/own but      *)
(* an arbitrary number of elements in-between. This reflects the possible     *)
(* stages of acquiring a lock. Once a thread embarks on the first stage, it   *)
(* excludes others, but it may require more steps to fully acquire the lock.  *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(***********************)
(* Generalized mutexes *)
(***********************)
Module GeneralizedMutex.
Section GeneralizedMutex.
Variable T : Type. (* the mutex stages, excluding undef and unit *)
Inductive mutex := undef | nown | own | mx of T.
Definition join x y :=
match x, y with
undef, _ => undef
| _, undef => undef
| nown, x => x
| x, nown => x
| own, _ => undef
| _, own => undef
| mx _, mx _ => undef
end.
Definition valid x := if x is undef then false else true.

Lemma joinC : commutative join.
Definition mutexEqMix := EqMixin mutex_eqP.