Skip to content

Commit 05b3bb1

Browse files
committed
Weak link eventfd
1 parent e8b9636 commit 05b3bb1

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/sys/eventfd.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1+
use std::mem;
12
use libc::{c_int, c_uint};
23
use fcntl::Fd;
34
use errno::{SysResult, SysError, from_ffi};
45

5-
mod ffi {
6-
use libc::{c_int, c_uint};
7-
8-
extern {
9-
pub fn eventfd(initval: c_uint, flags: c_int) -> c_int;
10-
}
11-
}
12-
136
bitflags!(
147
flags EventFdFlag: c_int {
158
static EFD_CLOEXEC = 0o2000000, // Since Linux 2.6.27
@@ -19,7 +12,21 @@ bitflags!(
1912
)
2013

2114
pub fn eventfd(initval: uint, flags: EventFdFlag) -> SysResult<Fd> {
22-
let res = unsafe { ffi::eventfd(initval as c_uint, flags.bits()) };
15+
type F = unsafe extern "C" fn(initval: c_uint, flags: c_int) -> c_int;
16+
17+
extern {
18+
#[linkage = "extern_weak"]
19+
static eventfd: *const ();
20+
}
21+
22+
if eventfd.is_null() {
23+
fail!("eventfd unsupported on this platform");
24+
}
25+
26+
let res = unsafe {
27+
mem::transmute::<*const (), F>(eventfd)(
28+
initval as c_uint, flags.bits())
29+
};
2330

2431
if res < 0 {
2532
return Err(SysError::last());

0 commit comments

Comments
 (0)