Skip to content
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
34 changes: 18 additions & 16 deletions src/libcargo/cargo.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1136,28 +1136,30 @@ fn get_temp_workdir(c: &Cargo) -> Path {
}
}

fn cmd_install(c: &Cargo) unsafe {
let wd = get_temp_workdir(c);
fn cmd_install(c: &Cargo) {
unsafe {
let wd = get_temp_workdir(c);

if vec::len(c.opts.free) == 2u {
let cwd = os::getcwd();
let status = run::run_program(~"cp", ~[~"-R", cwd.to_str(),
wd.to_str()]);
if vec::len(c.opts.free) == 2u {
let cwd = os::getcwd();
let status = run::run_program(~"cp", ~[~"-R", cwd.to_str(),
wd.to_str()]);

if status != 0 {
fail fmt!("could not copy directory: %s", cwd.to_str());
}
if status != 0 {
fail fmt!("could not copy directory: %s", cwd.to_str());
}

install_source(c, &wd);
return;
}
install_source(c, &wd);
return;
}

sync(c);
sync(c);

let query = c.opts.free[2];
c.current_install = query.to_str();
let query = c.opts.free[2];
c.current_install = query.to_str();

install_query(c, &wd, query);
install_query(c, &wd, query);
}
}

fn sync(c: &Cargo) {
Expand Down
8 changes: 5 additions & 3 deletions src/libcore/oldcomm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ pub fn listen<T: Owned, U>(f: fn(Chan<T>) -> U) -> U {
}

struct PortPtr<T:Owned> {
po: *rust_port,
drop unsafe {
po: *rust_port,
drop {
unsafe {
do task::unkillable {
// Once the port is detached it's guaranteed not to receive further
// messages
Expand All @@ -140,6 +141,7 @@ struct PortPtr<T:Owned> {
recv_::<T>(self.po);
}
rustrt::del_port(self.po);
}
}
}
}
Expand Down Expand Up @@ -209,7 +211,7 @@ pub fn send<T: Owned>(ch: Chan<T>, data: T) {
let Chan_(p) = ch;
let data_ptr = ptr::addr_of(&data) as *();
let res = rustrt::rust_port_id_send(p, data_ptr);
if res != 0 unsafe {
if res != 0 {
// Data sent successfully
cast::forget(move data);
}
Expand Down
6 changes: 4 additions & 2 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ pub fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
-> Option<~str> {
let buf = vec::to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char));
do vec::as_mut_buf(buf) |b, sz| {
if f(b, sz as size_t) unsafe {
Some(str::raw::from_buf(b as *u8))
if f(b, sz as size_t) {
unsafe {
Some(str::raw::from_buf(b as *u8))
}
} else {
None
}
Expand Down
90 changes: 50 additions & 40 deletions src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ impl PacketHeader {
reinterpret_cast(&self.buffer)
}

fn set_buffer<T: Owned>(b: ~Buffer<T>) unsafe {
self.buffer = reinterpret_cast(&b);
fn set_buffer<T: Owned>(b: ~Buffer<T>) {
unsafe {
self.buffer = reinterpret_cast(&b);
}
}
}

Expand Down Expand Up @@ -353,19 +355,21 @@ pub unsafe fn get_buffer<T: Owned>(p: *PacketHeader) -> ~Buffer<T> {
struct BufferResource<T: Owned> {
buffer: ~Buffer<T>,

drop unsafe {
let b = move_it!(self.buffer);
//let p = ptr::addr_of(*b);
//error!("drop %?", p);
let old_count = atomic_sub_rel(&mut b.header.ref_count, 1);
//let old_count = atomic_xchng_rel(b.header.ref_count, 0);
if old_count == 1 {
// The new count is 0.

// go go gadget drop glue
}
else {
forget(move b)
drop {
unsafe {
let b = move_it!(self.buffer);
//let p = ptr::addr_of(*b);
//error!("drop %?", p);
let old_count = atomic_sub_rel(&mut b.header.ref_count, 1);
//let old_count = atomic_xchng_rel(b.header.ref_count, 0);
if old_count == 1 {
// The new count is 0.

// go go gadget drop glue
}
else {
forget(move b)
}
}
}
}
Expand Down Expand Up @@ -638,18 +642,20 @@ fn wait_many<T: Selectable>(pkts: &[T]) -> uint {

let mut data_avail = false;
let mut ready_packet = pkts.len();
for pkts.eachi |i, p| unsafe {
let p = unsafe { &*p.header() };
let old = p.mark_blocked(this);
match old {
Full | Terminated => {
data_avail = true;
ready_packet = i;
(*p).state = old;
break;
}
Blocked => fail ~"blocking on blocked packet",
Empty => ()
for pkts.eachi |i, p| {
unsafe {
let p = &*p.header();
let old = p.mark_blocked(this);
match old {
Full | Terminated => {
data_avail = true;
ready_packet = i;
(*p).state = old;
break;
}
Blocked => fail ~"blocking on blocked packet",
Empty => ()
}
}
}

Expand Down Expand Up @@ -1069,23 +1075,27 @@ impl<T: Owned> Port<T>: GenericPort<T> {
}

impl<T: Owned> Port<T>: Peekable<T> {
pure fn peek() -> bool unsafe {
let mut endp = None;
endp <-> self.endp;
let peek = match &endp {
&Some(ref endp) => pipes::peek(endp),
&None => fail ~"peeking empty stream"
};
self.endp <-> endp;
peek
pure fn peek() -> bool {
unsafe {
let mut endp = None;
endp <-> self.endp;
let peek = match &endp {
&Some(ref endp) => pipes::peek(endp),
&None => fail ~"peeking empty stream"
};
self.endp <-> endp;
peek
}
}
}

impl<T: Owned> Port<T>: Selectable {
pure fn header() -> *PacketHeader unsafe {
match self.endp {
Some(ref endp) => endp.header(),
None => fail ~"peeking empty stream"
pure fn header() -> *PacketHeader {
unsafe {
match self.endp {
Some(ref endp) => endp.header(),
None => fail ~"peeking empty stream"
}
}
}
}
Expand Down
116 changes: 64 additions & 52 deletions src/libcore/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,26 @@ pub unsafe fn run_in_bare_thread(f: ~fn()) {
let (port, chan) = pipes::stream();
// XXX Unfortunate that this creates an extra scheduler but it's necessary
// since rust_raw_thread_join_delete is blocking
do task::spawn_sched(task::SingleThreaded) unsafe {
let closure: &fn() = || {
f()
};
let thread = rustrt::rust_raw_thread_start(closure);
rustrt::rust_raw_thread_join_delete(thread);
chan.send(());
do task::spawn_sched(task::SingleThreaded) {
unsafe {
let closure: &fn() = || {
f()
};
let thread = rustrt::rust_raw_thread_start(closure);
rustrt::rust_raw_thread_join_delete(thread);
chan.send(());
}
}
port.recv();
}

#[test]
fn test_run_in_bare_thread() unsafe {
let i = 100;
do run_in_bare_thread {
assert i == 100;
fn test_run_in_bare_thread() {
unsafe {
let i = 100;
do run_in_bare_thread {
assert i == 100;
}
}
}

Expand Down Expand Up @@ -273,8 +277,10 @@ pub unsafe fn weaken_task(f: fn(oldcomm::Port<()>)) {

struct Unweaken {
ch: oldcomm::Chan<()>,
drop unsafe {
rustrt::rust_task_unweaken(cast::reinterpret_cast(&self.ch));
drop {
unsafe {
rustrt::rust_task_unweaken(cast::reinterpret_cast(&self.ch));
}
}
}

Expand Down Expand Up @@ -359,37 +365,40 @@ struct ArcData<T> {

struct ArcDestruct<T> {
mut data: *libc::c_void,
drop unsafe {
if self.data.is_null() {
return; // Happens when destructing an unwrapper's handle.
}
do task::unkillable {
let data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
let new_count = rusti::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 unwrapper?
// It's safe to not xchg because the unwrapper will set the
// unwrap lock *before* dropping his/her reference. In effect,
// being here means we're the only *awake* task with the data.
if data.unwrapper != 0 {
let p: UnwrapProto =
cast::reinterpret_cast(&data.unwrapper);
let (message, response) = option::swap_unwrap(p);
// Send 'ready' and wait for a response.
pipes::send_one(move message, ());
// Unkillable wait. Message guaranteed to come.
if pipes::recv_one(move response) {
// Other task got the data.
cast::forget(move data);
drop {
unsafe {
if self.data.is_null() {
return; // Happens when destructing an unwrapper's handle.
}
do task::unkillable {
let data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
let new_count = rusti::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
// unwrapper? It's safe to not xchg because the unwrapper
// will set the unwrap lock *before* dropping his/her
// reference. In effect, being here means we're the only
// *awake* task with the data.
if data.unwrapper != 0 {
let p: UnwrapProto =
cast::reinterpret_cast(&data.unwrapper);
let (message, response) = option::swap_unwrap(p);
// Send 'ready' and wait for a response.
pipes::send_one(move message, ());
// Unkillable wait. Message guaranteed to come.
if pipes::recv_one(move response) {
// Other task got the data.
cast::forget(move data);
} else {
// Other task was killed. drop glue takes over.
}
} else {
// Other task was killed. drop glue takes over.
// drop glue takes over.
}
} else {
// drop glue takes over.
cast::forget(move data);
}
} else {
cast::forget(move data);
}
}
}
Expand All @@ -406,18 +415,21 @@ pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
struct DeathThroes<T> {
mut ptr: Option<~ArcData<T>>,
mut response: Option<pipes::ChanOne<bool>>,
drop unsafe {
let response = option::swap_unwrap(&mut self.response);
// In case we get killed early, we need to tell the person who
// tried to wake us whether they should hand-off the data to us.
if task::failing() {
pipes::send_one(move response, false);
// Either this swap_unwrap or the one below (at "Got here")
// ought to run.
cast::forget(option::swap_unwrap(&mut self.ptr));
} else {
assert self.ptr.is_none();
pipes::send_one(move response, true);
drop {
unsafe {
let response = option::swap_unwrap(&mut self.response);
// In case we get killed early, we need to tell the person who
// tried to wake us whether they should hand-off the data to
// us.
if task::failing() {
pipes::send_one(move response, false);
// Either this swap_unwrap or the one below (at "Got
// here") ought to run.
cast::forget(option::swap_unwrap(&mut self.ptr));
} else {
assert self.ptr.is_none();
pipes::send_one(move response, true);
}
}
}
}
Expand Down
Loading