2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2015, Joyent, Inc. All rights reserved.
16 #include <sys/eventfd.h>
23 eventfd(unsigned int initval
, int flags
)
26 uint64_t val
= initval
;
29 if (flags
& ~(EFD_NONBLOCK
| EFD_CLOEXEC
| EFD_SEMAPHORE
)) {
34 if (flags
& EFD_NONBLOCK
)
37 if (flags
& EFD_CLOEXEC
)
40 if ((fd
= open("/dev/eventfd", oflags
)) < 0)
43 if ((flags
& EFD_SEMAPHORE
) &&
44 ioctl(fd
, EVENTFDIOC_SEMAPHORE
, 0) != 0) {
49 if (write(fd
, &val
, sizeof (val
)) < sizeof (val
)) {
58 eventfd_read(int fd
, eventfd_t
*valp
)
60 return (read(fd
, valp
, sizeof (*valp
)) < sizeof (*valp
) ? -1 : 0);
64 eventfd_write(int fd
, eventfd_t val
)
66 return (write(fd
, &val
, sizeof (val
)) < sizeof (val
) ? -1 : 0);