Skip to content

Commit 6b22d62

Browse files
committed
Introduce zero-varaint enum through external_type_specification
1 parent 3b205d7 commit 6b22d62

4 files changed

Lines changed: 28 additions & 20 deletions

File tree

ostd/src/sync/guard.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ use crate::{
1212
#[verus_verify]
1313
pub trait SpinGuardian {
1414
/// The guard type for holding a spin lock or a spin-based write lock.
15-
//type Guard: AsAtomicModeGuard + GuardTransfer;
16-
type Guard;
15+
type Guard: /*AsAtomicModeGuard + */GuardTransfer;
1716
/// The guard type for holding a spin-based read lock.
18-
//type ReadGuard: AsAtomicModeGuard + GuardTransfer;
19-
type ReadGuard;
17+
type ReadGuard: /*AsAtomicModeGuard +*/GuardTransfer;
2018

2119
/// Creates a new guard.
2220
fn guard() -> Self::Guard;
2321
/// Creates a new read guard.
2422
fn read_guard() -> Self::ReadGuard;
2523
}
2624

27-
/*
25+
2826
/// The Guard can be transferred atomically.
27+
#[verus_verify]
2928
pub trait GuardTransfer {
3029
/// Atomically transfers the current guard to a new instance.
3130
///
@@ -35,13 +34,16 @@ pub trait GuardTransfer {
3534
/// The original guard must be dropped immediately after calling this method.
3635
fn transfer_to(&mut self) -> Self;
3736
}
38-
*/
39-
/// A guardian that disables preemption while holding a lock.
40-
#[verus_verify]
41-
// pub enum PreemptDisabled {}
42-
pub struct PreemptDisabled;
4337

38+
/// A guardian that disables preemption while holding a lock.
4439
#[verifier::external]
40+
pub enum PreemptDisabled {}
41+
42+
#[verifier::external_type_specification]
43+
#[verifier::external_body]
44+
pub struct ExPreemptDisabled(PreemptDisabled);
45+
46+
#[verus_verify]
4547
impl SpinGuardian for PreemptDisabled {
4648
type Guard = DisabledPreemptGuard;
4749
type ReadGuard = DisabledPreemptGuard;
@@ -63,7 +65,13 @@ impl SpinGuardian for PreemptDisabled {
6365
/// IRQ handlers are allowed to get executed while holding the
6466
/// lock. For example, if a lock is never used in the interrupt
6567
/// context, then it is ok not to use this guardian in the process context.
68+
#[verifier::external]
6669
pub enum LocalIrqDisabled {}
70+
71+
#[verifier::external_type_specification]
72+
#[verifier::external_body]
73+
pub struct ExLocalIrqDisabled(LocalIrqDisabled);
74+
6775
/*
6876
impl SpinGuardian for LocalIrqDisabled {
6977
type Guard = DisabledLocalIrqGuard;

ostd/src/sync/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ mod spin;
1010
mod wait;
1111
//pub(crate) use self::rcu::finish_grace_period;
1212
pub use self::{
13-
guard::{
14-
/*GuardTransfer,*/
15-
LocalIrqDisabled, PreemptDisabled, /*SpinGuardian, WriteIrqDisabled*/
16-
},
13+
guard::{GuardTransfer, LocalIrqDisabled, PreemptDisabled, SpinGuardian, /*WriteIrqDisabled*/},
1714
//mutex::{ArcMutexGuard, Mutex, MutexGuard},
1815
rcu::{non_null /*, Rcu, RcuDrop, RcuOption, RcuOptionReadGuard, RcuReadGuard*/},
1916
rwarc::{RoArc, RwArc},

ostd/src/sync/rwlock.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use core::{
2121
};
2222

2323
use super::{
24-
guard::{/*GuardTransfer,*/ SpinGuardian},
25-
//PreemptDisabled,
24+
PreemptDisabled,
25+
guard::{GuardTransfer, SpinGuardian},
2626
};
2727
//use crate::task::atomic_mode::AsAtomicModeGuard;
2828

@@ -170,7 +170,7 @@ struct_with_invariants! {
170170
/// ```
171171
///
172172
/// [`SpinLock`]: super::SpinLock
173-
pub struct RwLock<T /* : ?Sized*/ , Guard /* = PreemptDisabled*/ > {
173+
pub struct RwLock<T /* : ?Sized*/ , Guard /* = PreemptDisabled*/ > {
174174
guard: PhantomData<Guard>,
175175
/// The internal representation of the lock state is as follows:
176176
/// - **Bit 63:** Writer lock.

ostd/src/task/preempt/guard.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// SPDX-License-Identifier: MPL-2.0
22
use vstd::prelude::*;
33

4-
// use crate::{sync::GuardTransfer, task::atomic_mode::InAtomicMode};
4+
use crate::{sync::GuardTransfer/*, task::atomic_mode::InAtomicMode*/};
55

66
/// A guard for disable preempt.
7+
#[verus_verify]
78
#[clippy::has_significant_drop]
89
#[must_use]
910
#[derive(Debug)]
10-
#[verus_verify]
1111
pub struct DisabledPreemptGuard {
1212
// This private field prevents user from constructing values of this type directly.
1313
_private: (),
@@ -25,13 +25,16 @@ impl DisabledPreemptGuard {
2525
Self { _private: () }
2626
}
2727
}
28-
28+
*/
29+
#[verus_verify]
2930
impl GuardTransfer for DisabledPreemptGuard {
31+
#[verifier::external_body]
3032
fn transfer_to(&mut self) -> Self {
3133
disable_preempt()
3234
}
3335
}
3436

37+
/*
3538
impl Drop for DisabledPreemptGuard {
3639
fn drop(&mut self) {
3740
super::cpu_local::dec_guard_count();

0 commit comments

Comments
 (0)