about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-12-18 10:14:44 -0800
committerAlex Crichton <alex@alexcrichton.com>2013-12-24 19:59:54 -0800
commit1c4af5e3d93fe2953c31f8a76ee2aed15069204a (patch)
tree9c033596228af15427cd7c952c9713599c937ced /src
parent3dc38b0c51f8b98ea550b5a3842c87884f10fa8d (diff)
downloadrust-1c4af5e3d93fe2953c31f8a76ee2aed15069204a.tar.gz
rust-1c4af5e3d93fe2953c31f8a76ee2aed15069204a.zip
rustuv: Remove the id() function from IoFactory
The only user of this was the homing code in librustuv, and it just manually
does the cast from a pointer to a uint now.
Diffstat (limited to 'src')
-rw-r--r--src/libnative/io/mod.rs3
-rw-r--r--src/librustuv/homing.rs38
-rw-r--r--src/librustuv/lib.rs7
-rw-r--r--src/librustuv/uvio.rs7
-rw-r--r--src/librustuv/uvll.rs2
-rw-r--r--src/libstd/rt/rtio.rs2
6 files changed, 27 insertions, 32 deletions
diff --git a/src/libnative/io/mod.rs b/src/libnative/io/mod.rs
index 36e3f8af190..32056215e7c 100644
--- a/src/libnative/io/mod.rs
+++ b/src/libnative/io/mod.rs
@@ -111,9 +111,6 @@ fn mkerr_winbool(ret: libc::c_int) -> IoResult<()> {
 pub struct IoFactory;
 
 impl rtio::IoFactory for IoFactory {
-    // all native io factories are the same
-    fn id(&self) -> uint { 0 }
-
     // networking
     fn tcp_connect(&mut self, _addr: SocketAddr) -> IoResult<~RtioTcpStream> {
         Err(unimpl())
diff --git a/src/librustuv/homing.rs b/src/librustuv/homing.rs
index d7be06724a0..16534b7b38b 100644
--- a/src/librustuv/homing.rs
+++ b/src/librustuv/homing.rs
@@ -33,6 +33,7 @@
 
 #[allow(dead_code)];
 
+use std::cast;
 use std::rt::local::Local;
 use std::rt::rtio::LocalIo;
 use std::rt::task::{Task, BlockedTask};
@@ -70,6 +71,17 @@ impl Clone for HomeHandle {
     }
 }
 
+pub fn local_id() -> uint {
+    let mut io = match LocalIo::borrow() {
+        Some(io) => io, None => return 0,
+    };
+    let io = io.get();
+    unsafe {
+        let (_vtable, ptr): (uint, uint) = cast::transmute(io);
+        return ptr;
+    }
+}
+
 pub trait HomingIO {
     fn home<'r>(&'r mut self) -> &'r mut HomeHandle;
 
@@ -79,35 +91,26 @@ pub trait HomingIO {
     fn go_to_IO_home(&mut self) -> uint {
         let _f = ForbidUnwind::new("going home");
 
-        let mut cur_task: ~Task = Local::take();
-        let cur_loop_id = {
-            let mut io = cur_task.local_io().expect("libuv must have I/O");
-            io.get().id()
-        };
+        let cur_loop_id = local_id();
+        let destination = self.home().id;
 
         // Try at all costs to avoid the homing operation because it is quite
         // expensive. Hence, we only deschedule/send if we're not on the correct
         // event loop. If we're already on the home event loop, then we're good
         // to go (remember we have no preemption, so we're guaranteed to stay on
         // this event loop as long as we avoid the scheduler).
-        if cur_loop_id != self.home().id {
+        if cur_loop_id != destination {
+            let cur_task: ~Task = Local::take();
             cur_task.deschedule(1, |task| {
                 self.home().send(task);
                 Ok(())
             });
 
             // Once we wake up, assert that we're in the right location
-            let cur_loop_id = {
-                let mut io = LocalIo::borrow().expect("libuv must have I/O");
-                io.get().id()
-            };
-            assert_eq!(cur_loop_id, self.home().id);
-
-            cur_loop_id
-        } else {
-            Local::put(cur_task);
-            cur_loop_id
+            assert_eq!(local_id(), destination);
         }
+
+        return destination;
     }
 
     /// Fires a single homing missile, returning another missile targeted back
@@ -130,8 +133,7 @@ impl HomingMissile {
     /// Check at runtime that the task has *not* transplanted itself to a
     /// different I/O loop while executing.
     pub fn check(&self, msg: &'static str) {
-        let mut io = LocalIo::borrow().expect("libuv must have I/O");
-        assert!(io.get().id() == self.io_home, "{}", msg);
+        assert!(local_id() == self.io_home, "{}", msg);
     }
 }
 
diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs
index 49d695ea3fb..2ef10dd33ac 100644
--- a/src/librustuv/lib.rs
+++ b/src/librustuv/lib.rs
@@ -53,7 +53,6 @@ use std::ptr::null;
 use std::ptr;
 use std::rt::local::Local;
 use std::rt::task::{BlockedTask, Task};
-use std::rt::rtio::LocalIo;
 use std::str::raw::from_c_str;
 use std::str;
 use std::task;
@@ -161,18 +160,16 @@ pub struct ForbidSwitch {
 
 impl ForbidSwitch {
     fn new(s: &'static str) -> ForbidSwitch {
-        let mut io = LocalIo::borrow().expect("libuv must have local I/O");
         ForbidSwitch {
             msg: s,
-            io: io.get().id(),
+            io: homing::local_id(),
         }
     }
 }
 
 impl Drop for ForbidSwitch {
     fn drop(&mut self) {
-        let mut io = LocalIo::borrow().expect("libuv must have local I/O");
-        assert!(self.io == io.get().id(),
+        assert!(self.io == homing::local_id(),
                 "didnt want a scheduler switch: {}",
                 self.msg);
     }
diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs
index 322bead8be4..9e7343aa2da 100644
--- a/src/librustuv/uvio.rs
+++ b/src/librustuv/uvio.rs
@@ -132,13 +132,14 @@ impl UvIoFactory {
     pub fn uv_loop<'a>(&mut self) -> *uvll::uv_loop_t { self.loop_.handle }
 
     pub fn make_handle(&mut self) -> HomeHandle {
-        HomeHandle::new(self.id(), &mut **self.handle_pool.get_mut_ref())
+        // It's understood by the homing code that the "local id" is just the
+        // pointer of the local I/O factory cast to a uint.
+        let id: uint = unsafe { cast::transmute_copy(&self) };
+        HomeHandle::new(id, &mut **self.handle_pool.get_mut_ref())
     }
 }
 
 impl IoFactory for UvIoFactory {
-    fn id(&self) -> uint { unsafe { cast::transmute(self) } }
-
     // Connect to an address and return a new stream
     // NB: This blocks the task waiting on the connection.
     // It would probably be better to return a future
diff --git a/src/librustuv/uvll.rs b/src/librustuv/uvll.rs
index fa0bb85faed..ad5fad99f20 100644
--- a/src/librustuv/uvll.rs
+++ b/src/librustuv/uvll.rs
@@ -38,7 +38,7 @@ use std::libc;
 use std::libc::uintptr_t;
 
 pub use self::errors::{EACCES, ECONNREFUSED, ECONNRESET, EPIPE, ECONNABORTED,
-                       ECANCELED, EBADF, ENOTCONN};
+                       ECANCELED, EBADF, ENOTCONN, ENOENT};
 
 pub static OK: c_int = 0;
 pub static EOF: c_int = -4095;
diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs
index c1c40cc6dff..97b08cc18ca 100644
--- a/src/libstd/rt/rtio.rs
+++ b/src/libstd/rt/rtio.rs
@@ -150,8 +150,6 @@ impl<'a> LocalIo<'a> {
 }
 
 pub trait IoFactory {
-    fn id(&self) -> uint;
-
     // networking
     fn tcp_connect(&mut self, addr: SocketAddr) -> Result<~RtioTcpStream, IoError>;
     fn tcp_bind(&mut self, addr: SocketAddr) -> Result<~RtioTcpListener, IoError>;