diff options
author | Carl Lerche <me@carllerche.com> | 2015-04-08 10:58:06 -0700 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2015-04-08 10:58:06 -0700 |
commit | 9b0a534962f3a2852491a3b0bc4d4e857f2a1382 (patch) | |
tree | 142be49940886ee6ab4b552ad2405787c0f9c9aa /src | |
parent | c5c21c4c96b8ec4b5b4fa243ce1ad5978a02c964 (diff) | |
download | nix-9b0a534962f3a2852491a3b0bc4d4e857f2a1382.zip |
Bring back eventfd behind a feature flag
At some point, feature flags will be switched to a conditional build system.
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/eventfd.rs | 32 | ||||
-rw-r--r-- | src/sys/mod.rs | 6 |
2 files changed, 16 insertions, 22 deletions
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; |