Skip to content

Commit c9d92f1

Browse files
committed
eventfd: Follow nix conventions
This commit revamps to eventfd to follow nix conventions: - drop in-crate FFI definitions - rename EventFdFlag to EfdFlags Additionally, it changes the initval argument to be a libc::c_uint, matching the actual type.
1 parent a869f5c commit c9d92f1

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/sys/eventfd.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,16 @@ use libc;
22
use std::os::unix::io::RawFd;
33
use {Errno, Result};
44

5-
bitflags!(
6-
flags EventFdFlag: libc::c_int {
7-
const EFD_CLOEXEC = 0o2000000, // Since Linux 2.6.27
8-
const EFD_NONBLOCK = 0o0004000, // Since Linux 2.6.27
9-
const EFD_SEMAPHORE = 0o0000001, // Since Linux 2.6.30
10-
}
11-
);
12-
13-
mod ffi {
14-
use libc;
15-
16-
extern {
17-
pub fn eventfd(initval: libc::c_uint, flags: libc::c_int) -> libc::c_int;
5+
libc_bitflags! {
6+
flags EfdFlags: libc::c_int {
7+
const EFD_CLOEXEC, // Since Linux 2.6.27
8+
const EFD_NONBLOCK, // Since Linux 2.6.27
9+
const EFD_SEMAPHORE, // Since Linux 2.6.30
1810
}
1911
}
2012

21-
pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result<RawFd> {
22-
unsafe {
23-
let res = ffi::eventfd(initval as libc::c_uint, flags.bits());
13+
pub fn eventfd(initval: libc::c_uint, flags: EfdFlags) -> Result<RawFd> {
14+
let res = unsafe { libc::eventfd(initval, flags.bits()) };
2415

25-
Errno::result(res).map(|r| r as RawFd)
26-
}
16+
Errno::result(res).map(|r| r as RawFd)
2717
}

0 commit comments

Comments
 (0)