summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2015-04-08 10:58:06 -0700
committerCarl Lerche <me@carllerche.com>2015-04-08 10:58:06 -0700
commit9b0a534962f3a2852491a3b0bc4d4e857f2a1382 (patch)
tree142be49940886ee6ab4b552ad2405787c0f9c9aa
parentc5c21c4c96b8ec4b5b4fa243ce1ad5978a02c964 (diff)
downloadnix-9b0a534962f3a2852491a3b0bc4d4e857f2a1382.zip
Bring back eventfd behind a feature flag
At some point, feature flags will be switched to a conditional build system.
-rw-r--r--Cargo.toml4
-rw-r--r--src/sys/eventfd.rs32
-rw-r--r--src/sys/mod.rs6
3 files changed, 20 insertions, 22 deletions
diff --git a/Cargo.toml b/Cargo.toml
index f1c13d57..64b7bd46 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,6 +13,10 @@ exclude = [
"test/**/*"
]
+[features]
+
+eventfd = []
+
[dependencies]
libc = "0.1.4"
bitflags = "0.1.1"
diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs
index 866c95a3..e8e2bd23 100644
--- a/src/sys/eventfd.rs
+++ b/src/sys/eventfd.rs
@@ -1,37 +1,31 @@
-use std::mem;
-use libc::{c_int, c_uint};
-use errno::Errno;
+use libc;
use fcntl::Fd;
use {Error, Result};
bitflags!(
- flags EventFdFlag: c_int {
+ flags EventFdFlag: libc::c_int {
const EFD_CLOEXEC = 0o2000000, // Since Linux 2.6.27
const EFD_NONBLOCK = 0o0004000, // Since Linux 2.6.27
const EFD_SEMAPHORE = 0o0000001, // Since Linux 2.6.30
}
);
-pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result<Fd> {
- type F = unsafe extern "C" fn(initval: c_uint, flags: c_int) -> c_int;
+mod ffi {
+ use libc;
extern {
- // #[linkage = "extern_weak"]
- static eventfd: *const ();
+ pub fn eventfd(initval: libc::c_uint, flags: libc::c_int) -> libc::c_int;
}
+}
- if eventfd.is_null() {
- panic!("eventfd unsupported on this platform");
- }
+pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result<Fd> {
+ unsafe {
+ let res = ffi::eventfd(initval as libc::c_uint, flags.bits());
- let res = unsafe {
- mem::transmute::<*const (), F>(eventfd)(
- initval as c_uint, flags.bits())
- };
+ if res < 0 {
+ return Err(Error::last());
+ }
- if res < 0 {
- return Err(Error::Sys(Errno::last()));
+ Ok(res as Fd)
}
-
- Ok(res)
}
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index fbd75d23..f25aecb4 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -5,9 +5,9 @@ pub mod epoll;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub mod event;
-// Dont' support eventfd for now
-// #[cfg(any(target_os = "linux", target_os = "android"))]
-// pub mod eventfd;
+// TODO: switch from feature flags to conditional builds
+#[cfg(feature = "eventfd")]
+pub mod eventfd;
#[cfg(not(target_os = "ios"))]
pub mod ioctl;