@@ -3,9 +3,7 @@ mod tests;
3
3
4
4
use crate :: cell:: UnsafeCell ;
5
5
use crate :: fmt;
6
- use crate :: mem;
7
6
use crate :: ops:: { Deref , DerefMut } ;
8
- use crate :: ptr;
9
7
use crate :: sync:: { poison, LockResult , TryLockError , TryLockResult } ;
10
8
use crate :: sys_common:: rwlock as sys;
11
9
@@ -66,7 +64,7 @@ use crate::sys_common::rwlock as sys;
66
64
/// [`Mutex`]: super::Mutex
67
65
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
68
66
pub struct RwLock < T : ?Sized > {
69
- inner : Box < sys:: RWLock > ,
67
+ inner : sys:: MovableRWLock ,
70
68
poison : poison:: Flag ,
71
69
data : UnsafeCell < T > ,
72
70
}
@@ -130,7 +128,7 @@ impl<T> RwLock<T> {
130
128
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
131
129
pub fn new ( t : T ) -> RwLock < T > {
132
130
RwLock {
133
- inner : box sys:: RWLock :: new ( ) ,
131
+ inner : sys:: MovableRWLock :: new ( ) ,
134
132
poison : poison:: Flag :: new ( ) ,
135
133
data : UnsafeCell :: new ( t) ,
136
134
}
@@ -376,24 +374,8 @@ impl<T: ?Sized> RwLock<T> {
376
374
where
377
375
T : Sized ,
378
376
{
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)
397
379
}
398
380
399
381
/// Returns a mutable reference to the underlying data.
@@ -424,14 +406,6 @@ impl<T: ?Sized> RwLock<T> {
424
406
}
425
407
}
426
408
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
-
435
409
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
436
410
impl < T : ?Sized + fmt:: Debug > fmt:: Debug for RwLock < T > {
437
411
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
0 commit comments