Skip to content

Commit 35e844f

Browse files
committed
Make IO thread-safe.
Each IO handle has a home event loop, which created it. When a task wants to use an IO handle, it must first make sure it is on that home event loop. It uses the scheduler handle in the IO handle to send itself there before starting the IO action. Once the IO action completes, the task restores its previous home state. If it is an AnySched task, then it will be executed on the new scheduler. If it has a normal home, then it will return there before executing any more code after the IO action.
1 parent d09412a commit 35e844f

File tree

4 files changed

+653
-660
lines changed

4 files changed

+653
-660
lines changed

src/libstd/rt/io/timer.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Timer {
4141
}
4242

4343
impl RtioTimer for Timer {
44-
fn sleep(&self, msecs: u64) {
44+
fn sleep(&mut self, msecs: u64) {
4545
(**self).sleep(msecs);
4646
}
4747
}
@@ -50,15 +50,11 @@ impl RtioTimer for Timer {
5050
mod test {
5151
use super::*;
5252
use rt::test::*;
53-
use option::{Some, None};
5453
#[test]
5554
fn test_io_timer_sleep_simple() {
5655
do run_in_newsched_task {
5756
let timer = Timer::new();
58-
match timer {
59-
Some(t) => t.sleep(1),
60-
None => assert!(false)
61-
}
57+
do timer.map_move |mut t| { t.sleep(1) };
6258
}
6359
}
64-
}
60+
}

src/libstd/rt/rtio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub type RemoteCallbackObject = uvio::UvRemoteCallback;
2222
pub type IoFactoryObject = uvio::UvIoFactory;
2323
pub type RtioTcpStreamObject = uvio::UvTcpStream;
2424
pub type RtioTcpListenerObject = uvio::UvTcpListener;
25-
pub type RtioUdpSocketObject = uvio::HomedUvUdpSocket; //uvio::UvUdpSocket;
25+
pub type RtioUdpSocketObject = uvio::UvUdpSocket;
2626
pub type RtioTimerObject = uvio::UvTimer;
2727

2828
pub trait EventLoop {
@@ -88,5 +88,5 @@ pub trait RtioUdpSocket : RtioSocket {
8888
}
8989

9090
pub trait RtioTimer {
91-
fn sleep(&self, msecs: u64);
91+
fn sleep(&mut self, msecs: u64);
9292
}

0 commit comments

Comments
 (0)