11// SPDX-License-Identifier: MPL-2.0
2+ use vstd:: prelude:: * ;
3+ use vstd:: cell:: { self , PCell } ;
4+
25use alloc:: sync:: Arc ;
36use core:: {
47 cell:: UnsafeCell ,
@@ -8,8 +11,8 @@ use core::{
811 sync:: atomic:: { AtomicBool , Ordering } ,
912} ;
1013
11- use super :: { guard:: SpinGuardian , LocalIrqDisabled , PreemptDisabled } ;
12- use crate :: task:: atomic_mode:: AsAtomicModeGuard ;
14+ // use super::{guard::SpinGuardian, LocalIrqDisabled, PreemptDisabled};
15+ // use crate::task::atomic_mode::AsAtomicModeGuard;
1316
1417/// A spin lock.
1518///
@@ -27,32 +30,41 @@ use crate::task::atomic_mode::AsAtomicModeGuard;
2730///
2831/// [`disable_irq`]: Self::disable_irq
2932#[ repr( transparent) ]
30- pub struct SpinLock < T : ?Sized , G = PreemptDisabled > {
33+ #[ verus_verify]
34+ //pub struct SpinLock<T: ?Sized, G = PreemptDisabled> {
35+ pub struct SpinLock < T , G > {
3136 phantom : PhantomData < G > ,
3237 /// Only the last field of a struct may have a dynamically sized type.
3338 /// That's why SpinLockInner is put in the last field.
3439 inner : SpinLockInner < T > ,
3540}
3641
37- struct SpinLockInner < T : ?Sized > {
42+ #[ verus_verify]
43+ struct SpinLockInner < T > {
3844 lock : AtomicBool ,
39- val : UnsafeCell < T > ,
45+ //val: UnsafeCell<T>,
46+ val : PCell < T > ,
4047}
4148
49+ verus ! {
50+ #[ verus_verify]
4251impl <T , G > SpinLock <T , G > {
4352 /// Creates a new spin lock.
4453 pub const fn new( val: T ) -> Self {
54+ let ( val, Tracked ( perm) ) = PCell :: new( val) ;
4555 let lock_inner = SpinLockInner {
4656 lock: AtomicBool :: new( false ) ,
47- val : UnsafeCell :: new ( val) ,
57+ //val: UnsafeCell::new(val),
58+ val: val,
4859 } ;
4960 Self {
5061 phantom: PhantomData ,
5162 inner: lock_inner,
5263 }
5364 }
5465}
55-
66+ }
67+ /*
5668impl<T: ?Sized> SpinLock<T, PreemptDisabled> {
5769 /// Converts the guard behavior from disabling preemption to disabling IRQs.
5870 pub fn disable_irq(&self) -> &SpinLock<T, LocalIrqDisabled> {
@@ -156,14 +168,14 @@ pub struct SpinLockGuard_<T: ?Sized, R: Deref<Target = SpinLock<T, G>>, G: SpinG
156168 guard: G::Guard,
157169 lock: R,
158170}
159-
171+ /*
160172impl<T: ?Sized, R: Deref<Target = SpinLock<T, G>>, G: SpinGuardian> AsAtomicModeGuard
161173 for SpinLockGuard_<T, R, G>
162174{
163175 fn as_atomic_mode_guard(&self) -> &dyn crate::task::atomic_mode::InAtomicMode {
164176 self.guard.as_atomic_mode_guard()
165177 }
166- }
178+ }*/
167179
168180impl<T: ?Sized, R: Deref<Target = SpinLock<T, G>>, G: SpinGuardian> Deref
169181 for SpinLockGuard_<T, R, G>
@@ -210,3 +222,4 @@ unsafe impl<T: ?Sized + Sync, R: Deref<Target = SpinLock<T, G>> + Sync, G: SpinG
210222 for SpinLockGuard_<T, R, G>
211223{
212224}
225+ */
0 commit comments