2 * Copyright (c) 2010 Mark Heily <mark@heily.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/eventfd.h>
26 /* A structure is used to allow other targets to emulate this */
37 e = malloc(sizeof(*e));
41 if ((evfd = eventfd(0, 0)) < 0) {
45 if (fcntl(evfd, F_SETFL, O_NONBLOCK) < 0) {
56 eventfd_free(struct eventfd *e)
63 eventfd_raise(struct eventfd *e)
68 dbg_puts("raising event level");
70 if (write(e->fd, &counter, sizeof(counter)) < 0) {
73 /* Not considered an error */
81 dbg_printf("write(2): %s", strerror(errno));
89 eventfd_lower(struct eventfd *e)
94 /* Reset the counter */
95 dbg_puts("lowering event level");
96 if (read(e->fd, &cur, sizeof(cur)) < sizeof(cur)) {
99 /* Not considered an error */
107 dbg_printf("read(2): %s", strerror(errno));
116 eventfd_reader(struct eventfd *e)
122 eventfd_writer(struct eventfd *e)