summaryrefslogtreecommitdiff
path: root/src/sys/eventfd.rs
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 /src/sys/eventfd.rs
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.
Diffstat (limited to 'src/sys/eventfd.rs')
-rw-r--r--src/sys/eventfd.rs32
1 files changed, 13 insertions, 19 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)
}