From b3a392c38a0368eca7860ffcbbbe562d242da911 Mon Sep 17 00:00:00 2001 From: Ted Horst Date: Tue, 17 Jul 2012 23:13:11 -0500 Subject: [PATCH 1/2] call task::yield in comm::peek --- src/libcore/comm.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 7c85e5c5d5a78..07c95ca34f576 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -211,7 +211,18 @@ fn recv_(p: *rust_port) -> T { } fn peek_(p: *rust_port) -> bool { - rustrt::rust_port_size(p) != 0u as libc::size_t + let res = rustrt::rust_port_size(p) != 0u as libc::size_t; + if !res { + // Don't have to yield here, but task is involved in comms, + // so it might be a good idea + task::yield(); + } + else { + // As in recv, this is a good place to yield anyway until + // the compiler generates yield calls + task::yield(); + } + ret res; } /// Receive on one of two ports From c5115c217c9926156fd9ab5cbe7c5a765a11f91b Mon Sep 17 00:00:00 2001 From: Ted Horst Date: Wed, 18 Jul 2012 19:35:32 -0500 Subject: [PATCH 2/2] unconditionally yield before comm::peek and add a FIXME --- src/libcore/comm.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 07c95ca34f576..8455e5ec82e26 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -211,18 +211,10 @@ fn recv_(p: *rust_port) -> T { } fn peek_(p: *rust_port) -> bool { - let res = rustrt::rust_port_size(p) != 0u as libc::size_t; - if !res { - // Don't have to yield here, but task is involved in comms, - // so it might be a good idea - task::yield(); - } - else { - // As in recv, this is a good place to yield anyway until - // the compiler generates yield calls - task::yield(); - } - ret res; + // Yield here before we check to see if someone sent us a message + // FIXME #524, if the compilergenerates yields, we don't need this + task::yield(); + rustrt::rust_port_size(p) != 0u as libc::size_t } /// Receive on one of two ports