blob: cfc48e037e16c16db3112fc3c40744f649c7f54c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
use std::mem;
use libc::{c_int, c_uint};
use fcntl::Fd;
use errno::{SysResult, SysError};
bitflags!(
flags EventFdFlag: 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: uint, flags: EventFdFlag) -> SysResult<Fd> {
type F = unsafe extern "C" fn(initval: c_uint, flags: c_int) -> c_int;
extern {
#[linkage = "extern_weak"]
static eventfd: *const ();
}
if eventfd.is_null() {
panic!("eventfd unsupported on this platform");
}
let res = unsafe {
mem::transmute::<*const (), F>(eventfd)(
initval as c_uint, flags.bits())
};
if res < 0 {
return Err(SysError::last());
}
Ok(res)
}
|