Skip to content

Commit 52f378c

Browse files
committed
---
yaml --- r: 64594 b: refs/heads/snap-stage3 c: 5da29e3 h: refs/heads/master v: v3
1 parent c17a240 commit 52f378c

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 921d99108cd452f92569a0cafc8d11b36b38dfc0
4+
refs/heads/snap-stage3: 5da29e3278b639540679e88fc7dd008435066e9a
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/rt/io/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pub use self::stdio::print;
252252
pub use self::stdio::println;
253253

254254
pub use self::file::FileStream;
255+
pub use self::timer::Timer;
255256
pub use self::net::ip::IpAddr;
256257
pub use self::net::tcp::TcpListener;
257258
pub use self::net::tcp::TcpStream;
@@ -296,6 +297,9 @@ mod extensions;
296297
/// Non-I/O things needed by the I/O module
297298
mod support;
298299

300+
/// Basic Timer
301+
mod timer;
302+
299303
/// Thread-blocking implementations
300304
pub mod native {
301305
/// Posix file I/O
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// copyright 2013 the rust project developers. see the copyright
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/copyright.
4+
//
5+
// licensed under the apache license, version 2.0 <license-apache or
6+
// http://www.apache.org/licenses/license-2.0> or the mit license
7+
// <license-mit or http://opensource.org/licenses/mit>, at your
8+
// option. this file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
use option::{Option, Some, None};
11+
use result::{Ok, Err};
12+
use rt::io::{io_error};
13+
use rt::rtio::{IoFactory, IoFactoryObject,
14+
RtioTimer, RtioTimerObject};
15+
use rt::local::Local;
16+
17+
pub struct Timer(~RtioTimerObject);
18+
19+
impl Timer {
20+
fn new(i: ~RtioTimerObject) -> Timer {
21+
Timer(i)
22+
}
23+
24+
pub fn init() -> Option<Timer> {
25+
let timer = unsafe {
26+
rtdebug!("Timer::init: borrowing io to init timer");
27+
let io = Local::unsafe_borrow::<IoFactoryObject>();
28+
rtdebug!("about to init timer");
29+
(*io).timer_init()
30+
};
31+
match timer {
32+
Ok(t) => Some(Timer::new(t)),
33+
Err(ioerr) => {
34+
rtdebug!("Timer::init: failed to init: %?", ioerr);
35+
io_error::cond.raise(ioerr);
36+
None
37+
}
38+
}
39+
}
40+
}
41+
42+
impl RtioTimer for Timer {
43+
fn sleep(&self, msecs: u64) {
44+
(**self).sleep(msecs);
45+
}
46+
}
47+
48+
#[cfg(test)]
49+
mod test {
50+
use super::*;
51+
use rt::test::*;
52+
use option::{Some, None};
53+
#[test]
54+
fn test_io_timer_sleep_simple() {
55+
do run_in_newsched_task {
56+
let timer = Timer::init();
57+
match timer {
58+
Some(t) => t.sleep(1),
59+
None => assert!(false)
60+
}
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)