@@ -8,7 +8,7 @@ use kernel::{
88 linked_list:: List ,
99 linked_list:: { GetLinks , Links } ,
1010 prelude:: * ,
11- sync:: { Ref , SpinLock } ,
11+ sync:: { Ref , SpinLock , UniqueRef } ,
1212 user_ptr:: UserSlicePtrWriter ,
1313 ScopeGuard ,
1414} ;
@@ -55,29 +55,27 @@ impl Transaction {
5555 let data_address = alloc. ptr ;
5656 let file_list = alloc. take_file_list ( ) ;
5757 alloc. keep_alive ( ) ;
58- let tr = Ref :: try_new_and_init (
59- Self {
60- // SAFETY: `spinlock_init` is called below.
61- inner : unsafe { SpinLock :: new ( TransactionInner { file_list } ) } ,
62- node_ref : Some ( node_ref) ,
63- stack_next,
64- from : from. clone ( ) ,
65- to,
66- code : tr. code ,
67- flags : tr. flags ,
68- data_size : tr. data_size as _ ,
69- data_address,
70- offsets_size : tr. offsets_size as _ ,
71- links : Links :: new ( ) ,
72- free_allocation : AtomicBool :: new ( true ) ,
73- } ,
74- |mut tr| {
75- // SAFETY: `inner` is pinned when `tr` is.
76- let pinned = unsafe { tr. as_mut ( ) . map_unchecked_mut ( |t| & mut t. inner ) } ;
77- kernel:: spinlock_init!( pinned, "Transaction::inner" ) ;
78- } ,
79- ) ?;
80- Ok ( tr)
58+ let mut tr = Pin :: from ( UniqueRef :: try_new ( Self {
59+ // SAFETY: `spinlock_init` is called below.
60+ inner : unsafe { SpinLock :: new ( TransactionInner { file_list } ) } ,
61+ node_ref : Some ( node_ref) ,
62+ stack_next,
63+ from : from. clone ( ) ,
64+ to,
65+ code : tr. code ,
66+ flags : tr. flags ,
67+ data_size : tr. data_size as _ ,
68+ data_address,
69+ offsets_size : tr. offsets_size as _ ,
70+ links : Links :: new ( ) ,
71+ free_allocation : AtomicBool :: new ( true ) ,
72+ } ) ?) ;
73+
74+ // SAFETY: `inner` is pinned when `tr` is.
75+ let pinned = unsafe { tr. as_mut ( ) . map_unchecked_mut ( |t| & mut t. inner ) } ;
76+ kernel:: spinlock_init!( pinned, "Transaction::inner" ) ;
77+
78+ Ok ( tr. into ( ) )
8179 }
8280
8381 pub ( crate ) fn new_reply (
@@ -90,29 +88,27 @@ impl Transaction {
9088 let data_address = alloc. ptr ;
9189 let file_list = alloc. take_file_list ( ) ;
9290 alloc. keep_alive ( ) ;
93- let tr = Ref :: try_new_and_init (
94- Self {
95- // SAFETY: `spinlock_init` is called below.
96- inner : unsafe { SpinLock :: new ( TransactionInner { file_list } ) } ,
97- node_ref : None ,
98- stack_next : None ,
99- from : from. clone ( ) ,
100- to,
101- code : tr. code ,
102- flags : tr. flags ,
103- data_size : tr. data_size as _ ,
104- data_address,
105- offsets_size : tr. offsets_size as _ ,
106- links : Links :: new ( ) ,
107- free_allocation : AtomicBool :: new ( true ) ,
108- } ,
109- |mut tr| {
110- // SAFETY: `inner` is pinned when `tr` is.
111- let pinned = unsafe { tr. as_mut ( ) . map_unchecked_mut ( |t| & mut t. inner ) } ;
112- kernel:: spinlock_init!( pinned, "Transaction::inner" ) ;
113- } ,
114- ) ?;
115- Ok ( tr)
91+ let mut tr = Pin :: from ( UniqueRef :: try_new ( Self {
92+ // SAFETY: `spinlock_init` is called below.
93+ inner : unsafe { SpinLock :: new ( TransactionInner { file_list } ) } ,
94+ node_ref : None ,
95+ stack_next : None ,
96+ from : from. clone ( ) ,
97+ to,
98+ code : tr. code ,
99+ flags : tr. flags ,
100+ data_size : tr. data_size as _ ,
101+ data_address,
102+ offsets_size : tr. offsets_size as _ ,
103+ links : Links :: new ( ) ,
104+ free_allocation : AtomicBool :: new ( true ) ,
105+ } ) ?) ;
106+
107+ // SAFETY: `inner` is pinned when `tr` is.
108+ let pinned = unsafe { tr. as_mut ( ) . map_unchecked_mut ( |t| & mut t. inner ) } ;
109+ kernel:: spinlock_init!( pinned, "Transaction::inner" ) ;
110+
111+ Ok ( tr. into ( ) )
116112 }
117113
118114 /// Determines if the transaction is stacked on top of the given transaction.
0 commit comments