ichwd - Fix typo in TCO2_CNT register #define.
[dragonfly.git] / test / debug / evfilt_user.c
blobf5ace653d59699e084324195ceb1e6ac170631d7
1 /*
2 * cc evfilt_user.c -pthread -I/usr/src/sys/ -o /tmp/evfilt_user
3 */
5 #include <sys/types.h>
6 #include <sys/event.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <pthread.h>
12 static void *domaster(void *arg);
13 static void *doslave(void *arg);
15 int
16 main(int ac, char **avj)
18 int fd;
19 int r;
20 struct kevent kev;
21 pthread_t td1;
22 pthread_t td2;
24 fd = kqueue();
25 EV_SET(&kev, 1, EVFILT_USER, EV_ADD|EV_CLEAR, 0, 0, 0);
26 r = kevent(fd, &kev, 1, NULL, 0, NULL);
27 printf("r = %d\n", r);
28 pthread_create(&td1, NULL, domaster, (void *)(intptr_t)fd);
29 sleep(1);
30 pthread_create(&td2, NULL, doslave, (void *)(intptr_t)fd);
31 pthread_join(td1, NULL);
32 pthread_join(td2, NULL);
35 static void *
36 domaster(void *arg)
38 struct kevent kev;
39 int fd = (int)(intptr_t)arg;
40 int r;
42 printf("master running\n");
43 for (;;) {
44 EV_SET(&kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, 0);
45 r = kevent(fd, &kev, 1, NULL, 0, NULL);
46 printf("issued trigger %d\n", r);
47 sleep(1);
50 return NULL;
53 static void *
54 doslave(void *arg)
56 struct kevent kev;
57 int fd = (int)(intptr_t)arg;
58 int r;
60 printf("slave running\n");
61 for (;;) {
62 r = kevent(fd, NULL, 0, &kev, 1, NULL);
63 printf("received %d\n", r);
65 EV_SET(&kev, 1, EVFILT_USER, EV_CLEAR, 0, 0, 0);
66 r = kevent(fd, &kev, 1, NULL, 0, NULL);
69 return NULL;