diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-11-04 12:45:05 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-11-10 01:37:10 -0800 |
| commit | 28219fc679e6c2f747ad3e49eb746a383797ef9b (patch) | |
| tree | 264c95902202c54f0978a483b6b932cd13462d6a /src/libstd/rt | |
| parent | 9286d5113d843e65fb13ff0cf142c1bfb10124f7 (diff) | |
| download | rust-28219fc679e6c2f747ad3e49eb746a383797ef9b.tar.gz rust-28219fc679e6c2f747ad3e49eb746a383797ef9b.zip | |
Remove usage of ~fn() from uv async/idle
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/basic.rs | 25 | ||||
| -rw-r--r-- | src/libstd/rt/rtio.rs | 10 | ||||
| -rw-r--r-- | src/libstd/rt/sched.rs | 14 |
3 files changed, 31 insertions, 18 deletions
diff --git a/src/libstd/rt/basic.rs b/src/libstd/rt/basic.rs index 86d3f8a52ba..0c8d192d89a 100644 --- a/src/libstd/rt/basic.rs +++ b/src/libstd/rt/basic.rs @@ -15,7 +15,8 @@ use prelude::*; use cast; -use rt::rtio::{EventLoop, IoFactory, RemoteCallback, PausibleIdleCallback}; +use rt::rtio::{EventLoop, IoFactory, RemoteCallback, PausibleIdleCallback, + Callback}; use unstable::sync::Exclusive; use util; @@ -25,9 +26,9 @@ pub fn event_loop() -> ~EventLoop { } struct BasicLoop { - work: ~[~fn()], // pending work - idle: Option<*BasicPausible>, // only one is allowed - remotes: ~[(uint, ~fn())], + work: ~[proc()], // pending work + idle: Option<*mut BasicPausible>, // only one is allowed + remotes: ~[(uint, ~Callback)], next_remote: uint, messages: Exclusive<~[Message]> } @@ -86,8 +87,8 @@ impl BasicLoop { fn message(&mut self, message: Message) { match message { RunRemote(i) => { - match self.remotes.iter().find(|& &(id, _)| id == i) { - Some(&(_, ref f)) => (*f)(), + match self.remotes.mut_iter().find(|& &(id, _)| id == i) { + Some(&(_, ref mut f)) => f.call(), None => unreachable!() } } @@ -106,7 +107,7 @@ impl BasicLoop { match self.idle { Some(idle) => { if (*idle).active { - (*(*idle).work.get_ref())(); + (*idle).work.get_mut_ref().call(); } } None => {} @@ -144,7 +145,7 @@ impl EventLoop for BasicLoop { } } - fn callback(&mut self, f: ~fn()) { + fn callback(&mut self, f: proc()) { self.work.push(f); } @@ -153,13 +154,13 @@ impl EventLoop for BasicLoop { let callback = ~BasicPausible::new(self); rtassert!(self.idle.is_none()); unsafe { - let cb_ptr: &*BasicPausible = cast::transmute(&callback); + let cb_ptr: &*mut BasicPausible = cast::transmute(&callback); self.idle = Some(*cb_ptr); } return callback as ~PausibleIdleCallback; } - fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback { + fn remote_callback(&mut self, f: ~Callback) -> ~RemoteCallback { let id = self.next_remote; self.next_remote += 1; self.remotes.push((id, f)); @@ -203,7 +204,7 @@ impl Drop for BasicRemote { struct BasicPausible { eloop: *mut BasicLoop, - work: Option<~fn()>, + work: Option<~Callback>, active: bool, } @@ -218,7 +219,7 @@ impl BasicPausible { } impl PausibleIdleCallback for BasicPausible { - fn start(&mut self, f: ~fn()) { + fn start(&mut self, f: ~Callback) { rtassert!(!self.active && self.work.is_none()); self.active = true; self.work = Some(f); diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index d24de7cbfee..8684537f4e4 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -24,11 +24,15 @@ use path::Path; use super::io::{SeekStyle}; use super::io::{FileMode, FileAccess, FileStat, FilePermission}; +pub trait Callback { + fn call(&mut self); +} + pub trait EventLoop { fn run(&mut self); - fn callback(&mut self, ~fn()); + fn callback(&mut self, proc()); fn pausible_idle_callback(&mut self) -> ~PausibleIdleCallback; - fn remote_callback(&mut self, ~fn()) -> ~RemoteCallback; + fn remote_callback(&mut self, ~Callback) -> ~RemoteCallback; /// The asynchronous I/O services. Not all event loops may provide one // FIXME(#9382) this is an awful interface @@ -222,7 +226,7 @@ pub trait RtioTTY { } pub trait PausibleIdleCallback { - fn start(&mut self, f: ~fn()); + fn start(&mut self, f: ~Callback); fn pause(&mut self); fn resume(&mut self); fn close(&mut self); diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index e71cd92589c..fb4bd573a73 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -23,7 +23,7 @@ use super::message_queue::MessageQueue; use rt::kill::BlockedTask; use rt::local_ptr; use rt::local::Local; -use rt::rtio::{RemoteCallback, PausibleIdleCallback}; +use rt::rtio::{RemoteCallback, PausibleIdleCallback, Callback}; use borrow::{to_uint}; use cell::Cell; use rand::{XorShiftRng, Rng, Rand}; @@ -184,7 +184,7 @@ impl Scheduler { // Before starting our first task, make sure the idle callback // is active. As we do not start in the sleep state this is // important. - self.idle_callback.get_mut_ref().start(Scheduler::run_sched_once); + self.idle_callback.get_mut_ref().start(~SchedRunner as ~Callback); // Now, as far as all the scheduler state is concerned, we are // inside the "scheduler" context. So we can act like the @@ -767,7 +767,7 @@ impl Scheduler { } pub fn make_handle(&mut self) -> SchedHandle { - let remote = self.event_loop.remote_callback(Scheduler::run_sched_once); + let remote = self.event_loop.remote_callback(~SchedRunner as ~Callback); return SchedHandle { remote: remote, @@ -802,6 +802,14 @@ impl SchedHandle { } } +struct SchedRunner; + +impl Callback for SchedRunner { + fn call(&mut self) { + Scheduler::run_sched_once(); + } +} + struct CleanupJob { task: ~Task, f: UnsafeTaskReceiver |
