File tree Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: 62f1d68439dcfd509eaca29887afa97f22938373
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
- refs/heads/snap-stage3: 8334dd445fb10089a68808e7895f0c00d6fd0b3e
4
+ refs/heads/snap-stage3: d8bd8de82e19702ad26fff704ff9a4890ebe1bf7
5
5
refs/heads/try: db814977d07bd798feb24f6b74c00800ef458a13
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Original file line number Diff line number Diff line change @@ -218,8 +218,15 @@ impl Timer {
218
218
}
219
219
220
220
pub fn sleep ( ms : u64 ) {
221
- // FIXME: this can fail because of EINTR, what do do?
222
- let _ = unsafe { libc:: usleep ( ( ms * 1000 ) as libc:: c_uint ) } ;
221
+ let mut to_sleep = libc:: timespec {
222
+ tv_sec : ( ms / 1000 ) as libc:: time_t ,
223
+ tv_nsec : ( ( ms % 1000 ) * 1000000 ) as libc:: c_long ,
224
+ } ;
225
+ while unsafe { libc:: nanosleep ( & to_sleep, & mut to_sleep) } != 0 {
226
+ if os:: errno ( ) as int != libc:: EINTR as int {
227
+ fail ! ( "failed to sleep, but not because of EINTR?" ) ;
228
+ }
229
+ }
223
230
}
224
231
225
232
fn inner ( & mut self ) -> ~Inner {
Original file line number Diff line number Diff line change 23
23
//! why).
24
24
//!
25
25
//! As with timer_other, timers just using sleep() do not use the timerfd at
26
- //! all. They remove the timerfd from the worker thread and then invoke usleep()
27
- //! to block the calling thread.
26
+ //! all. They remove the timerfd from the worker thread and then invoke
27
+ //! nanosleep() to block the calling thread.
28
28
//!
29
29
//! As with timer_other, all units in this file are in units of millseconds.
30
30
@@ -183,8 +183,15 @@ impl Timer {
183
183
}
184
184
185
185
pub fn sleep ( ms : u64 ) {
186
- // FIXME: this can fail because of EINTR, what do do?
187
- let _ = unsafe { libc:: usleep ( ( ms * 1000 ) as libc:: c_uint ) } ;
186
+ let mut to_sleep = libc:: timespec {
187
+ tv_sec : ( ms / 1000 ) as libc:: time_t ,
188
+ tv_nsec : ( ( ms % 1000 ) * 1000000 ) as libc:: c_long ,
189
+ } ;
190
+ while unsafe { libc:: nanosleep ( & to_sleep, & mut to_sleep) } != 0 {
191
+ if os:: errno ( ) as int != libc:: EINTR as int {
192
+ fail ! ( "failed to sleep, but not because of EINTR?" ) ;
193
+ }
194
+ }
188
195
}
189
196
190
197
fn remove ( & mut self ) {
Original file line number Diff line number Diff line change @@ -3682,6 +3682,7 @@ pub mod funcs {
3682
3682
use libc:: types:: common:: c95:: c_void;
3683
3683
use libc:: types:: os:: arch:: c95:: { c_char, c_int, c_long, c_uint} ;
3684
3684
use libc:: types:: os:: arch:: c95:: { size_t} ;
3685
+ use libc:: types:: os:: common:: posix01:: timespec;
3685
3686
use libc:: types:: os:: arch:: posix01:: utimbuf;
3686
3687
use libc:: types:: os:: arch:: posix88:: { gid_t, off_t, pid_t} ;
3687
3688
use libc:: types:: os:: arch:: posix88:: { ssize_t, uid_t} ;
@@ -3731,6 +3732,7 @@ pub mod funcs {
3731
3732
pub fn setuid ( uid : uid_t ) -> c_int ;
3732
3733
pub fn sleep ( secs : c_uint ) -> c_uint ;
3733
3734
pub fn usleep ( secs : c_uint ) -> c_int ;
3735
+ pub fn nanosleep ( rqtp : * timespec , rmtp : * mut timespec ) -> c_int ;
3734
3736
pub fn sysconf ( name : c_int ) -> c_long ;
3735
3737
pub fn tcgetpgrp ( fd : c_int ) -> pid_t ;
3736
3738
pub fn ttyname ( fd : c_int ) -> * c_char ;
You can’t perform that action at this time.
0 commit comments