Library zoo_std.condition

Require Import zoo.prelude.
Require Import zoo.base.
Require Export zoo_std.mutex.
Require Export zoo_std.condition__code.
Require Import zoo_std.condition__types.
Require Import zoo.options.

Implicit Type b : bool.
Implicit Type t pred : val.

Section mutex۰G.
  Context `{mutex۰G : MutexG Σ}.

  Definition condition۰inv t : iProp Σ :=
    True.

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

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

  Lemma condition٠notifyspec t :
    {{{
      condition۰inv t
    }}}
      condition٠notify t
    {{{
      RET ();
      True
    }}}.
  Lemma condition٠notifydiaspec t :
    DIASPEC
    {{
      condition۰inv t
    }}
      condition٠notify t
    {{
      RET ();
      True
    }}.

  Lemma condition٠notify_allspec t :
    {{{
      condition۰inv t
    }}}
      condition٠notify_all t
    {{{
      RET ();
      True
    }}}.
  #[global] Instance condition٠notify_alldiaspec t :
    DIASPEC
    {{
      condition۰inv t
    }}
      condition٠notify_all t
    {{
      RET ();
      True
    }}.

  Lemma condition٠waitspec t mtx P :
    {{{
      condition۰inv t
      mutex۰inv mtx P
      mutex۰locked mtx
      P
    }}}
      condition٠wait t mtx
    {{{
      RET ();
      mutex۰locked mtx
      P
    }}}.
  Lemma condition٠waitdiaspec t mtx P :
    DIASPEC
    {{
      condition۰inv t
      mutex۰inv mtx P
      mutex۰locked mtx
      P
    }}
      condition٠wait t mtx
    {{
      RET ();
      mutex۰locked mtx
      P
    }}.

  Lemma condition٠wait_untilspec' Ψ t mtx pred P :
    {{{
      condition۰inv t
      mutex۰inv mtx P
      mutex۰locked mtx
      P
      Ψ false
       (
        mutex۰locked mtx -∗
        P -∗
        Ψ false -∗
        WP pred () {{ res,
           b,
          res = #b
          mutex۰locked mtx
          (if b then True else P)
          Ψ b
        }}
      )
    }}}
      condition٠wait_until t mtx pred
    {{{
      RET ();
      mutex۰locked mtx
      Ψ true
    }}}.
  Lemma condition٠wait_untilspec Ψ t mtx pred P :
    {{{
      condition۰inv t
      mutex۰inv mtx P
      mutex۰locked mtx
      P
      Ψ false
       (
        mutex۰locked mtx -∗
        P -∗
        Ψ false -∗
        WP pred () {{ res,
           b,
          res = #b
          mutex۰locked mtx
          P
          Ψ b
        }}
      )
    }}}
      condition٠wait_until t mtx pred
    {{{
      RET ();
      mutex۰locked mtx
      P
      Ψ true
    }}}.

  Lemma condition٠wait_whilespec' Ψ t mtx pred P :
    {{{
      condition۰inv t
      mutex۰inv mtx P
      mutex۰locked mtx
      P
      Ψ true
       (
        mutex۰locked mtx -∗
        P -∗
        Ψ true -∗
        WP pred () {{ res,
           b,
          res = #b
          mutex۰locked mtx
          (if b then P else True)
          Ψ b
        }}
      )
    }}}
      condition٠wait_while t mtx pred
    {{{
      RET ();
      mutex۰locked mtx
      Ψ false
    }}}.
  Lemma condition٠wait_whilespec Ψ t mtx pred P :
    {{{
      condition۰inv t
      mutex۰inv mtx P
      mutex۰locked mtx
      P
      Ψ true
       (
        mutex۰locked mtx -∗
        P -∗
        Ψ true -∗
        WP pred () {{ res,
           b,
          res = #b
          mutex۰locked mtx
          P
          Ψ b
        }}
      )
    }}}
      condition٠wait_while t mtx pred
    {{{
      RET ();
      mutex۰locked mtx
      P
      Ψ false
    }}}.
End mutex۰G.

Require zoo_std.condition__opaque.

#[global] Opaque condition۰inv.