about summary refs log tree commit diff
path: root/src/libstd/sys/unix
diff options
context:
space:
mode:
authorAaron Turon <aturon@mozilla.com>2014-10-15 15:45:59 -0700
committerAaron Turon <aturon@mozilla.com>2014-11-08 20:40:38 -0800
commit3d195482a45bf3ed0f12dc9d70d14192262ca711 (patch)
treed9cf1a93cc1e862e641cd17fdb41ebe93d22bfea /src/libstd/sys/unix
parentd34b1b0ca9bf5e0d7cd30952f5de0ab09ed57b41 (diff)
Runtime removal: refactor helper threads
This patch continues the runtime removal by moving
libnative::io::helper_thread into sys::helper_signal and
sys_common::helper_thread

Because this eliminates APIs in `libnative` and `librustrt`, it is a:

[breaking-change]

This functionality is likely to be available publicly, in some form,
from `std` in the future.
Diffstat (limited to 'src/libstd/sys/unix')
-rw-r--r--src/libstd/sys/unix/helper_signal.rs29
-rw-r--r--src/libstd/sys/unix/mod.rs11
2 files changed, 40 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/helper_signal.rs b/src/libstd/sys/unix/helper_signal.rs
new file mode 100644
index 00000000000..a806bea2568
--- /dev/null
+++ b/src/libstd/sys/unix/helper_signal.rs
@@ -0,0 +1,29 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use libc;
+use os;
+
+use sys::fs::FileDesc;
+
+pub type signal = libc::c_int;
+
+pub fn new() -> (signal, signal) {
+    let os::Pipe { reader, writer } = unsafe { os::pipe().unwrap() };
+    (reader, writer)
+}
+
+pub fn signal(fd: libc::c_int) {
+    FileDesc::new(fd, false).write([0]).ok().unwrap();
+}
+
+pub fn close(fd: libc::c_int) {
+    let _fd = FileDesc::new(fd, true);
+}
diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs
index 5a43fd08f90..6295864e0e1 100644
--- a/src/libstd/sys/unix/mod.rs
+++ b/src/libstd/sys/unix/mod.rs
@@ -17,12 +17,23 @@ use prelude::*;
 use io::{mod, IoResult, IoError};
 use sys_common::mkerr_libc;
 
+
+macro_rules! helper_init( (static $name:ident: Helper<$m:ty>) => (
+    static $name: Helper<$m> = Helper {
+        lock: ::rt::mutex::NATIVE_MUTEX_INIT,
+        chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
+        signal: ::cell::UnsafeCell { value: 0 },
+        initialized: ::cell::UnsafeCell { value: false },
+    };
+) )
+
 pub mod c;
 pub mod fs;
 pub mod os;
 pub mod tcp;
 pub mod udp;
 pub mod pipe;
+pub mod helper_signal;
 
 pub mod addrinfo {
     pub use sys_common::net::get_host_addresses;