@@ -124,9 +124,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
124
124
#[ unsafe_no_drop_flag]
125
125
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
126
126
pub struct Arc < T : ?Sized > {
127
- // FIXME #12808: strange name to try to avoid interfering with
128
- // field accesses of the contained type via Deref
129
- _ptr : Shared < ArcInner < T > > ,
127
+ ptr : Shared < ArcInner < T > > ,
130
128
}
131
129
132
130
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -144,9 +142,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
144
142
#[ unsafe_no_drop_flag]
145
143
#[ stable( feature = "arc_weak" , since = "1.4.0" ) ]
146
144
pub struct Weak < T : ?Sized > {
147
- // FIXME #12808: strange name to try to avoid interfering with
148
- // field accesses of the contained type via Deref
149
- _ptr : Shared < ArcInner < T > > ,
145
+ ptr : Shared < ArcInner < T > > ,
150
146
}
151
147
152
148
#[ stable( feature = "arc_weak" , since = "1.4.0" ) ]
@@ -198,7 +194,7 @@ impl<T> Arc<T> {
198
194
weak : atomic:: AtomicUsize :: new ( 1 ) ,
199
195
data : data,
200
196
} ;
201
- Arc { _ptr : unsafe { Shared :: new ( Box :: into_raw ( x) ) } }
197
+ Arc { ptr : unsafe { Shared :: new ( Box :: into_raw ( x) ) } }
202
198
}
203
199
204
200
/// Unwraps the contained value if the `Arc<T>` has exactly one strong reference.
@@ -230,11 +226,11 @@ impl<T> Arc<T> {
230
226
atomic:: fence ( Acquire ) ;
231
227
232
228
unsafe {
233
- let ptr = * this. _ptr ;
229
+ let ptr = * this. ptr ;
234
230
let elem = ptr:: read ( & ( * ptr) . data ) ;
235
231
236
232
// Make a weak pointer to clean up the implicit strong-weak reference
237
- let _weak = Weak { _ptr : this. _ptr } ;
233
+ let _weak = Weak { ptr : this. ptr } ;
238
234
mem:: forget ( this) ;
239
235
240
236
Ok ( elem)
@@ -263,6 +259,7 @@ impl<T: ?Sized> Arc<T> {
263
259
loop {
264
260
// check if the weak counter is currently "locked"; if so, spin.
265
261
if cur == usize:: MAX {
262
+ cur = this. inner ( ) . weak . load ( Relaxed ) ;
266
263
continue ;
267
264
}
268
265
@@ -274,7 +271,7 @@ impl<T: ?Sized> Arc<T> {
274
271
// synchronize with the write coming from `is_unique`, so that the
275
272
// events prior to that write happen before this read.
276
273
match this. inner ( ) . weak . compare_exchange_weak ( cur, cur + 1 , Acquire , Relaxed ) {
277
- Ok ( _) => return Weak { _ptr : this. _ptr } ,
274
+ Ok ( _) => return Weak { ptr : this. ptr } ,
278
275
Err ( old) => cur = old,
279
276
}
280
277
}
@@ -303,13 +300,13 @@ impl<T: ?Sized> Arc<T> {
303
300
// `ArcInner` structure itself is `Sync` because the inner data is
304
301
// `Sync` as well, so we're ok loaning out an immutable pointer to these
305
302
// contents.
306
- unsafe { & * * self . _ptr }
303
+ unsafe { & * * self . ptr }
307
304
}
308
305
309
306
// Non-inlined part of `drop`.
310
307
#[ inline( never) ]
311
308
unsafe fn drop_slow ( & mut self ) {
312
- let ptr = * self . _ptr ;
309
+ let ptr = * self . ptr ;
313
310
314
311
// Destroy the data at this time, even though we may not free the box
315
312
// allocation itself (there may still be weak pointers lying around).
@@ -367,7 +364,7 @@ impl<T: ?Sized> Clone for Arc<T> {
367
364
}
368
365
}
369
366
370
- Arc { _ptr : self . _ptr }
367
+ Arc { ptr : self . ptr }
371
368
}
372
369
}
373
370
@@ -435,15 +432,15 @@ impl<T: Clone> Arc<T> {
435
432
436
433
// Materialize our own implicit weak pointer, so that it can clean
437
434
// up the ArcInner as needed.
438
- let weak = Weak { _ptr : this. _ptr } ;
435
+ let weak = Weak { ptr : this. ptr } ;
439
436
440
437
// mark the data itself as already deallocated
441
438
unsafe {
442
439
// there is no data race in the implicit write caused by `read`
443
440
// here (due to zeroing) because data is no longer accessed by
444
441
// other threads (due to there being no more strong refs at this
445
442
// point).
446
- let mut swap = Arc :: new ( ptr:: read ( & ( * * weak. _ptr ) . data ) ) ;
443
+ let mut swap = Arc :: new ( ptr:: read ( & ( * * weak. ptr ) . data ) ) ;
447
444
mem:: swap ( this, & mut swap) ;
448
445
mem:: forget ( swap) ;
449
446
}
@@ -456,7 +453,7 @@ impl<T: Clone> Arc<T> {
456
453
// As with `get_mut()`, the unsafety is ok because our reference was
457
454
// either unique to begin with, or became one upon cloning the contents.
458
455
unsafe {
459
- let inner = & mut * * this. _ptr ;
456
+ let inner = & mut * * this. ptr ;
460
457
& mut inner. data
461
458
}
462
459
}
@@ -488,7 +485,7 @@ impl<T: ?Sized> Arc<T> {
488
485
// the Arc itself to be `mut`, so we're returning the only possible
489
486
// reference to the inner data.
490
487
unsafe {
491
- let inner = & mut * * this. _ptr ;
488
+ let inner = & mut * * this. ptr ;
492
489
Some ( & mut inner. data )
493
490
}
494
491
} else {
@@ -557,7 +554,7 @@ impl<T: ?Sized> Drop for Arc<T> {
557
554
// This structure has #[unsafe_no_drop_flag], so this drop glue may run
558
555
// more than once (but it is guaranteed to be zeroed after the first if
559
556
// it's run more than once)
560
- let thin = * self . _ptr as * const ( ) ;
557
+ let thin = * self . ptr as * const ( ) ;
561
558
562
559
if thin as usize == mem:: POST_DROP_USIZE {
563
560
return ;
@@ -638,7 +635,7 @@ impl<T: ?Sized> Weak<T> {
638
635
639
636
// Relaxed is valid for the same reason it is on Arc's Clone impl
640
637
match inner. strong . compare_exchange_weak ( n, n + 1 , Relaxed , Relaxed ) {
641
- Ok ( _) => return Some ( Arc { _ptr : self . _ptr } ) ,
638
+ Ok ( _) => return Some ( Arc { ptr : self . ptr } ) ,
642
639
Err ( old) => n = old,
643
640
}
644
641
}
@@ -647,7 +644,7 @@ impl<T: ?Sized> Weak<T> {
647
644
#[ inline]
648
645
fn inner ( & self ) -> & ArcInner < T > {
649
646
// See comments above for why this is "safe"
650
- unsafe { & * * self . _ptr }
647
+ unsafe { & * * self . ptr }
651
648
}
652
649
}
653
650
@@ -681,7 +678,7 @@ impl<T: ?Sized> Clone for Weak<T> {
681
678
}
682
679
}
683
680
684
- return Weak { _ptr : self . _ptr } ;
681
+ return Weak { ptr : self . ptr } ;
685
682
}
686
683
}
687
684
@@ -713,7 +710,7 @@ impl<T: ?Sized> Drop for Weak<T> {
713
710
/// } // implicit drop
714
711
/// ```
715
712
fn drop ( & mut self ) {
716
- let ptr = * self . _ptr ;
713
+ let ptr = * self . ptr ;
717
714
let thin = ptr as * const ( ) ;
718
715
719
716
// see comments above for why this check is here
@@ -885,7 +882,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Arc<T> {
885
882
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
886
883
impl < T : ?Sized > fmt:: Pointer for Arc < T > {
887
884
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
888
- fmt:: Pointer :: fmt ( & * self . _ptr , f)
885
+ fmt:: Pointer :: fmt ( & * self . ptr , f)
889
886
}
890
887
}
891
888
@@ -930,7 +927,7 @@ impl<T> Weak<T> {
930
927
issue = "30425" ) ]
931
928
pub fn new ( ) -> Weak < T > {
932
929
unsafe {
933
- Weak { _ptr : Shared :: new ( Box :: into_raw ( box ArcInner {
930
+ Weak { ptr : Shared :: new ( Box :: into_raw ( box ArcInner {
934
931
strong : atomic:: AtomicUsize :: new ( 0 ) ,
935
932
weak : atomic:: AtomicUsize :: new ( 1 ) ,
936
933
data : uninitialized ( ) ,
0 commit comments