From a4ce09b497cee146a6dd2cc8ff115ae1a43c838a Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Sun, 21 Sep 2014 23:47:04 -0700 Subject: Bind eventfd() --- src/sys/eventfd.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/sys/eventfd.rs (limited to 'src/sys/eventfd.rs') diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs new file mode 100644 index 00000000..178cd277 --- /dev/null +++ b/src/sys/eventfd.rs @@ -0,0 +1,29 @@ +use libc::{c_int, c_uint}; +use fcntl::Fd; +use errno::{SysResult, SysError, from_ffi}; + +mod ffi { + use libc::{c_int, c_uint}; + + extern { + pub fn eventfd(initval: c_uint, flags: c_int) -> c_int; + } +} + +bitflags!( + flags EventFdFlag: c_int { + static EFD_CLOEXEC = 0o2000000, // Since Linux 2.6.27 + static EFD_NONBLOCK = 0o0004000, // Since Linux 2.6.27 + static EFD_SEMAPHORE = 0o0000001, // Since Linux 2.6.30 + } +) + +pub fn eventfd(initval: uint, flags: EventFdFlag) -> SysResult { + let res = unsafe { ffi::eventfd(initval as c_uint, flags.bits()) }; + + if res < 0 { + return Err(SysError::last()); + } + + Ok(res) +} -- cgit v1.2.3