@@ -38,13 +38,16 @@ struct SharedState {
38
38
}
39
39
40
40
impl SharedState {
41
- fn try_new ( ) -> Result < Arc < Self > > {
42
- let state = Arc :: try_new ( Self {
43
- // SAFETY: `condvar_init!` is called below.
44
- state_changed : unsafe { CondVar :: new ( ) } ,
45
- // SAFETY: `mutex_init!` is called below.
46
- inner : unsafe { Mutex :: new ( SharedStateInner { token_count : 0 } ) } ,
47
- } ) ?;
41
+ fn try_new ( ) -> Result < Pin < Arc < Self > > > {
42
+ // SAFETY: `state` is pinning `Arc`, which implements `Unpin`.
43
+ let state = unsafe {
44
+ Pin :: new_unchecked ( Arc :: try_new ( Self {
45
+ // SAFETY: `condvar_init!` is called below.
46
+ state_changed : CondVar :: new ( ) ,
47
+ // SAFETY: `mutex_init!` is called below.
48
+ inner : Mutex :: new ( SharedStateInner { token_count : 0 } ) ,
49
+ } ) ?)
50
+ } ;
48
51
// SAFETY: `state_changed` is pinned behind `Arc`.
49
52
let state_changed = unsafe { Pin :: new_unchecked ( & state. state_changed ) } ;
50
53
kernel:: condvar_init!( state_changed, "SharedState::state_changed" ) ;
@@ -56,11 +59,11 @@ impl SharedState {
56
59
}
57
60
58
61
struct Token {
59
- shared : Arc < SharedState > ,
62
+ shared : Pin < Arc < SharedState > > ,
60
63
}
61
64
62
- impl FileOpener < Arc < SharedState > > for Token {
63
- fn open ( shared : & Arc < SharedState > ) -> Result < Self :: Wrapper > {
65
+ impl FileOpener < Pin < Arc < SharedState > > > for Token {
66
+ fn open ( shared : & Pin < Arc < SharedState > > ) -> Result < Self :: Wrapper > {
64
67
Ok ( Box :: try_new ( Self {
65
68
shared : shared. clone ( ) ,
66
69
} ) ?)
@@ -122,7 +125,7 @@ impl FileOperations for Token {
122
125
}
123
126
124
127
struct RustMiscdev {
125
- _dev : Pin < Box < miscdev:: Registration < Arc < SharedState > > > > ,
128
+ _dev : Pin < Box < miscdev:: Registration < Pin < Arc < SharedState > > > > > ,
126
129
}
127
130
128
131
impl KernelModule for RustMiscdev {
0 commit comments