Skip to content

Commit

Permalink
Make IO thread-safe.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anasazi committed Aug 19, 2013
1 parent d09412a commit 35e844f
Show file tree
Hide file tree
Showing 4 changed files with 653 additions and 660 deletions.
10 changes: 3 additions & 7 deletions src/libstd/rt/io/timer.rs
Expand Up @@ -41,7 +41,7 @@ impl Timer {
}

impl RtioTimer for Timer {
fn sleep(&self, msecs: u64) {
fn sleep(&mut self, msecs: u64) {
(**self).sleep(msecs);
}
}
Expand All @@ -50,15 +50,11 @@ impl RtioTimer for Timer {
mod test {
use super::*;
use rt::test::*;
use option::{Some, None};
#[test]
fn test_io_timer_sleep_simple() {
do run_in_newsched_task {
let timer = Timer::new();
match timer {
Some(t) => t.sleep(1),
None => assert!(false)
}
do timer.map_move |mut t| { t.sleep(1) };
}
}
}
}
4 changes: 2 additions & 2 deletions src/libstd/rt/rtio.rs
Expand Up @@ -22,7 +22,7 @@ pub type RemoteCallbackObject = uvio::UvRemoteCallback;
pub type IoFactoryObject = uvio::UvIoFactory;
pub type RtioTcpStreamObject = uvio::UvTcpStream;
pub type RtioTcpListenerObject = uvio::UvTcpListener;
pub type RtioUdpSocketObject = uvio::HomedUvUdpSocket; //uvio::UvUdpSocket;
pub type RtioUdpSocketObject = uvio::UvUdpSocket;
pub type RtioTimerObject = uvio::UvTimer;

pub trait EventLoop {
Expand Down Expand Up @@ -88,5 +88,5 @@ pub trait RtioUdpSocket : RtioSocket {
}

pub trait RtioTimer {
fn sleep(&self, msecs: u64);
fn sleep(&mut self, msecs: u64);
}

5 comments on commit 35e844f

@bors
Copy link
Contributor

@bors bors commented on 35e844f Aug 21, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at anasazi@35e844f

@bors
Copy link
Contributor

@bors bors commented on 35e844f Aug 21, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging anasazi/rust/homing-io = 35e844f into auto

@bors
Copy link
Contributor

@bors bors commented on 35e844f Aug 21, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anasazi/rust/homing-io = 35e844f merged ok, testing candidate = 0bc1ca4

@bors
Copy link
Contributor

@bors bors commented on 35e844f Aug 21, 2013

@bors
Copy link
Contributor

@bors bors commented on 35e844f Aug 21, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 0bc1ca4

Please sign in to comment.