Skip to content

Partial fix for #3369 #5058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ pub extern mod rustrt {
++n: libc::size_t);
}

#[abi = "rust-intrinsic"]
pub extern mod rusti {
pub fn move_val_init<T>(dst: &mut T, -src: T);
}

/// Returns the number of elements the vector can hold without reallocating
#[inline(always)]
pub pure fn capacity<T>(v: @[const T]) -> uint {
Expand Down Expand Up @@ -185,9 +180,10 @@ pub mod traits {
pub mod traits {}

pub mod raw {
use at_vec::{capacity, rusti, rustrt};
use at_vec::{capacity, rustrt};
use cast::transmute;
use libc;
use private::intrinsics::{move_val_init};
use ptr::addr_of;
use ptr;
use sys;
Expand Down Expand Up @@ -229,7 +225,7 @@ pub mod raw {
(**repr).unboxed.fill += sys::size_of::<T>();
let p = addr_of(&((**repr).unboxed.data));
let p = ptr::offset(p, fill) as *mut T;
rusti::move_val_init(&mut(*p), initval);
move_val_init(&mut(*p), initval);
}

pub unsafe fn push_slow<T>(v: &mut @[const T], initval: T) {
Expand Down
6 changes: 1 addition & 5 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use num::strconv;
use num;
use ops;
use option::Option;
use private::intrinsics::floorf32;
use from_str;
use to_str;

Expand Down Expand Up @@ -332,11 +333,6 @@ impl ops::Neg<f32> for f32 {
pure fn neg(&self) -> f32 { -*self }
}

#[abi="rust-intrinsic"]
pub extern {
fn floorf32(val: f32) -> f32;
}

impl num::Round for f32 {
#[inline(always)]
pure fn round(&self, mode: num::RoundMode) -> f32 {
Expand Down
6 changes: 1 addition & 5 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use num::strconv;
use num;
use ops;
use option::Option;
use private::intrinsics::floorf64;
use to_str;
use from_str;

Expand Down Expand Up @@ -357,11 +358,6 @@ impl ops::Neg<f64> for f64 {
pure fn neg(&self) -> f64 { -*self }
}

#[abi="rust-intrinsic"]
pub extern {
fn floorf64(val: f64) -> f64;
}

impl num::Round for f64 {
#[inline(always)]
pure fn round(&self, mode: num::RoundMode) -> f64 {
Expand Down
24 changes: 7 additions & 17 deletions src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ use libc;
use option;
use option::{None, Option, Some, unwrap};
use pipes;
use private::intrinsics;
use ptr;
use private;
use task;
Expand Down Expand Up @@ -256,37 +257,26 @@ pub fn entangle_buffer<T: Owned, Tstart: Owned>(
(SendPacketBuffered(p), RecvPacketBuffered(p))
}

#[abi = "rust-intrinsic"]
#[doc(hidden)]
extern mod rusti {
fn atomic_xchg(dst: &mut int, src: int) -> int;
fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
fn atomic_xchg_rel(dst: &mut int, src: int) -> int;

fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
fn atomic_xsub_rel(dst: &mut int, src: int) -> int;
}

// If I call the rusti versions directly from a polymorphic function,
// I get link errors. This is a bug that needs investigated more.
#[doc(hidden)]
pub fn atomic_xchng_rel(dst: &mut int, src: int) -> int {
unsafe {
rusti::atomic_xchg_rel(dst, src)
intrinsics::atomic_xchg_rel(dst, src)
}
}

#[doc(hidden)]
pub fn atomic_add_acq(dst: &mut int, src: int) -> int {
unsafe {
rusti::atomic_xadd_acq(dst, src)
intrinsics::atomic_xadd_acq(dst, src)
}
}

#[doc(hidden)]
pub fn atomic_sub_rel(dst: &mut int, src: int) -> int {
unsafe {
rusti::atomic_xsub_rel(dst, src)
intrinsics::atomic_xsub_rel(dst, src)
}
}

Expand All @@ -295,7 +285,7 @@ pub fn swap_task(dst: &mut *rust_task, src: *rust_task) -> *rust_task {
// It might be worth making both acquire and release versions of
// this.
unsafe {
transmute(rusti::atomic_xchg(transmute(dst), src as int))
transmute(intrinsics::atomic_xchg(transmute(dst), src as int))
}
}

Expand Down Expand Up @@ -335,14 +325,14 @@ fn wait_event(this: *rust_task) -> *libc::c_void {
#[doc(hidden)]
fn swap_state_acq(dst: &mut State, src: State) -> State {
unsafe {
transmute(rusti::atomic_xchg_acq(transmute(dst), src as int))
transmute(intrinsics::atomic_xchg_acq(transmute(dst), src as int))
}
}

#[doc(hidden)]
fn swap_state_rel(dst: &mut State, src: State) -> State {
unsafe {
transmute(rusti::atomic_xchg_rel(transmute(dst), src as int))
transmute(intrinsics::atomic_xchg_rel(transmute(dst), src as int))
}
}

Expand Down
18 changes: 7 additions & 11 deletions src/libcore/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub mod finally;
pub mod weak_task;
#[path = "private/exchange_alloc.rs"]
pub mod exchange_alloc;
#[path = "private/intrinsics.rs"]
pub mod intrinsics;

extern mod rustrt {
pub unsafe fn rust_create_little_lock() -> rust_little_lock;
Expand All @@ -43,13 +45,6 @@ extern mod rustrt {
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
}

#[abi = "rust-intrinsic"]
extern mod rusti {
fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
fn atomic_xadd(dst: &mut int, src: int) -> int;
fn atomic_xsub(dst: &mut int, src: int) -> int;
}

#[allow(non_camel_case_types)] // runtime type
type raw_thread = libc::c_void;

Expand Down Expand Up @@ -101,7 +96,7 @@ fn test_run_in_bare_thread_exchange() {

fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool {
unsafe {
let old = rusti::atomic_cxchg(address, oldval, newval);
let old = intrinsics::atomic_cxchg(address, oldval, newval);
old == oldval
}
}
Expand Down Expand Up @@ -132,7 +127,8 @@ struct ArcDestruct<T> {
}
do task::unkillable {
let data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
let new_count = rusti::atomic_xsub(&mut data.count, 1) - 1;
let new_count =
intrinsics::atomic_xsub(&mut data.count, 1) - 1;
assert new_count >= 0;
if new_count == 0 {
// Were we really last, or should we hand off to an
Expand Down Expand Up @@ -205,7 +201,7 @@ pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
// Got in. Step 0: Tell destructor not to run. We are now it.
rc.data = ptr::null();
// Step 1 - drop our own reference.
let new_count = rusti::atomic_xsub(&mut ptr.count, 1) - 1;
let new_count = intrinsics::atomic_xsub(&mut ptr.count, 1) - 1;
//assert new_count >= 0;
if new_count == 0 {
// We were the last owner. Can unwrap immediately.
Expand Down Expand Up @@ -284,7 +280,7 @@ pub unsafe fn clone_shared_mutable_state<T: Owned>(rc: &SharedMutableState<T>)
-> SharedMutableState<T> {
unsafe {
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
let new_count = rusti::atomic_xadd(&mut ptr.count, 1) + 1;
let new_count = intrinsics::atomic_xadd(&mut ptr.count, 1) + 1;
assert new_count >= 2;
cast::forget(ptr);
}
Expand Down
6 changes: 0 additions & 6 deletions src/libcore/private/at_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ fn exit_runner(exit_fns: *ExitFunctions) {
}
}

#[abi = "rust-intrinsic"]
pub extern mod rusti {
fn move_val_init<T>(dst: &mut T, -src: T);
fn init<T>() -> T;
}

#[test]
fn test_at_exit() {
let i = 10;
Expand Down
10 changes: 3 additions & 7 deletions src/libcore/private/exchange_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use c_malloc = libc::malloc;
use c_free = libc::free;
use managed::raw::{BoxHeaderRepr, BoxRepr};
use cast::transmute;
use private::intrinsics::{atomic_xadd,atomic_xsub};
use ptr::null;
use intrinsic::TyDesc;

Expand All @@ -35,15 +36,15 @@ pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
box.header.next = null();

let exchange_count = &mut *rust_get_exchange_count_ptr();
rusti::atomic_xadd(exchange_count, 1);
atomic_xadd(exchange_count, 1);

return transmute(box);
}
}

pub unsafe fn free(ptr: *c_void) {
let exchange_count = &mut *rust_get_exchange_count_ptr();
rusti::atomic_xsub(exchange_count, 1);
atomic_xsub(exchange_count, 1);

assert ptr.is_not_null();
c_free(ptr);
Expand All @@ -68,8 +69,3 @@ extern {
fn rust_get_exchange_count_ptr() -> *mut int;
}

#[abi = "rust-intrinsic"]
extern mod rusti {
fn atomic_xadd(dst: &mut int, src: int) -> int;
fn atomic_xsub(dst: &mut int, src: int) -> int;
}
6 changes: 1 addition & 5 deletions src/libcore/private/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use private::{Exclusive, exclusive};
use private::{SharedMutableState, shared_mutable_state};
use private::{get_shared_immutable_state};
use private::at_exit::at_exit;
use private::intrinsics::atomic_cxchg;
use hashmap::linear::LinearMap;
use sys::Closure;
use task::spawn;
Expand Down Expand Up @@ -231,11 +232,6 @@ extern {
fn rust_get_global_data_ptr() -> *mut int;
}

#[abi = "rust-intrinsic"]
extern {
fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
}

#[test]
fn test_clone_rc() {
type MyType = SharedMutableState<int>;
Expand Down
Loading