rewrite arc to use region & expressions (also making it pass borrowck)
This commit is contained in:
parent
4fec4cd8f5
commit
6ca6a3b80b
1 changed files with 4 additions and 5 deletions
|
@ -6,11 +6,11 @@ export arc, get, clone;
|
||||||
#[abi = "cdecl"]
|
#[abi = "cdecl"]
|
||||||
native mod rustrt {
|
native mod rustrt {
|
||||||
#[rust_stack]
|
#[rust_stack]
|
||||||
fn rust_atomic_increment(p: *mut libc::intptr_t)
|
fn rust_atomic_increment(p: &mut libc::intptr_t)
|
||||||
-> libc::intptr_t;
|
-> libc::intptr_t;
|
||||||
|
|
||||||
#[rust_stack]
|
#[rust_stack]
|
||||||
fn rust_atomic_decrement(p: *mut libc::intptr_t)
|
fn rust_atomic_decrement(p: &mut libc::intptr_t)
|
||||||
-> libc::intptr_t;
|
-> libc::intptr_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ type arc_data<T> = {
|
||||||
|
|
||||||
resource arc_destruct<T>(data: *arc_data<T>) {
|
resource arc_destruct<T>(data: *arc_data<T>) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = ptr::mut_addr_of((*data).count);
|
let ptr = &mut (*data).count;
|
||||||
|
|
||||||
let new_count = rustrt::rust_atomic_decrement(ptr);
|
let new_count = rustrt::rust_atomic_decrement(ptr);
|
||||||
assert new_count >= 0;
|
assert new_count >= 0;
|
||||||
|
@ -52,8 +52,7 @@ fn get<T>(rc: &a.arc<T>) -> &a.T {
|
||||||
fn clone<T>(rc: &arc<T>) -> arc<T> {
|
fn clone<T>(rc: &arc<T>) -> arc<T> {
|
||||||
let data = **rc;
|
let data = **rc;
|
||||||
unsafe {
|
unsafe {
|
||||||
rustrt::rust_atomic_increment(
|
rustrt::rust_atomic_increment(&mut (*data).count);
|
||||||
ptr::mut_addr_of((*data).count));
|
|
||||||
}
|
}
|
||||||
arc_destruct(**rc)
|
arc_destruct(**rc)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue