pub struct AtomicUsize(/* private fields */);Expand description
Creusot wrapper around std::sync::atomic::AtomicUsize.
Implementations§
Source§impl AtomicUsize
impl AtomicUsize
Sourcepub fn new(
val: usize,
sync_view: Ghost<&mut SyncView>,
) -> (Self, Ghost<Perm<AtomicUsize>>)
pub fn new( val: usize, sync_view: Ghost<&mut SyncView>, ) -> (Self, Ghost<Perm<AtomicUsize>>)
ensures
result.1.val() == FMap::singleton(result.0.get_timestamp(^sync_view), (val, ^sync_view))
ensures
**sync_view <= ^sync_viewensures
*result.1.ward() == result.0terminates
Sourcepub fn into_inner(
self,
own: Ghost<Perm<AtomicUsize>>,
) -> (usize, Ghost<SyncView>)
pub fn into_inner( self, own: Ghost<Perm<AtomicUsize>>, ) -> (usize, Ghost<SyncView>)
Wrapper for std::sync::atomic::AtomicUsize::into_inner.
requires
self == *own.ward()ensures
match own.val().lookup(self.get_timestamp(*result.1)) { Some((v, _)) => result.0 == v, None => false }
ensures
forall<t> match own.val().lookup(t) { Some((_, view)) => t <= self.get_timestamp(*result.1) && view <= *result.1, None => true }
terminates
Sourcepub fn refresh(
&mut self,
own: Ghost<&mut Perm<AtomicUsize>>,
sync_view: Ghost<&mut SyncView>,
)
pub fn refresh( &mut self, own: Ghost<&mut Perm<AtomicUsize>>, sync_view: Ghost<&mut SyncView>, )
Clear the old unusable history, thanks to the full ownership of the atomic.
requires
*self == *own.ward()ensures
**sync_view <= ^sync_viewensures
match (*own).val().lookup(self.get_timestamp(^sync_view)) { Some((v, _)) => (^own).val() == FMap::singleton(self.get_timestamp(^sync_view), (v, **sync_view)), None => false }
ensures
forall<t> match own.val().lookup(t) { Some((_, view)) => t <= self.get_timestamp(^sync_view) && view <= ^sync_view, None => true }
ensures
*self == ^selfterminates
Sourcepub fn compare_exchange<F, Success: UpdateOrdering, Failure: LoadOrdering>(
&self,
current: usize,
new: usize,
f: Ghost<F>,
) -> Result<usize, usize>
pub fn compare_exchange<F, Success: UpdateOrdering, Failure: LoadOrdering>( &self, current: usize, new: usize, f: Ghost<F>, ) -> Result<usize, usize>
Wrapper for std::sync::atomic::AtomicUsize::compare_exchange.
The load and the store are always sequentially consistent.
requires
forall<c: &mut Committer<Self, $type, _, _>> !c.shot_store() ==> c.ward() == *self ==> c.val_load().deep_model() == current.deep_model() ==> c.val_store() == new ==> f.precondition((Ok(c),)) && (f.postcondition_once((Ok(c),), ()) ==> (^c).shot_store())
requires
forall<c: &Committer<Self, $type, _, _>> !c.shot_store() ==> c.ward() == *self ==> // NOTE: This following line is not present for `weak` c.val_load().deep_model() != current.deep_model() ==> f.precondition((Err(c),))
ensures
(exists<c: &mut Committer<Self, $type, _, _>> !c.shot_store() && c.ward() == *self && c.val_load().deep_model() == current.deep_model() && c.val_store() == new && result == Ok(c.val_load()) && f.postcondition_once((Ok(c),), ())) || (exists<c: &Committer<Self, $type, _, _>> !c.shot_store() && c.ward() == *self && // NOTE: This following line is not present for `weak` c.val_load().deep_model() != current.deep_model() && result == Err(c.val_load()) && f.postcondition_once((Err(c),), ()) )
Sourcepub fn compare_exchange_weak<F, Success: UpdateOrdering, Failure: LoadOrdering>(
&self,
current: usize,
new: usize,
f: Ghost<F>,
) -> Result<usize, usize>
pub fn compare_exchange_weak<F, Success: UpdateOrdering, Failure: LoadOrdering>( &self, current: usize, new: usize, f: Ghost<F>, ) -> Result<usize, usize>
Wrapper for std::sync::atomic::AtomicUsize::compare_exchange_weak.
The load and the store are always sequentially consistent.
requires
forall<c: &mut Committer<Self, $type, _, _>> !c.shot_store() ==> c.ward() == *self ==> c.val_load().deep_model() == current.deep_model() ==> c.val_store() == new ==> f.precondition((Ok(c),)) && (f.postcondition_once((Ok(c),), ()) ==> (^c).shot_store())
requires
forall<c: &Committer<Self, $type, _, _>> !c.shot_store() ==> c.ward() == *self ==> f.precondition((Err(c),))
ensures
(exists<c: &mut Committer<Self, $type, _, _>> !c.shot_store() && c.ward() == *self && c.val_load().deep_model() == current.deep_model() && c.val_store() == new && result == Ok(c.val_load()) && f.postcondition_once((Ok(c),), ())) || (exists<c: &Committer<Self, $type, _, _>> !c.shot_store() && c.ward() == *self && result == Err(c.val_load()) && f.postcondition_once((Err(c),), ()) )
Sourcepub fn load<F, Load: LoadOrdering>(&self, f: Ghost<F>) -> usize
pub fn load<F, Load: LoadOrdering>(&self, f: Ghost<F>) -> usize
Wrapper for std::sync::atomic::AtomicUsize::load.
requires
forall<c: &Committer<Self, $type, Load, ()>> !c.shot_store() ==> c.ward() == *self ==> f.precondition((c,))
ensures
exists<c: &Committer<Self, $type, Load, ()>> !c.shot_store() && c.ward() == *self && c.val_load() == result && f.postcondition_once((c,), ())
Sourcepub fn store<F, Store: StoreOrdering>(&self, val: usize, f: Ghost<F>)
pub fn store<F, Store: StoreOrdering>(&self, val: usize, f: Ghost<F>)
Wrapper for std::sync::atomic::AtomicUsize::store.
requires
forall<c: &mut Committer<Self, $type, (), Store>> !c.shot_store() ==> c.ward() == *self ==> c.val_store() == val ==> f.precondition((c,)) && (f.postcondition_once((c,), ()) ==> (^c).shot_store())
ensures
exists<c: &mut Committer<Self, $type, (), Store>> !c.shot_store() && c.ward() == *self && c.val_store() == val && f.postcondition_once((c,), ())
Source§impl AtomicUsize
impl AtomicUsize
Sourcepub fn fetch_add<F, Ord: UpdateOrdering>(
&self,
val: usize,
f: Ghost<F>,
) -> usize
pub fn fetch_add<F, Ord: UpdateOrdering>( &self, val: usize, f: Ghost<F>, ) -> usize
Wrapper for std::sync::atomic::AtomicUsize::fetch_add.
requires
forall<c: &mut Committer<Self, $int_type, Ord::Load, Ord::Store>> !c.shot_store() ==> c.ward() == *self ==> c.val_store() == val + c.val_load() ==> f.precondition((c,)) && (f.postcondition_once((c,), ()) ==> (^c).shot_store())
ensures
exists<c: &mut Committer<Self, $int_type, Ord::Load, Ord::Store>> !c.shot_store() && c.ward() == *self && c.val_store() == val + c.val_load() && c.val_load() == result && f.postcondition_once((c,), ())
Trait Implementations§
Source§impl HasTimestamp for AtomicUsize
impl HasTimestamp for AtomicUsize
Source§fn get_timestamp(self, _: SyncView) -> Timestamp
fn get_timestamp(self, _: SyncView) -> Timestamp
logic(opaque) ⚠
Source§fn get_timestamp_monotonic(self, x: SyncView, y: SyncView)
fn get_timestamp_monotonic(self, x: SyncView, y: SyncView)
logic(law) ⚠
requires
x <= yensures
self.get_timestamp(x) <= self.get_timestamp(y)Source§impl PermTarget for AtomicUsize
impl PermTarget for AtomicUsize
Source§fn is_disjoint(
&self,
_self_val: &Self::Value,
other: &Self,
_other_val: &Self::Value,
) -> bool
fn is_disjoint( &self, _self_val: &Self::Value, other: &Self, _other_val: &Self::Value, ) -> bool
Perm::disjoint_lemma. Read moreAuto Trait Implementations§
impl !Freeze for AtomicUsize
impl Objective for AtomicUsize
impl RefUnwindSafe for AtomicUsize
impl Send for AtomicUsize
impl Sync for AtomicUsize
impl Unpin for AtomicUsize
impl UnsafeUnpin for AtomicUsize
impl UnwindSafe for AtomicUsize
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<G, T> Guard<FullBorrow<T>> for Gwhere
G: GuardRef<T>,
impl<G, T> Guard<FullBorrow<T>> for Gwhere
G: GuardRef<T>,
Source§fn guards(self, initial: FullBorrow<T>, current: FullBorrow<T>) -> bool
fn guards(self, initial: FullBorrow<T>, current: FullBorrow<T>) -> bool
logic(open, prophetic, inline)
self.guards_ref(current.cur()) && ^initial == ^current
Source§impl<C> GuardRef<Perm<C>> for Cwhere
C: PermTarget + ?Sized,
impl<C> GuardRef<Perm<C>> for Cwhere
C: PermTarget + ?Sized,
Source§fn guards_ref(self, c: Perm<C>) -> bool
fn guards_ref(self, c: Perm<C>) -> bool
logic(open, inline)
*c.ward() == self