Library zoo_parabs.waiter

Require Import zoo.prelude.
Require Import zoo.base.
Require Export zoo_parabs.base.
Require Export zoo_parabs.waiter__code.
Require Import zoo_parabs.waiter__types.
Require Import zoo.options.

Implicit Type b : bool.
Implicit Type 𝑡 : location.
Implicit Type v t mtx cond : val.

Class WaiterG Σ `{zoo۰G : !ZooG Σ} :=
  { #[local] waiter۰G۰mutex۰G :: MutexG Σ
  }.

Definition waiter۰Σ :=
  #[mutex۰Σ
  ].
#[global] Instance subGws_hub_Σ Σ `{zoo۰G : !ZooG Σ} :
  subG waiter۰Σ Σ
  WaiterG Σ.

Section waiter۰G.
  Context `{waiter۰G : WaiterG Σ}.

  #[local] Definition inv۰inner 𝑡 : iProp Σ :=
     b,
    𝑡.[flag] #b.
  #[local] Instance : CustomIpat "inv۰inner" :=
    " ( %b & H𝑡_flag ) ".
  Definition waiter۰inv t : iProp Σ :=
     𝑡 mtx cond,
    t = #𝑡
    𝑡.[mutex] mtx
    mutex۰inv mtx (inv۰inner 𝑡)
    𝑡.[condition] cond
    condition۰inv cond.
  #[local] Instance : CustomIpat "inv" :=
    " ( %𝑡 & %mtx & %cond & -> & #H𝑡_mutex & #Hmtx_inv & #H𝑡_condition & #Hcond_inv ) ".

  #[global] Instance waiter۰invpersistent t :
    Persistent (waiter۰inv t).

  Lemma waiter٠createspec :
    {{{
      True
    }}}
      waiter٠create ()
    {{{
      t
    , RET t;
      waiter۰inv t
    }}}.

  Lemma waiter٠notifyspec t :
    {{{
      waiter۰inv t
    }}}
      waiter٠notify t
    {{{
      b
    , RET #b;
      True
    }}}.

  Lemma waiter٠prepare_waitspec t :
    {{{
      waiter۰inv t
    }}}
      waiter٠prepare_wait t
    {{{
      RET ();
      True
    }}}.

  Lemma waiter٠cancel_waitspec t :
    {{{
      waiter۰inv t
    }}}
      waiter٠cancel_wait t
    {{{
      b
    , RET #b;
      True
    }}}.

  Lemma waiter٠commit_waitspec t :
    {{{
      waiter۰inv t
    }}}
      waiter٠commit_wait t
    {{{
      RET ();
      True
    }}}.
End waiter۰G.

Require zoo_parabs.waiter__opaque.

#[global] Opaque waiter۰inv.