@@ -3,9 +3,7 @@ mod tests;
33
44use crate :: cell:: UnsafeCell ;
55use crate :: fmt;
6- use crate :: mem;
76use crate :: ops:: { Deref , DerefMut } ;
8- use crate :: ptr;
97use crate :: sync:: { poison, LockResult , TryLockError , TryLockResult } ;
108use crate :: sys_common:: rwlock as sys;
119
@@ -66,7 +64,7 @@ use crate::sys_common::rwlock as sys;
6664/// [`Mutex`]: super::Mutex
6765#[ stable( feature = "rust1" , since = "1.0.0" ) ]
6866pub struct RwLock < T : ?Sized > {
69- inner : Box < sys:: RWLock > ,
67+ inner : sys:: MovableRWLock ,
7068 poison : poison:: Flag ,
7169 data : UnsafeCell < T > ,
7270}
@@ -130,7 +128,7 @@ impl<T> RwLock<T> {
130128 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
131129 pub fn new ( t : T ) -> RwLock < T > {
132130 RwLock {
133- inner : box sys:: RWLock :: new ( ) ,
131+ inner : sys:: MovableRWLock :: new ( ) ,
134132 poison : poison:: Flag :: new ( ) ,
135133 data : UnsafeCell :: new ( t) ,
136134 }
@@ -376,24 +374,8 @@ impl<T: ?Sized> RwLock<T> {
376374 where
377375 T : Sized ,
378376 {
379- // We know statically that there are no outstanding references to
380- // `self` so there's no need to lock the inner lock.
381- //
382- // To get the inner value, we'd like to call `data.into_inner()`,
383- // but because `RwLock` impl-s `Drop`, we can't move out of it, so
384- // we'll have to destructure it manually instead.
385- unsafe {
386- // Like `let RwLock { inner, poison, data } = self`.
387- let ( inner, poison, data) = {
388- let RwLock { ref inner, ref poison, ref data } = self ;
389- ( ptr:: read ( inner) , ptr:: read ( poison) , ptr:: read ( data) )
390- } ;
391- mem:: forget ( self ) ;
392- inner. destroy ( ) ; // Keep in sync with the `Drop` impl.
393- drop ( inner) ;
394-
395- poison:: map_result ( poison. borrow ( ) , |_| data. into_inner ( ) )
396- }
377+ let data = self . data . into_inner ( ) ;
378+ poison:: map_result ( self . poison . borrow ( ) , |_| data)
397379 }
398380
399381 /// Returns a mutable reference to the underlying data.
@@ -424,14 +406,6 @@ impl<T: ?Sized> RwLock<T> {
424406 }
425407}
426408
427- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
428- unsafe impl < #[ may_dangle] T : ?Sized > Drop for RwLock < T > {
429- fn drop ( & mut self ) {
430- // IMPORTANT: This code needs to be kept in sync with `RwLock::into_inner`.
431- unsafe { self . inner . destroy ( ) }
432- }
433- }
434-
435409#[ stable( feature = "rust1" , since = "1.0.0" ) ]
436410impl < T : ?Sized + fmt:: Debug > fmt:: Debug for RwLock < T > {
437411 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
0 commit comments