Skip to content

Commit d89b4c8

Browse files
committed
std: Modify arc to tolerate upcoming change to uniques
1 parent 174f789 commit d89b4c8

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/libstd/arc.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ type arc_data<T> = {
1919
data: T
2020
};
2121

22-
resource arc_destruct<T>(data: *arc_data<T>) {
22+
resource arc_destruct<T>(data: *libc::c_void) {
2323
unsafe {
24-
let ptr = &mut (*data).count;
24+
let data: ~arc_data<T> = unsafe::reinterpret_cast(data);
25+
let ref_ptr = &mut data.count;
2526

26-
let new_count = rustrt::rust_atomic_decrement(ptr);
27+
let new_count = rustrt::rust_atomic_decrement(ref_ptr);
2728
assert new_count >= 0;
2829
if new_count == 0 {
29-
let _ptr : ~arc_data<T> = unsafe::reinterpret_cast(data);
3030
// drop glue takes over.
31+
} else {
32+
unsafe::forget(data);
3133
}
3234
}
3335
}
@@ -48,7 +50,11 @@ fn arc<T>(-data: T) -> arc<T> {
4850
wrapper."]
4951
fn get<T>(rc: &a.arc<T>) -> &a.T {
5052
unsafe {
51-
&(***rc).data
53+
let ptr: ~arc_data<T> = unsafe::reinterpret_cast(**rc);
54+
// Cast us back into the correct region
55+
let r = unsafe::reinterpret_cast(&ptr.data);
56+
unsafe::forget(ptr);
57+
ret r;
5258
}
5359
}
5460

@@ -58,9 +64,10 @@ The resulting two `arc` objects will point to the same underlying data
5864
object. However, one of the `arc` objects can be sent to another task,
5965
allowing them to share the underlying data."]
6066
fn clone<T>(rc: &arc<T>) -> arc<T> {
61-
let data = **rc;
6267
unsafe {
63-
rustrt::rust_atomic_increment(&mut (*data).count);
68+
let ptr: ~arc_data<T> = unsafe::reinterpret_cast(**rc);
69+
rustrt::rust_atomic_increment(&mut ptr.count);
70+
unsafe::forget(ptr);
6471
}
6572
arc_destruct(**rc)
6673
}

0 commit comments

Comments
 (0)