Skip to content

Commit b49771e

Browse files
committed
std: Remove try_send_deferred plus all fallout
Now that extra::sync primitives are built on a proper mutex instead of a pthreads one, there's no longer any use for this function.
1 parent 21e8466 commit b49771e

File tree

10 files changed

+31
-30
lines changed

10 files changed

+31
-30
lines changed

src/libgreen/simple.rs

Lines changed: 2 additions & 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, _can_resched: bool) {
57+
fn reawaken(mut ~self, mut to_wake: ~Task) {
5858
let me = &mut *self as *mut SimpleTask;
5959
to_wake.put_runtime(self as ~Runtime);
6060
unsafe {
@@ -76,6 +76,7 @@ impl Runtime for SimpleTask {
7676
}
7777
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> { None }
7878
fn stack_bounds(&self) -> (uint, uint) { fail!() }
79+
fn can_block(&self) -> bool { true }
7980
fn wrap(~self) -> ~Any { fail!() }
8081
}
8182

src/libgreen/task.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl Runtime for GreenTask {
376376
}
377377
}
378378

379-
fn reawaken(mut ~self, to_wake: ~Task, can_resched: bool) {
379+
fn reawaken(mut ~self, to_wake: ~Task) {
380380
self.put_task(to_wake);
381381
assert!(self.sched.is_none());
382382

@@ -409,15 +409,10 @@ impl Runtime for GreenTask {
409409
match running_task.maybe_take_runtime::<GreenTask>() {
410410
Some(mut running_green_task) => {
411411
running_green_task.put_task(running_task);
412-
let mut sched = running_green_task.sched.take_unwrap();
412+
let sched = running_green_task.sched.take_unwrap();
413413

414414
if sched.pool_id == self.pool_id {
415-
if can_resched {
416-
sched.run_task(running_green_task, self);
417-
} else {
418-
sched.enqueue_task(self);
419-
running_green_task.put_with_sched(sched);
420-
}
415+
sched.run_task(running_green_task, self);
421416
} else {
422417
self.reawaken_remotely();
423418

@@ -462,6 +457,8 @@ impl Runtime for GreenTask {
462457
c.current_stack_segment.end() as uint)
463458
}
464459

460+
fn can_block(&self) -> bool { false }
461+
465462
fn wrap(~self) -> ~Any { self as ~Any }
466463
}
467464

src/libnative/task.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ impl rt::Runtime for Ops {
143143

144144
fn stack_bounds(&self) -> (uint, uint) { self.stack_bounds }
145145

146+
fn can_block(&self) -> bool { true }
147+
146148
// This function gets a little interesting. There are a few safety and
147149
// ownership violations going on here, but this is all done in the name of
148150
// shared state. Additionally, all of the violations are protected with a
@@ -231,7 +233,7 @@ impl rt::Runtime for Ops {
231233

232234
// See the comments on `deschedule` for why the task is forgotten here, and
233235
// why it's valid to do so.
234-
fn reawaken(mut ~self, mut to_wake: ~Task, _can_resched: bool) {
236+
fn reawaken(mut ~self, mut to_wake: ~Task) {
235237
unsafe {
236238
let me = &mut *self as *mut Ops;
237239
to_wake.put_runtime(self as ~rt::Runtime);

src/librustuv/idle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mod test {
122122
}
123123
}
124124
};
125-
let _ = task.wake().map(|t| t.reawaken(true));
125+
let _ = task.wake().map(|t| t.reawaken());
126126
}
127127
}
128128

src/librustuv/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn wait_until_woken_after(slot: *mut Option<BlockedTask>, f: ||) {
208208

209209
fn wakeup(slot: &mut Option<BlockedTask>) {
210210
assert!(slot.is_some());
211-
let _ = slot.take_unwrap().wake().map(|t| t.reawaken(true));
211+
let _ = slot.take_unwrap().wake().map(|t| t.reawaken());
212212
}
213213

214214
pub struct Request {

src/librustuv/queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
6767
loop {
6868
match state.consumer.pop() {
6969
mpsc::Data(Task(task)) => {
70-
let _ = task.wake().map(|t| t.reawaken(true));
70+
let _ = task.wake().map(|t| t.reawaken());
7171
}
7272
mpsc::Data(Increment) => unsafe {
7373
if state.refcnt == 0 {

src/librustuv/timer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extern fn timer_cb(handle: *uvll::uv_timer_t, status: c_int) {
138138

139139
match timer.action.take_unwrap() {
140140
WakeTask(task) => {
141-
let _ = task.wake().map(|t| t.reawaken(true));
141+
let _ = task.wake().map(|t| t.reawaken());
142142
}
143143
SendOnce(chan) => { let _ = chan.try_send(()); }
144144
SendMany(chan, id) => {

src/libstd/comm/mod.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,9 @@ impl Packet {
443443

444444
// This function must have had at least an acquire fence before it to be
445445
// properly called.
446-
fn wakeup(&mut self, can_resched: bool) {
446+
fn wakeup(&mut self) {
447447
match self.to_wake.take_unwrap().wake() {
448-
Some(task) => task.reawaken(can_resched),
448+
Some(task) => task.reawaken(),
449449
None => {}
450450
}
451451
self.selecting.store(false, Relaxed);
@@ -519,7 +519,7 @@ impl Packet {
519519
match self.channels.fetch_sub(1, SeqCst) {
520520
1 => {
521521
match self.cnt.swap(DISCONNECTED, SeqCst) {
522-
-1 => { self.wakeup(true); }
522+
-1 => { self.wakeup(); }
523523
DISCONNECTED => {}
524524
n => { assert!(n >= 0); }
525525
}
@@ -595,20 +595,14 @@ impl<T: Send> Chan<T> {
595595
///
596596
/// Like `send`, this method will never block. If the failure of send cannot
597597
/// be tolerated, then this method should be used instead.
598-
pub fn try_send(&self, t: T) -> bool { self.try(t, true) }
599-
600-
/// This function will not stick around for very long. The purpose of this
601-
/// function is to guarantee that no rescheduling is performed.
602-
pub fn try_send_deferred(&self, t: T) -> bool { self.try(t, false) }
603-
604-
fn try(&self, t: T, can_resched: bool) -> bool {
598+
pub fn try_send(&self, t: T) -> bool {
605599
unsafe {
606600
let this = cast::transmute_mut(self);
607601
this.queue.push(t);
608602
let packet = this.queue.packet();
609603
match (*packet).increment() {
610604
// As described above, -1 == wakeup
611-
-1 => { (*packet).wakeup(can_resched); true }
605+
-1 => { (*packet).wakeup(); true }
612606
// Also as above, SPSC queues must be >= -2
613607
-2 => true,
614608
// We succeeded if we sent data
@@ -623,7 +617,7 @@ impl<T: Send> Chan<T> {
623617
// the TLS overhead can be a bit much.
624618
n => {
625619
assert!(n >= 0);
626-
if can_resched && n > 0 && n % RESCHED_FREQ == 0 {
620+
if n > 0 && n % RESCHED_FREQ == 0 {
627621
let task: ~Task = Local::take();
628622
task.maybe_yield();
629623
}
@@ -700,7 +694,7 @@ impl<T: Send> SharedChan<T> {
700694

701695
match (*packet).increment() {
702696
DISCONNECTED => {} // oh well, we tried
703-
-1 => { (*packet).wakeup(true); }
697+
-1 => { (*packet).wakeup(); }
704698
n => {
705699
if n > 0 && n % RESCHED_FREQ == 0 {
706700
let task: ~Task = Local::take();

src/libstd/rt/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ pub trait Runtime {
146146
fn maybe_yield(~self, cur_task: ~Task);
147147
fn deschedule(~self, times: uint, cur_task: ~Task,
148148
f: |BlockedTask| -> Result<(), BlockedTask>);
149-
fn reawaken(~self, to_wake: ~Task, can_resched: bool);
149+
fn reawaken(~self, to_wake: ~Task);
150150

151151
// Miscellaneous calls which are very different depending on what context
152152
// you're in.
153153
fn spawn_sibling(~self, cur_task: ~Task, opts: TaskOpts, f: proc());
154154
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>>;
155155
/// The (low, high) edges of the current stack.
156156
fn stack_bounds(&self) -> (uint, uint); // (lo, hi)
157+
fn can_block(&self) -> bool;
157158

158159
// FIXME: This is a serious code smell and this should not exist at all.
159160
fn wrap(~self) -> ~Any;

src/libstd/rt/task.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ impl Task {
250250
/// Wakes up a previously blocked task, optionally specifiying whether the
251251
/// current task can accept a change in scheduling. This function can only
252252
/// be called on tasks that were previously blocked in `deschedule`.
253-
pub fn reawaken(mut ~self, can_resched: bool) {
253+
pub fn reawaken(mut ~self) {
254254
let ops = self.imp.take_unwrap();
255-
ops.reawaken(self, can_resched);
255+
ops.reawaken(self);
256256
}
257257

258258
/// Yields control of this task to another task. This function will
@@ -283,6 +283,12 @@ impl Task {
283283
pub fn stack_bounds(&self) -> (uint, uint) {
284284
self.imp.get_ref().stack_bounds()
285285
}
286+
287+
/// Returns whether it is legal for this task to block the OS thread that it
288+
/// is running on.
289+
pub fn can_block(&self) -> bool {
290+
self.imp.get_ref().can_block()
291+
}
286292
}
287293

288294
impl Drop for Task {

0 commit comments

Comments
 (0)