File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -155,21 +155,28 @@ pub struct WriteTransaction<F> {
155155}
156156
157157pub struct TxGuardOwned < F > {
158- _lock : async_lock:: MutexGuardArc < Option < u64 > > ,
159- inner : WriteTransaction < F > ,
158+ _lock : Option < async_lock:: MutexGuardArc < Option < u64 > > > ,
159+ inner : Option < WriteTransaction < F > > ,
160+ }
161+
162+ impl < F > Drop for TxGuardOwned < F > {
163+ fn drop ( & mut self ) {
164+ let _ = self . _lock . take ( ) ;
165+ self . inner . take ( ) . expect ( "already dropped" ) . downgrade ( ) ;
166+ }
160167}
161168
162169impl < F > Deref for TxGuardOwned < F > {
163170 type Target = WriteTransaction < F > ;
164171
165172 fn deref ( & self ) -> & Self :: Target {
166- & self . inner
173+ self . inner . as_ref ( ) . expect ( "guard used after drop" )
167174 }
168175}
169176
170177impl < F > DerefMut for TxGuardOwned < F > {
171178 fn deref_mut ( & mut self ) -> & mut Self :: Target {
172- & mut self . inner
179+ self . inner . as_mut ( ) . expect ( "guard used after drop" )
173180 }
174181}
175182
@@ -238,8 +245,8 @@ impl<F> WriteTransaction<F> {
238245 match * g {
239246 // we still hold the lock, we can proceed
240247 Some ( id) if self . id == id => TxGuardOwned {
241- _lock : g ,
242- inner : self ,
248+ _lock : Some ( g ) ,
249+ inner : Some ( self ) ,
243250 } ,
244251 // Somebody took the lock from us
245252 Some ( _) => todo ! ( "lock stolen" ) ,
You can’t perform that action at this time.
0 commit comments