val new_lock (p:vprop)
  : SteelT (lock p) p (fun _ -> emp)
let new_lock (p:vprop)
  : SteelT (lock p) p (fun _ -> emp) =
  let r = alloc_pt available in
  intro_lockinv_available p r;
  let i:inv (lockinv p r) = new_invariant (lockinv p r) in
  return (Lock r i)
val new_lock (p:vprop)
  : SteelT (lock p) p (fun _ -> emp)
let new_lock (p: vprop) : SteelT (lock p) p (fun _ -> emp) =
let r = alloc_pt available in
intro_lockinv_available p r;
let i:inv (lockinv p r) = new_invariant (lockinv p r) in
return (Lock r i)
Steel.SpinLock.fst.checked
Steel.Reference.fsti.checked Steel.FractionalPermission.fst.checked Steel.Effect.Atomic.fsti.checked Steel.Effect.fsti.checked prims.fst.checked FStar.Pervasives.fsti.checked FStar.Ghost.fsti.checked
Steel.SpinLock.fst
Steel.Effect.Common.vprop Steel.Effect.Atomic.return Steel.SpinLock.lock FStar.Ghost.hide FStar.Set.set Steel.Memory.iname FStar.Set.empty FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit Steel.Effect.Common.req Steel.Effect.Common.rm Steel.SpinLock.Lock Steel.Effect.Common.inv Steel.SpinLock.lockinv Steel.Effect.Atomic.new_invariant Prims.unit Steel.SpinLock.intro_lockinv_available Steel.Reference.ref Prims.bool Steel.Reference.alloc_pt Steel.SpinLock.available Steel.Effect.Common.emp
(*
   Copyright 2020 Microsoft Research

   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.
*)

module Steel.SpinLock

open FStar.Ghost
open Steel.Effect.Atomic
open Steel.Effect
open Steel.Reference
open Steel.FractionalPermission

#set-options "--ide_id_info_off --fuel 0 --ifuel 0"

let available = false
let locked = true

let lockinv (p:vprop) (r:ref bool) : vprop =
  h_exists (fun b -> pts_to r full_perm b `star` (if b then emp else p))

noeq
type lock (p:vprop) = | Lock: r: ref bool -> i: inv (lockinv p r) -> lock p

val intro_lockinv_available (#uses:inames) (p:vprop) (r:ref bool)
  : SteelGhostT unit uses (pts_to r full_perm available `star` p) (fun _ -> lockinv p r)

val intro_lockinv_locked (#uses:inames) (p:vprop) (r:ref bool)
  : SteelGhostT unit uses (pts_to r full_perm locked) (fun _ -> lockinv p r)

let intro_lockinv_available #uses p r =
  intro_exists false
    (fun (b: bool) ->
      pts_to r full_perm b `star`
        (if b then emp else p)
    )

let intro_lockinv_locked #uses p r =
  intro_exists true
    (fun b -> pts_to r full_perm b `star`
          (if b then emp else p))
val new_lock (p:vprop)
  : SteelT (lock p) p (fun _ -> emp)
p: Steel.Effect.Common.vprop -> Steel.Effect.SteelT (Steel.SpinLock.lock p)