Fix Arc Clone

pull/255/head
ThePuzzlemaker 4 years ago committed by Alexis Beingessner
parent 57fd6cf32b
commit e16ed7f336

@ -55,7 +55,7 @@ machines) incrementing the reference count at once. This is what we'll do.
It's pretty simple to implement this behaviour:
```rust,ignore
if old_rc >= isize::MAX {
if old_rc >= isize::MAX as usize {
std::process::abort();
}
```
@ -77,9 +77,9 @@ impl<T> Clone for Arc<T> {
let inner = unsafe { self.ptr.as_ref() };
// Using a relaxed ordering is alright here as knowledge of the original
// reference prevents other threads from wrongly deleting the object.
inner.rc.fetch_add(1, Ordering::Relaxed);
let old_rc = inner.rc.fetch_add(1, Ordering::Relaxed);
if old_rc >= isize::MAX {
if old_rc >= isize::MAX as usize {
std::process::abort();
}

@ -46,16 +46,14 @@ impl<T> Deref for Arc<T> {
}
}
use std::sync::atomic::Ordering;
impl<T> Clone for Arc<T> {
fn clone(&self) -> Arc<T> {
let inner = unsafe { self.ptr.as_ref() };
// Using a relaxed ordering is alright here as knowledge of the original
// reference prevents other threads from wrongly deleting the object.
inner.rc.fetch_add(1, Ordering::Relaxed);
let old_rc = inner.rc.fetch_add(1, Ordering::Relaxed);
if old_rc >= isize::MAX {
if old_rc >= isize::MAX as usize {
std::process::abort();
}

Loading…
Cancel
Save