3 #include <sys/eventfd.h>
10 static void xsem_wait(int fd
)
14 if (eventfd_read(fd
, &cntr
) != 0) {
15 perror("reading eventfd");
19 fprintf(stderr
, "fd %d wait completed: count=%" PRIu64
"\n",
23 static void xsem_post(int fd
, int count
)
25 eventfd_t cntr
= count
;
27 if (eventfd_write(fd
, cntr
) != 0) {
28 perror("writing eventfd");
33 static void sem_player(int fd1
, int fd2
)
35 /* these printfs did contain the pid
36 * so "[%u] ... ", getpid()
37 * not good for regresson tests
38 * (also xsem_wait above)
40 fprintf(stderr
, "fd %d posting 1\n", fd1
);
43 fprintf(stderr
, "fd %d waiting\n", fd2
);
46 fprintf(stderr
, "fd %d posting 1\n", fd1
);
49 fprintf(stderr
, "fd %d waiting\n", fd2
);
52 fprintf(stderr
, "fd %d posting 5\n", fd1
);
55 fprintf(stderr
, "fd %d waiting 5 times\n", fd2
);
63 static void usage(char const *prg
)
65 fprintf(stderr
, "use: %s [-h]\n", prg
);
68 int main(int argc
, char **argv
)
70 int c
, fd1
, fd2
, status
;
71 pid_t cpid_poster
, cpid_waiter
;
73 while ((c
= getopt(argc
, argv
, "h")) != -1) {
82 if ((fd1
= eventfd(0, EFD_SEMAPHORE
)) == -1 ||
83 (fd2
= eventfd(0, EFD_SEMAPHORE
)) == -1) {
87 if ((cpid_poster
= fork()) == 0) {
92 if ((cpid_waiter
= fork()) == 0) {
96 waitpid(cpid_poster
, &status
, 0);
97 waitpid(cpid_waiter
, &status
, 0);