diff options
| author | Eric Reed <ecreed@cs.washington.edu> | 2013-08-08 18:58:18 -0700 |
|---|---|---|
| committer | Eric Reed <ecreed@cs.washington.edu> | 2013-08-19 16:31:21 -0700 |
| commit | 35e844ffc1e3c022e868817ad1c548b900db800a (patch) | |
| tree | 876d39c320381af77708ceace32f55094b27384d /src/libstd/rt/io | |
| parent | d09412ab893f54ef5309cf63d17bcb6110d582b9 (diff) | |
| download | rust-35e844ffc1e3c022e868817ad1c548b900db800a.tar.gz rust-35e844ffc1e3c022e868817ad1c548b900db800a.zip | |
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.
Diffstat (limited to 'src/libstd/rt/io')
| -rw-r--r-- | src/libstd/rt/io/timer.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/libstd/rt/io/timer.rs b/src/libstd/rt/io/timer.rs index c7820ebf623..bfd1ed48ac1 100644 --- a/src/libstd/rt/io/timer.rs +++ b/src/libstd/rt/io/timer.rs @@ -41,7 +41,7 @@ impl Timer { } impl RtioTimer for Timer { - fn sleep(&self, msecs: u64) { + fn sleep(&mut self, msecs: u64) { (**self).sleep(msecs); } } @@ -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) }; } } -} \ No newline at end of file +} |
