about summary refs log tree commit diff
path: root/src/libstd/sys/redox/thread.rs
diff options
context:
space:
mode:
authorJeremy Soller <jackpot51@gmail.com>2016-10-28 14:17:34 -0600
committerJeremy Soller <jackpot51@gmail.com>2016-10-28 14:17:34 -0600
commita5de9bb591c9752d39c87339fd8f5ff49ea4b2da (patch)
tree69c296d20f5fe58d0bbd2b603bd4143430a5d6a2 /src/libstd/sys/redox/thread.rs
parent8b09e01fef9912e7c3eef997c40f9f4f91d09e4c (diff)
downloadrust-a5de9bb591c9752d39c87339fd8f5ff49ea4b2da.tar.gz
rust-a5de9bb591c9752d39c87339fd8f5ff49ea4b2da.zip
Remove unsafe libc layer
Diffstat (limited to 'src/libstd/sys/redox/thread.rs')
-rw-r--r--src/libstd/sys/redox/thread.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/libstd/sys/redox/thread.rs b/src/libstd/sys/redox/thread.rs
index eaf908dc53e..616da662d9a 100644
--- a/src/libstd/sys/redox/thread.rs
+++ b/src/libstd/sys/redox/thread.rs
@@ -14,7 +14,6 @@ use ffi::CStr;
 use io;
 use libc;
 use mem;
-use sys::os;
 use sys_common::thread::start_thread;
 use time::Duration;
 
@@ -42,7 +41,7 @@ impl Thread {
     }
 
     pub fn set_name(_name: &CStr) {
-
+        unimplemented!();
     }
 
     pub fn sleep(dur: Duration) {
@@ -51,20 +50,18 @@ impl Thread {
 
         // If we're awoken with a signal then the return value will be -1 and
         // nanosleep will fill in `ts` with the remaining time.
-        unsafe {
-            while secs > 0 || nsecs > 0 {
-                let mut ts = libc::timespec {
-                    tv_sec: cmp::min(libc::time_t::max_value() as u64, secs) as libc::time_t,
-                    tv_nsec: nsecs,
-                };
-                secs -= ts.tv_sec as u64;
-                if libc::nanosleep(&ts, &mut ts) == -1 {
-                    assert_eq!(os::errno(), libc::EINTR);
-                    secs += ts.tv_sec as u64;
-                    nsecs = ts.tv_nsec;
-                } else {
-                    nsecs = 0;
-                }
+        while secs > 0 || nsecs > 0 {
+            let req = libc::timespec {
+                tv_sec: cmp::min(libc::time_t::max_value() as u64, secs) as libc::time_t,
+                tv_nsec: nsecs,
+            };
+            secs -= req.tv_sec as u64;
+            let mut rem = libc::timespec::default();
+            if libc::nanosleep(&req, &mut rem).is_err() {
+                secs += rem.tv_sec as u64;
+                nsecs = rem.tv_nsec;
+            } else {
+                nsecs = 0;
             }
         }
     }