Skip to content

Commit 6a3a516

Browse files
committed
---
yaml --- r: 6268 b: refs/heads/master c: 5b9f76e h: refs/heads/master v: v3
1 parent 1ec0d05 commit 6a3a516

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c74fd1dc772ca67ec4d885152f01e33acad9213c
2+
refs/heads/master: 5b9f76eb7c53a28ed99d4005645485e24568ce22

trunk/src/lib/comm.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ native "cdecl" mod rustrt {
4040

4141
fn chan_id_send<uniq T>(t: *sys::type_desc,
4242
target_task: task::task, target_port: port_id,
43-
-data: T);
43+
data: T) -> ctypes::uintptr_t;
4444

4545
fn new_port(unit_sz: uint) -> *rust_port;
4646
fn del_port(po: *rust_port);
@@ -109,7 +109,11 @@ to it.
109109
*/
110110
fn send<uniq T>(ch: chan<T>, -data: T) {
111111
let chan_t(t, p) = ch;
112-
rustrt::chan_id_send(sys::get_type_desc::<T>(), t, p, data);
112+
let res = rustrt::chan_id_send(sys::get_type_desc::<T>(), t, p, data);
113+
if res != 0u unsafe {
114+
// Data sent successfully
115+
unsafe::leak(data);
116+
}
113117
task::yield();
114118
}
115119

trunk/src/lib/ctypes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ type size_t = uint;
1010
type ssize_t = int;
1111
/* Type: uint32_t */
1212
type uint32_t = u32;
13+
/* Type: uintptr_t */
14+
type uintptr_t = uint;

trunk/src/rt/rust_builtin.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,11 @@ get_port_id(rust_port *port) {
485485
return port->id;
486486
}
487487

488-
extern "C" CDECL void
488+
extern "C" CDECL uintptr_t
489489
chan_id_send(type_desc *t, rust_task_id target_task_id,
490490
rust_port_id target_port_id, void *sptr) {
491491
// FIXME: make sure this is thread-safe
492+
bool sent = false;
492493
rust_task *task = rust_scheduler::get_task();
493494
rust_task *target_task = task->kernel->get_task_by_id(target_task_id);
494495
if(target_task) {
@@ -497,9 +498,11 @@ chan_id_send(type_desc *t, rust_task_id target_task_id,
497498
port->send(sptr);
498499
scoped_lock with(target_task->lock);
499500
port->deref();
501+
sent = true;
500502
}
501503
target_task->deref();
502504
}
505+
return (uintptr_t)sent;
503506
}
504507

505508
// This is called by an intrinsic on the Rust stack.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std;
2+
import std::comm;
3+
4+
fn main() {
5+
let c = {
6+
let p = comm::port();
7+
comm::chan(p)
8+
};
9+
comm::send(c, "coffee");
10+
}

0 commit comments

Comments
 (0)