Skip to content

Commit 7f48345

Browse files
committed
std: Remove must deferred sending functions
These functions are all unnecessary now, and they only have meaning in the M:N context. Removing these functions uncovered a bug in the librustuv timer bindings, but it was fairly easy to cover (and the test is already committed). These cannot be completely removed just yet due to their usage in the WaitQueue of extra::sync, and until the mutex in libextra is rewritten it will not be possible to remove the deferred sends for channels.
1 parent 1c4af5e commit 7f48345

File tree

7 files changed

+19
-43
lines changed

7 files changed

+19
-43
lines changed

src/libextra/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl WaitQueue {
7979

8080
fn wait_end(&self) -> WaitEnd {
8181
let (wait_end, signal_end) = Chan::new();
82-
self.tail.send_deferred(signal_end);
82+
assert!(self.tail.try_send_deferred(signal_end));
8383
wait_end
8484
}
8585
}

src/libgreen/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Runtime for SimpleTask {
5454
}
5555
Local::put(cur_task);
5656
}
57-
fn reawaken(mut ~self, mut to_wake: ~Task) {
57+
fn reawaken(mut ~self, mut to_wake: ~Task, _can_resched: bool) {
5858
let me = &mut *self as *mut SimpleTask;
5959
to_wake.put_runtime(self as ~Runtime);
6060
unsafe {

src/libgreen/task.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl Runtime for GreenTask {
346346
}
347347
}
348348

349-
fn reawaken(mut ~self, to_wake: ~Task) {
349+
fn reawaken(mut ~self, to_wake: ~Task, can_resched: bool) {
350350
self.put_task(to_wake);
351351
assert!(self.sched.is_none());
352352

@@ -372,10 +372,15 @@ impl Runtime for GreenTask {
372372
match running_task.maybe_take_runtime::<GreenTask>() {
373373
Some(mut running_green_task) => {
374374
running_green_task.put_task(running_task);
375-
let sched = running_green_task.sched.take_unwrap();
375+
let mut sched = running_green_task.sched.take_unwrap();
376376

377377
if sched.pool_id == self.pool_id {
378-
sched.run_task(running_green_task, self);
378+
if can_resched {
379+
sched.run_task(running_green_task, self);
380+
} else {
381+
sched.enqueue_task(self);
382+
running_green_task.put_with_sched(sched);
383+
}
379384
} else {
380385
self.reawaken_remotely();
381386

src/librustuv/pipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ extern fn listen_cb(server: *uvll::uv_stream_t, status: libc::c_int) {
210210
}
211211
n => Err(uv_error_to_io_error(UvError(n)))
212212
};
213-
pipe.outgoing.send_deferred(msg);
213+
pipe.outgoing.send(msg);
214214
}
215215

216216
impl Drop for PipeListener {

src/librustuv/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl SignalWatcher {
5252
extern fn signal_cb(handle: *uvll::uv_signal_t, signum: c_int) {
5353
let s: &mut SignalWatcher = unsafe { UvHandle::from_uv_handle(&handle) };
5454
assert_eq!(signum as int, s.signal as int);
55-
s.channel.try_send_deferred(s.signal);
55+
s.channel.try_send(s.signal);
5656
}
5757

5858
impl HomingIO for SignalWatcher {

src/librustuv/timer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ extern fn timer_cb(handle: *uvll::uv_timer_t, status: c_int) {
140140
WakeTask(task) => {
141141
task.wake().map(|t| t.reawaken(true));
142142
}
143-
SendOnce(chan) => { chan.try_send_deferred(()); }
143+
SendOnce(chan) => { chan.try_send(()); }
144144
SendMany(chan, id) => {
145-
chan.try_send_deferred(());
145+
chan.try_send(());
146146

147147
// Note that the above operation could have performed some form of
148148
// scheduling. This means that the timer may have decided to insert

src/libstd/comm/mod.rs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ impl Packet {
496496
match self.channels.fetch_sub(1, SeqCst) {
497497
1 => {
498498
match self.cnt.swap(DISCONNECTED, SeqCst) {
499-
-1 => { self.wakeup(false); }
499+
-1 => { self.wakeup(true); }
500500
DISCONNECTED => {}
501501
n => { assert!(n >= 0); }
502502
}
@@ -537,9 +537,6 @@ impl<T: Send> Chan<T> {
537537
/// port.
538538
///
539539
/// Rust channels are infinitely buffered so this method will never block.
540-
/// This method may trigger a rescheduling, however, in order to wake up a
541-
/// blocked receiver (if one is present). If no scheduling is desired, then
542-
/// the `send_deferred` guarantees that there will be no reschedulings.
543540
///
544541
/// # Failure
545542
///
@@ -561,15 +558,6 @@ impl<T: Send> Chan<T> {
561558
}
562559
}
563560

564-
/// This function is equivalent in the semantics of `send`, but it
565-
/// guarantees that a rescheduling will never occur when this method is
566-
/// called.
567-
pub fn send_deferred(&self, t: T) {
568-
if !self.try_send_deferred(t) {
569-
fail!("sending on a closed channel");
570-
}
571-
}
572-
573561
/// Attempts to send a value on this channel, returning whether it was
574562
/// successfully sent.
575563
///
@@ -585,9 +573,8 @@ impl<T: Send> Chan<T> {
585573
/// be tolerated, then this method should be used instead.
586574
pub fn try_send(&self, t: T) -> bool { self.try(t, true) }
587575

588-
/// This function is equivalent in the semantics of `try_send`, but it
589-
/// guarantees that a rescheduling will never occur when this method is
590-
/// called.
576+
/// This function will not stick around for very long. The purpose of this
577+
/// function is to guarantee that no rescheduling is performed.
591578
pub fn try_send_deferred(&self, t: T) -> bool { self.try(t, false) }
592579

593580
fn try(&self, t: T, can_resched: bool) -> bool {
@@ -649,25 +636,9 @@ impl<T: Send> SharedChan<T> {
649636
}
650637
}
651638

652-
/// This function is equivalent in the semantics of `send`, but it
653-
/// guarantees that a rescheduling will never occur when this method is
654-
/// called.
655-
pub fn send_deferred(&self, t: T) {
656-
if !self.try_send_deferred(t) {
657-
fail!("sending on a closed channel");
658-
}
659-
}
660-
661639
/// Equivalent method to `try_send` on the `Chan` type (using the same
662640
/// semantics)
663-
pub fn try_send(&self, t: T) -> bool { self.try(t, true) }
664-
665-
/// This function is equivalent in the semantics of `try_send`, but it
666-
/// guarantees that a rescheduling will never occur when this method is
667-
/// called.
668-
pub fn try_send_deferred(&self, t: T) -> bool { self.try(t, false) }
669-
670-
fn try(&self, t: T, can_resched: bool) -> bool {
641+
pub fn try_send(&self, t: T) -> bool {
671642
unsafe {
672643
// Note that the multiple sender case is a little tricker
673644
// semantically than the single sender case. The logic for
@@ -704,7 +675,7 @@ impl<T: Send> SharedChan<T> {
704675

705676
match (*packet).increment() {
706677
DISCONNECTED => {} // oh well, we tried
707-
-1 => { (*packet).wakeup(can_resched); }
678+
-1 => { (*packet).wakeup(true); }
708679
n => {
709680
if n > 0 && n % RESCHED_FREQ == 0 {
710681
let task: ~Task = Local::take();

0 commit comments

Comments
 (0)