]>
git.ipfire.org Git - thirdparty/linux.git/blob - tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c
1 // SPDX-License-Identifier: GPL-2.0
10 #include <sys/socket.h>
11 #include <sys/eventfd.h>
12 #include "../../kselftest_harness.h"
14 struct epoll_mtcontext
24 static void signal_handler(int signum
)
28 static void kill_timeout(struct epoll_mtcontext
*ctx
)
31 pthread_kill(ctx
->main
, SIGUSR1
);
32 pthread_kill(ctx
->waiter
, SIGUSR1
);
35 static void *waiter_entry1a(void *data
)
38 struct epoll_mtcontext
*ctx
= data
;
40 if (epoll_wait(ctx
->efd
[0], &e
, 1, -1) > 0)
41 __sync_fetch_and_add(&ctx
->count
, 1);
46 static void *waiter_entry1ap(void *data
)
50 struct epoll_mtcontext
*ctx
= data
;
54 if (poll(&pfd
, 1, -1) > 0) {
55 if (epoll_wait(ctx
->efd
[0], &e
, 1, 0) > 0)
56 __sync_fetch_and_add(&ctx
->count
, 1);
62 static void *waiter_entry1o(void *data
)
65 struct epoll_mtcontext
*ctx
= data
;
67 if (epoll_wait(ctx
->efd
[0], &e
, 1, -1) > 0)
68 __sync_fetch_and_or(&ctx
->count
, 1);
73 static void *waiter_entry1op(void *data
)
77 struct epoll_mtcontext
*ctx
= data
;
81 if (poll(&pfd
, 1, -1) > 0) {
82 if (epoll_wait(ctx
->efd
[0], &e
, 1, 0) > 0)
83 __sync_fetch_and_or(&ctx
->count
, 1);
89 static void *waiter_entry2a(void *data
)
91 struct epoll_event events
[2];
92 struct epoll_mtcontext
*ctx
= data
;
94 if (epoll_wait(ctx
->efd
[0], events
, 2, -1) > 0)
95 __sync_fetch_and_add(&ctx
->count
, 1);
100 static void *waiter_entry2ap(void *data
)
103 struct epoll_event events
[2];
104 struct epoll_mtcontext
*ctx
= data
;
106 pfd
.fd
= ctx
->efd
[0];
108 if (poll(&pfd
, 1, -1) > 0) {
109 if (epoll_wait(ctx
->efd
[0], events
, 2, 0) > 0)
110 __sync_fetch_and_add(&ctx
->count
, 1);
116 static void *emitter_entry1(void *data
)
118 struct epoll_mtcontext
*ctx
= data
;
121 write(ctx
->sfd
[1], "w", 1);
128 static void *emitter_entry2(void *data
)
130 struct epoll_mtcontext
*ctx
= data
;
133 write(ctx
->sfd
[1], "w", 1);
134 write(ctx
->sfd
[3], "w", 1);
152 struct epoll_event e
;
154 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
156 efd
= epoll_create(1);
160 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
162 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
164 EXPECT_EQ(epoll_wait(efd
, &e
, 1, 0), 1);
165 EXPECT_EQ(epoll_wait(efd
, &e
, 1, 0), 1);
183 struct epoll_event e
;
185 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
187 efd
= epoll_create(1);
190 e
.events
= EPOLLIN
| EPOLLET
;
191 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
193 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
195 EXPECT_EQ(epoll_wait(efd
, &e
, 1, 0), 1);
196 EXPECT_EQ(epoll_wait(efd
, &e
, 1, 0), 0);
214 struct epoll_event events
[2];
216 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
217 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[2]), 0);
219 efd
= epoll_create(1);
222 events
[0].events
= EPOLLIN
;
223 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[0], events
), 0);
225 events
[0].events
= EPOLLIN
;
226 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[2], events
), 0);
228 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
229 ASSERT_EQ(write(sfd
[3], "w", 1), 1);
231 EXPECT_EQ(epoll_wait(efd
, events
, 2, 0), 2);
232 EXPECT_EQ(epoll_wait(efd
, events
, 2, 0), 2);
252 struct epoll_event events
[2];
254 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
255 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[2]), 0);
257 efd
= epoll_create(1);
260 events
[0].events
= EPOLLIN
| EPOLLET
;
261 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[0], events
), 0);
263 events
[0].events
= EPOLLIN
| EPOLLET
;
264 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[2], events
), 0);
266 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
267 ASSERT_EQ(write(sfd
[3], "w", 1), 1);
269 EXPECT_EQ(epoll_wait(efd
, events
, 2, 0), 2);
270 EXPECT_EQ(epoll_wait(efd
, events
, 2, 0), 0);
291 struct epoll_event e
;
293 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
295 efd
= epoll_create(1);
299 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
301 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
305 ASSERT_EQ(poll(&pfd
, 1, 0), 1);
306 ASSERT_EQ(epoll_wait(efd
, &e
, 1, 0), 1);
310 ASSERT_EQ(poll(&pfd
, 1, 0), 1);
311 ASSERT_EQ(epoll_wait(efd
, &e
, 1, 0), 1);
330 struct epoll_event e
;
332 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
334 efd
= epoll_create(1);
337 e
.events
= EPOLLIN
| EPOLLET
;
338 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
340 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
344 ASSERT_EQ(poll(&pfd
, 1, 0), 1);
345 ASSERT_EQ(epoll_wait(efd
, &e
, 1, 0), 1);
349 ASSERT_EQ(poll(&pfd
, 1, 0), 0);
350 ASSERT_EQ(epoll_wait(efd
, &e
, 1, 0), 0);
370 struct epoll_event events
[2];
372 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
373 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[2]), 0);
375 efd
= epoll_create(1);
378 events
[0].events
= EPOLLIN
;
379 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[0], events
), 0);
381 events
[0].events
= EPOLLIN
;
382 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[2], events
), 0);
384 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
385 ASSERT_EQ(write(sfd
[3], "w", 1), 1);
389 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
390 EXPECT_EQ(epoll_wait(efd
, events
, 2, 0), 2);
394 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
395 EXPECT_EQ(epoll_wait(efd
, events
, 2, 0), 2);
416 struct epoll_event events
[2];
418 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
419 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[2]), 0);
421 efd
= epoll_create(1);
424 events
[0].events
= EPOLLIN
| EPOLLET
;
425 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[0], events
), 0);
427 events
[0].events
= EPOLLIN
| EPOLLET
;
428 ASSERT_EQ(epoll_ctl(efd
, EPOLL_CTL_ADD
, sfd
[2], events
), 0);
430 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
431 ASSERT_EQ(write(sfd
[3], "w", 1), 1);
435 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
436 EXPECT_EQ(epoll_wait(efd
, events
, 2, 0), 2);
440 EXPECT_EQ(poll(&pfd
, 1, 0), 0);
441 EXPECT_EQ(epoll_wait(efd
, events
, 2, 0), 0);
460 struct epoll_event e
;
461 struct epoll_mtcontext ctx
= { 0 };
463 signal(SIGUSR1
, signal_handler
);
465 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
467 ctx
.efd
[0] = epoll_create(1);
468 ASSERT_GE(ctx
.efd
[0], 0);
471 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
473 ctx
.main
= pthread_self();
474 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
475 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
477 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
478 __sync_fetch_and_add(&ctx
.count
, 1);
480 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
481 EXPECT_EQ(ctx
.count
, 2);
483 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
484 pthread_kill(emitter
, SIGUSR1
);
485 pthread_join(emitter
, NULL
);
503 struct epoll_event e
;
504 struct epoll_mtcontext ctx
= { 0 };
506 signal(SIGUSR1
, signal_handler
);
508 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
510 ctx
.efd
[0] = epoll_create(1);
511 ASSERT_GE(ctx
.efd
[0], 0);
513 e
.events
= EPOLLIN
| EPOLLET
;
514 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
516 ctx
.main
= pthread_self();
517 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
518 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
520 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
521 __sync_fetch_and_add(&ctx
.count
, 1);
523 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
524 EXPECT_EQ(ctx
.count
, 1);
526 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
527 pthread_kill(emitter
, SIGUSR1
);
528 pthread_join(emitter
, NULL
);
546 struct epoll_event events
[2];
547 struct epoll_mtcontext ctx
= { 0 };
549 signal(SIGUSR1
, signal_handler
);
551 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
552 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
554 ctx
.efd
[0] = epoll_create(1);
555 ASSERT_GE(ctx
.efd
[0], 0);
557 events
[0].events
= EPOLLIN
;
558 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[0], events
), 0);
560 events
[0].events
= EPOLLIN
;
561 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[2], events
), 0);
563 ctx
.main
= pthread_self();
564 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry2a
, &ctx
), 0);
565 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
567 if (epoll_wait(ctx
.efd
[0], events
, 2, -1) > 0)
568 __sync_fetch_and_add(&ctx
.count
, 1);
570 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
571 EXPECT_EQ(ctx
.count
, 2);
573 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
574 pthread_kill(emitter
, SIGUSR1
);
575 pthread_join(emitter
, NULL
);
595 struct epoll_event events
[2];
596 struct epoll_mtcontext ctx
= { 0 };
598 signal(SIGUSR1
, signal_handler
);
600 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
601 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
603 ctx
.efd
[0] = epoll_create(1);
604 ASSERT_GE(ctx
.efd
[0], 0);
606 events
[0].events
= EPOLLIN
| EPOLLET
;
607 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[0], events
), 0);
609 events
[0].events
= EPOLLIN
| EPOLLET
;
610 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[2], events
), 0);
612 ctx
.main
= pthread_self();
613 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
614 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
616 if (epoll_wait(ctx
.efd
[0], events
, 1, -1) > 0)
617 __sync_fetch_and_add(&ctx
.count
, 1);
619 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
620 EXPECT_EQ(ctx
.count
, 2);
622 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
623 pthread_kill(emitter
, SIGUSR1
);
624 pthread_join(emitter
, NULL
);
644 struct epoll_event e
;
645 struct epoll_mtcontext ctx
= { 0 };
647 signal(SIGUSR1
, signal_handler
);
649 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
651 ctx
.efd
[0] = epoll_create(1);
652 ASSERT_GE(ctx
.efd
[0], 0);
655 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
657 ctx
.main
= pthread_self();
658 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
659 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
661 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
662 __sync_fetch_and_add(&ctx
.count
, 1);
664 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
665 EXPECT_EQ(ctx
.count
, 2);
667 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
668 pthread_kill(emitter
, SIGUSR1
);
669 pthread_join(emitter
, NULL
);
687 struct epoll_event e
;
688 struct epoll_mtcontext ctx
= { 0 };
690 signal(SIGUSR1
, signal_handler
);
692 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
694 ctx
.efd
[0] = epoll_create(1);
695 ASSERT_GE(ctx
.efd
[0], 0);
697 e
.events
= EPOLLIN
| EPOLLET
;
698 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
700 ctx
.main
= pthread_self();
701 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
702 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
704 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
705 __sync_fetch_and_add(&ctx
.count
, 1);
707 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
708 EXPECT_EQ(ctx
.count
, 1);
710 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
711 pthread_kill(emitter
, SIGUSR1
);
712 pthread_join(emitter
, NULL
);
730 struct epoll_event events
[2];
731 struct epoll_mtcontext ctx
= { 0 };
733 signal(SIGUSR1
, signal_handler
);
735 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
736 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
738 ctx
.efd
[0] = epoll_create(1);
739 ASSERT_GE(ctx
.efd
[0], 0);
741 events
[0].events
= EPOLLIN
;
742 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[0], events
), 0);
744 events
[0].events
= EPOLLIN
;
745 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[2], events
), 0);
747 ctx
.main
= pthread_self();
748 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry2ap
, &ctx
), 0);
749 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
751 if (epoll_wait(ctx
.efd
[0], events
, 2, -1) > 0)
752 __sync_fetch_and_add(&ctx
.count
, 1);
754 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
755 EXPECT_EQ(ctx
.count
, 2);
757 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
758 pthread_kill(emitter
, SIGUSR1
);
759 pthread_join(emitter
, NULL
);
779 struct epoll_event events
[2];
780 struct epoll_mtcontext ctx
= { 0 };
782 signal(SIGUSR1
, signal_handler
);
784 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
785 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
787 ctx
.efd
[0] = epoll_create(1);
788 ASSERT_GE(ctx
.efd
[0], 0);
790 events
[0].events
= EPOLLIN
| EPOLLET
;
791 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[0], events
), 0);
793 events
[0].events
= EPOLLIN
| EPOLLET
;
794 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[2], events
), 0);
796 ctx
.main
= pthread_self();
797 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
798 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
800 if (epoll_wait(ctx
.efd
[0], events
, 1, -1) > 0)
801 __sync_fetch_and_add(&ctx
.count
, 1);
803 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
804 EXPECT_EQ(ctx
.count
, 2);
806 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
807 pthread_kill(emitter
, SIGUSR1
);
808 pthread_join(emitter
, NULL
);
831 struct epoll_event e
;
833 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
835 efd
[0] = epoll_create(1);
836 ASSERT_GE(efd
[0], 0);
838 efd
[1] = epoll_create(1);
839 ASSERT_GE(efd
[1], 0);
842 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
845 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], &e
), 0);
847 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
849 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
850 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
871 struct epoll_event e
;
873 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
875 efd
[0] = epoll_create(1);
876 ASSERT_GE(efd
[0], 0);
878 efd
[1] = epoll_create(1);
879 ASSERT_GE(efd
[1], 0);
881 e
.events
= EPOLLIN
| EPOLLET
;
882 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
885 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], &e
), 0);
887 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
889 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
890 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
911 struct epoll_event e
;
913 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
915 efd
[0] = epoll_create(1);
916 ASSERT_GE(efd
[0], 0);
918 efd
[1] = epoll_create(1);
919 ASSERT_GE(efd
[1], 0);
922 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
924 e
.events
= EPOLLIN
| EPOLLET
;
925 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], &e
), 0);
927 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
929 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
930 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 0);
951 struct epoll_event e
;
953 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
955 efd
[0] = epoll_create(1);
956 ASSERT_GE(efd
[0], 0);
958 efd
[1] = epoll_create(1);
959 ASSERT_GE(efd
[1], 0);
961 e
.events
= EPOLLIN
| EPOLLET
;
962 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
964 e
.events
= EPOLLIN
| EPOLLET
;
965 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], &e
), 0);
967 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
969 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
970 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 0);
992 struct epoll_event e
;
994 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
996 efd
[0] = epoll_create(1);
997 ASSERT_GE(efd
[0], 0);
999 efd
[1] = epoll_create(1);
1000 ASSERT_GE(efd
[1], 0);
1003 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
1006 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], &e
), 0);
1008 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
1011 pfd
.events
= POLLIN
;
1012 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
1013 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
1016 pfd
.events
= POLLIN
;
1017 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
1018 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
1040 struct epoll_event e
;
1042 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
1044 efd
[0] = epoll_create(1);
1045 ASSERT_GE(efd
[0], 0);
1047 efd
[1] = epoll_create(1);
1048 ASSERT_GE(efd
[1], 0);
1050 e
.events
= EPOLLIN
| EPOLLET
;
1051 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
1054 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], &e
), 0);
1056 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
1059 pfd
.events
= POLLIN
;
1060 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
1061 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
1064 pfd
.events
= POLLIN
;
1065 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
1066 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
1088 struct epoll_event e
;
1090 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
1092 efd
[0] = epoll_create(1);
1093 ASSERT_GE(efd
[0], 0);
1095 efd
[1] = epoll_create(1);
1096 ASSERT_GE(efd
[1], 0);
1099 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
1101 e
.events
= EPOLLIN
| EPOLLET
;
1102 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], &e
), 0);
1104 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
1107 pfd
.events
= POLLIN
;
1108 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
1109 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
1112 pfd
.events
= POLLIN
;
1113 EXPECT_EQ(poll(&pfd
, 1, 0), 0);
1114 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 0);
1136 struct epoll_event e
;
1138 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, sfd
), 0);
1140 efd
[0] = epoll_create(1);
1141 ASSERT_GE(efd
[0], 0);
1143 efd
[1] = epoll_create(1);
1144 ASSERT_GE(efd
[1], 0);
1146 e
.events
= EPOLLIN
| EPOLLET
;
1147 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], &e
), 0);
1149 e
.events
= EPOLLIN
| EPOLLET
;
1150 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], &e
), 0);
1152 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
1155 pfd
.events
= POLLIN
;
1156 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
1157 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 1);
1160 pfd
.events
= POLLIN
;
1161 EXPECT_EQ(poll(&pfd
, 1, 0), 0);
1162 EXPECT_EQ(epoll_wait(efd
[0], &e
, 1, 0), 0);
1182 struct epoll_event e
;
1183 struct epoll_mtcontext ctx
= { 0 };
1185 signal(SIGUSR1
, signal_handler
);
1187 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1189 ctx
.efd
[0] = epoll_create(1);
1190 ASSERT_GE(ctx
.efd
[0], 0);
1192 ctx
.efd
[1] = epoll_create(1);
1193 ASSERT_GE(ctx
.efd
[1], 0);
1196 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1199 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1201 ctx
.main
= pthread_self();
1202 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
1203 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1205 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
1206 __sync_fetch_and_add(&ctx
.count
, 1);
1208 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1209 EXPECT_EQ(ctx
.count
, 2);
1211 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1212 pthread_kill(emitter
, SIGUSR1
);
1213 pthread_join(emitter
, NULL
);
1234 struct epoll_event e
;
1235 struct epoll_mtcontext ctx
= { 0 };
1237 signal(SIGUSR1
, signal_handler
);
1239 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1241 ctx
.efd
[0] = epoll_create(1);
1242 ASSERT_GE(ctx
.efd
[0], 0);
1244 ctx
.efd
[1] = epoll_create(1);
1245 ASSERT_GE(ctx
.efd
[1], 0);
1247 e
.events
= EPOLLIN
| EPOLLET
;
1248 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1251 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1253 ctx
.main
= pthread_self();
1254 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
1255 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1257 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
1258 __sync_fetch_and_add(&ctx
.count
, 1);
1260 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1261 EXPECT_EQ(ctx
.count
, 2);
1263 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1264 pthread_kill(emitter
, SIGUSR1
);
1265 pthread_join(emitter
, NULL
);
1286 struct epoll_event e
;
1287 struct epoll_mtcontext ctx
= { 0 };
1289 signal(SIGUSR1
, signal_handler
);
1291 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1293 ctx
.efd
[0] = epoll_create(1);
1294 ASSERT_GE(ctx
.efd
[0], 0);
1296 ctx
.efd
[1] = epoll_create(1);
1297 ASSERT_GE(ctx
.efd
[1], 0);
1300 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1302 e
.events
= EPOLLIN
| EPOLLET
;
1303 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1305 ctx
.main
= pthread_self();
1306 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
1307 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1309 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
1310 __sync_fetch_and_add(&ctx
.count
, 1);
1312 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1313 EXPECT_EQ(ctx
.count
, 1);
1315 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1316 pthread_kill(emitter
, SIGUSR1
);
1317 pthread_join(emitter
, NULL
);
1338 struct epoll_event e
;
1339 struct epoll_mtcontext ctx
= { 0 };
1341 signal(SIGUSR1
, signal_handler
);
1343 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1345 ctx
.efd
[0] = epoll_create(1);
1346 ASSERT_GE(ctx
.efd
[0], 0);
1348 ctx
.efd
[1] = epoll_create(1);
1349 ASSERT_GE(ctx
.efd
[1], 0);
1351 e
.events
= EPOLLIN
| EPOLLET
;
1352 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1354 e
.events
= EPOLLIN
| EPOLLET
;
1355 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1357 ctx
.main
= pthread_self();
1358 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
1359 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1361 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
1362 __sync_fetch_and_add(&ctx
.count
, 1);
1364 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1365 EXPECT_EQ(ctx
.count
, 1);
1367 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1368 pthread_kill(emitter
, SIGUSR1
);
1369 pthread_join(emitter
, NULL
);
1390 struct epoll_event e
;
1391 struct epoll_mtcontext ctx
= { 0 };
1393 signal(SIGUSR1
, signal_handler
);
1395 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1397 ctx
.efd
[0] = epoll_create(1);
1398 ASSERT_GE(ctx
.efd
[0], 0);
1400 ctx
.efd
[1] = epoll_create(1);
1401 ASSERT_GE(ctx
.efd
[1], 0);
1404 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1407 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1409 ctx
.main
= pthread_self();
1410 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
1411 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1413 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
1414 __sync_fetch_and_add(&ctx
.count
, 1);
1416 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1417 EXPECT_EQ(ctx
.count
, 2);
1419 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1420 pthread_kill(emitter
, SIGUSR1
);
1421 pthread_join(emitter
, NULL
);
1441 struct epoll_event e
;
1442 struct epoll_mtcontext ctx
= { 0 };
1444 signal(SIGUSR1
, signal_handler
);
1446 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1448 ctx
.efd
[0] = epoll_create(1);
1449 ASSERT_GE(ctx
.efd
[0], 0);
1451 ctx
.efd
[1] = epoll_create(1);
1452 ASSERT_GE(ctx
.efd
[1], 0);
1454 e
.events
= EPOLLIN
| EPOLLET
;
1455 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1458 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1460 ctx
.main
= pthread_self();
1461 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
1462 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1464 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
1465 __sync_fetch_and_add(&ctx
.count
, 1);
1467 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1468 EXPECT_EQ(ctx
.count
, 2);
1470 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1471 pthread_kill(emitter
, SIGUSR1
);
1472 pthread_join(emitter
, NULL
);
1492 struct epoll_event e
;
1493 struct epoll_mtcontext ctx
= { 0 };
1495 signal(SIGUSR1
, signal_handler
);
1497 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1499 ctx
.efd
[0] = epoll_create(1);
1500 ASSERT_GE(ctx
.efd
[0], 0);
1502 ctx
.efd
[1] = epoll_create(1);
1503 ASSERT_GE(ctx
.efd
[1], 0);
1506 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1508 e
.events
= EPOLLIN
| EPOLLET
;
1509 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1511 ctx
.main
= pthread_self();
1512 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
1513 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1515 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
1516 __sync_fetch_and_add(&ctx
.count
, 1);
1518 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1519 EXPECT_EQ(ctx
.count
, 1);
1521 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1522 pthread_kill(emitter
, SIGUSR1
);
1523 pthread_join(emitter
, NULL
);
1543 struct epoll_event e
;
1544 struct epoll_mtcontext ctx
= { 0 };
1546 signal(SIGUSR1
, signal_handler
);
1548 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1550 ctx
.efd
[0] = epoll_create(1);
1551 ASSERT_GE(ctx
.efd
[0], 0);
1553 ctx
.efd
[1] = epoll_create(1);
1554 ASSERT_GE(ctx
.efd
[1], 0);
1556 e
.events
= EPOLLIN
| EPOLLET
;
1557 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1559 e
.events
= EPOLLIN
| EPOLLET
;
1560 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1562 ctx
.main
= pthread_self();
1563 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
1564 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1566 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
1567 __sync_fetch_and_add(&ctx
.count
, 1);
1569 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1570 EXPECT_EQ(ctx
.count
, 1);
1572 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1573 pthread_kill(emitter
, SIGUSR1
);
1574 pthread_join(emitter
, NULL
);
1594 struct epoll_event e
;
1595 struct epoll_mtcontext ctx
= { 0 };
1597 signal(SIGUSR1
, signal_handler
);
1599 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1601 ctx
.efd
[0] = epoll_create(1);
1602 ASSERT_GE(ctx
.efd
[0], 0);
1604 ctx
.efd
[1] = epoll_create(1);
1605 ASSERT_GE(ctx
.efd
[1], 0);
1608 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1611 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1613 ctx
.main
= pthread_self();
1614 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
1615 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1617 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
1618 __sync_fetch_and_add(&ctx
.count
, 1);
1620 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1621 EXPECT_EQ(ctx
.count
, 2);
1623 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1624 pthread_kill(emitter
, SIGUSR1
);
1625 pthread_join(emitter
, NULL
);
1646 struct epoll_event e
;
1647 struct epoll_mtcontext ctx
= { 0 };
1649 signal(SIGUSR1
, signal_handler
);
1651 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1653 ctx
.efd
[0] = epoll_create(1);
1654 ASSERT_GE(ctx
.efd
[0], 0);
1656 ctx
.efd
[1] = epoll_create(1);
1657 ASSERT_GE(ctx
.efd
[1], 0);
1659 e
.events
= EPOLLIN
| EPOLLET
;
1660 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1663 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1665 ctx
.main
= pthread_self();
1666 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1o
, &ctx
), 0);
1667 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1669 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
1670 __sync_fetch_and_or(&ctx
.count
, 2);
1672 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1673 EXPECT_TRUE((ctx
.count
== 2) || (ctx
.count
== 3));
1675 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1676 pthread_kill(emitter
, SIGUSR1
);
1677 pthread_join(emitter
, NULL
);
1698 struct epoll_event e
;
1699 struct epoll_mtcontext ctx
= { 0 };
1701 signal(SIGUSR1
, signal_handler
);
1703 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1705 ctx
.efd
[0] = epoll_create(1);
1706 ASSERT_GE(ctx
.efd
[0], 0);
1708 ctx
.efd
[1] = epoll_create(1);
1709 ASSERT_GE(ctx
.efd
[1], 0);
1712 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1714 e
.events
= EPOLLIN
| EPOLLET
;
1715 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1717 ctx
.main
= pthread_self();
1718 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
1719 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1721 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
1722 __sync_fetch_and_add(&ctx
.count
, 1);
1724 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1725 EXPECT_EQ(ctx
.count
, 2);
1727 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1728 pthread_kill(emitter
, SIGUSR1
);
1729 pthread_join(emitter
, NULL
);
1750 struct epoll_event e
;
1751 struct epoll_mtcontext ctx
= { 0 };
1753 signal(SIGUSR1
, signal_handler
);
1755 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1757 ctx
.efd
[0] = epoll_create(1);
1758 ASSERT_GE(ctx
.efd
[0], 0);
1760 ctx
.efd
[1] = epoll_create(1);
1761 ASSERT_GE(ctx
.efd
[1], 0);
1763 e
.events
= EPOLLIN
| EPOLLET
;
1764 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1766 e
.events
= EPOLLIN
| EPOLLET
;
1767 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1769 ctx
.main
= pthread_self();
1770 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1o
, &ctx
), 0);
1771 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1773 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
1774 __sync_fetch_and_or(&ctx
.count
, 2);
1776 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1777 EXPECT_TRUE((ctx
.count
== 2) || (ctx
.count
== 3));
1779 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1780 pthread_kill(emitter
, SIGUSR1
);
1781 pthread_join(emitter
, NULL
);
1803 struct epoll_event e
;
1804 struct epoll_mtcontext ctx
= { 0 };
1806 signal(SIGUSR1
, signal_handler
);
1808 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1810 ctx
.efd
[0] = epoll_create(1);
1811 ASSERT_GE(ctx
.efd
[0], 0);
1813 ctx
.efd
[1] = epoll_create(1);
1814 ASSERT_GE(ctx
.efd
[1], 0);
1817 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1820 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1822 ctx
.main
= pthread_self();
1823 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
1824 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1826 pfd
.fd
= ctx
.efd
[1];
1827 pfd
.events
= POLLIN
;
1828 if (poll(&pfd
, 1, -1) > 0) {
1829 if (epoll_wait(ctx
.efd
[1], &e
, 1, 0) > 0)
1830 __sync_fetch_and_add(&ctx
.count
, 1);
1833 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1834 EXPECT_EQ(ctx
.count
, 2);
1836 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1837 pthread_kill(emitter
, SIGUSR1
);
1838 pthread_join(emitter
, NULL
);
1860 struct epoll_event e
;
1861 struct epoll_mtcontext ctx
= { 0 };
1863 signal(SIGUSR1
, signal_handler
);
1865 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1867 ctx
.efd
[0] = epoll_create(1);
1868 ASSERT_GE(ctx
.efd
[0], 0);
1870 ctx
.efd
[1] = epoll_create(1);
1871 ASSERT_GE(ctx
.efd
[1], 0);
1873 e
.events
= EPOLLIN
| EPOLLET
;
1874 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1877 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1879 ctx
.main
= pthread_self();
1880 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1o
, &ctx
), 0);
1881 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1883 pfd
.fd
= ctx
.efd
[1];
1884 pfd
.events
= POLLIN
;
1885 if (poll(&pfd
, 1, -1) > 0) {
1886 if (epoll_wait(ctx
.efd
[1], &e
, 1, 0) > 0)
1887 __sync_fetch_and_or(&ctx
.count
, 2);
1890 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1891 EXPECT_TRUE((ctx
.count
== 2) || (ctx
.count
== 3));
1893 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1894 pthread_kill(emitter
, SIGUSR1
);
1895 pthread_join(emitter
, NULL
);
1917 struct epoll_event e
;
1918 struct epoll_mtcontext ctx
= { 0 };
1920 signal(SIGUSR1
, signal_handler
);
1922 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1924 ctx
.efd
[0] = epoll_create(1);
1925 ASSERT_GE(ctx
.efd
[0], 0);
1927 ctx
.efd
[1] = epoll_create(1);
1928 ASSERT_GE(ctx
.efd
[1], 0);
1931 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1933 e
.events
= EPOLLIN
| EPOLLET
;
1934 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1936 ctx
.main
= pthread_self();
1937 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
1938 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1940 pfd
.fd
= ctx
.efd
[1];
1941 pfd
.events
= POLLIN
;
1942 if (poll(&pfd
, 1, -1) > 0) {
1943 if (epoll_wait(ctx
.efd
[1], &e
, 1, 0) > 0)
1944 __sync_fetch_and_add(&ctx
.count
, 1);
1947 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
1948 EXPECT_EQ(ctx
.count
, 2);
1950 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
1951 pthread_kill(emitter
, SIGUSR1
);
1952 pthread_join(emitter
, NULL
);
1974 struct epoll_event e
;
1975 struct epoll_mtcontext ctx
= { 0 };
1977 signal(SIGUSR1
, signal_handler
);
1979 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
1981 ctx
.efd
[0] = epoll_create(1);
1982 ASSERT_GE(ctx
.efd
[0], 0);
1984 ctx
.efd
[1] = epoll_create(1);
1985 ASSERT_GE(ctx
.efd
[1], 0);
1987 e
.events
= EPOLLIN
| EPOLLET
;
1988 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
1990 e
.events
= EPOLLIN
| EPOLLET
;
1991 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
1993 ctx
.main
= pthread_self();
1994 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1o
, &ctx
), 0);
1995 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
1997 pfd
.fd
= ctx
.efd
[1];
1998 pfd
.events
= POLLIN
;
1999 if (poll(&pfd
, 1, -1) > 0) {
2000 if (epoll_wait(ctx
.efd
[1], &e
, 1, 0) > 0)
2001 __sync_fetch_and_or(&ctx
.count
, 2);
2004 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2005 EXPECT_TRUE((ctx
.count
== 2) || (ctx
.count
== 3));
2007 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2008 pthread_kill(emitter
, SIGUSR1
);
2009 pthread_join(emitter
, NULL
);
2030 struct epoll_event e
;
2031 struct epoll_mtcontext ctx
= { 0 };
2033 signal(SIGUSR1
, signal_handler
);
2035 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
2037 ctx
.efd
[0] = epoll_create(1);
2038 ASSERT_GE(ctx
.efd
[0], 0);
2040 ctx
.efd
[1] = epoll_create(1);
2041 ASSERT_GE(ctx
.efd
[1], 0);
2044 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2047 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2049 ctx
.main
= pthread_self();
2050 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
2051 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
2053 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
2054 __sync_fetch_and_add(&ctx
.count
, 1);
2056 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2057 EXPECT_EQ(ctx
.count
, 2);
2059 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2060 pthread_kill(emitter
, SIGUSR1
);
2061 pthread_join(emitter
, NULL
);
2082 struct epoll_event e
;
2083 struct epoll_mtcontext ctx
= { 0 };
2085 signal(SIGUSR1
, signal_handler
);
2087 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
2089 ctx
.efd
[0] = epoll_create(1);
2090 ASSERT_GE(ctx
.efd
[0], 0);
2092 ctx
.efd
[1] = epoll_create(1);
2093 ASSERT_GE(ctx
.efd
[1], 0);
2095 e
.events
= EPOLLIN
| EPOLLET
;
2096 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2099 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2101 ctx
.main
= pthread_self();
2102 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1op
, &ctx
), 0);
2103 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
2105 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
2106 __sync_fetch_and_or(&ctx
.count
, 2);
2108 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2109 EXPECT_TRUE((ctx
.count
== 2) || (ctx
.count
== 3));
2111 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2112 pthread_kill(emitter
, SIGUSR1
);
2113 pthread_join(emitter
, NULL
);
2134 struct epoll_event e
;
2135 struct epoll_mtcontext ctx
= { 0 };
2137 signal(SIGUSR1
, signal_handler
);
2139 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
2141 ctx
.efd
[0] = epoll_create(1);
2142 ASSERT_GE(ctx
.efd
[0], 0);
2144 ctx
.efd
[1] = epoll_create(1);
2145 ASSERT_GE(ctx
.efd
[1], 0);
2148 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2150 e
.events
= EPOLLIN
| EPOLLET
;
2151 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2153 ctx
.main
= pthread_self();
2154 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
2155 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
2157 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
2158 __sync_fetch_and_add(&ctx
.count
, 1);
2160 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2161 EXPECT_EQ(ctx
.count
, 2);
2163 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2164 pthread_kill(emitter
, SIGUSR1
);
2165 pthread_join(emitter
, NULL
);
2186 struct epoll_event e
;
2187 struct epoll_mtcontext ctx
= { 0 };
2189 signal(SIGUSR1
, signal_handler
);
2191 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
2193 ctx
.efd
[0] = epoll_create(1);
2194 ASSERT_GE(ctx
.efd
[0], 0);
2196 ctx
.efd
[1] = epoll_create(1);
2197 ASSERT_GE(ctx
.efd
[1], 0);
2199 e
.events
= EPOLLIN
| EPOLLET
;
2200 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2202 e
.events
= EPOLLIN
| EPOLLET
;
2203 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2205 ctx
.main
= pthread_self();
2206 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1op
, &ctx
), 0);
2207 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
2209 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
2210 __sync_fetch_and_or(&ctx
.count
, 2);
2212 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2213 EXPECT_TRUE((ctx
.count
== 2) || (ctx
.count
== 3));
2215 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2216 pthread_kill(emitter
, SIGUSR1
);
2217 pthread_join(emitter
, NULL
);
2239 struct epoll_event e
;
2240 struct epoll_mtcontext ctx
= { 0 };
2242 signal(SIGUSR1
, signal_handler
);
2244 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
2246 ctx
.efd
[0] = epoll_create(1);
2247 ASSERT_GE(ctx
.efd
[0], 0);
2249 ctx
.efd
[1] = epoll_create(1);
2250 ASSERT_GE(ctx
.efd
[1], 0);
2253 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2256 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2258 ctx
.main
= pthread_self();
2259 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
2260 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
2262 pfd
.fd
= ctx
.efd
[1];
2263 pfd
.events
= POLLIN
;
2264 if (poll(&pfd
, 1, -1) > 0) {
2265 if (epoll_wait(ctx
.efd
[1], &e
, 1, 0) > 0)
2266 __sync_fetch_and_add(&ctx
.count
, 1);
2269 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2270 EXPECT_EQ(ctx
.count
, 2);
2272 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2273 pthread_kill(emitter
, SIGUSR1
);
2274 pthread_join(emitter
, NULL
);
2295 struct epoll_event e
;
2296 struct epoll_mtcontext ctx
= { 0 };
2298 signal(SIGUSR1
, signal_handler
);
2300 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
2302 ctx
.efd
[0] = epoll_create(1);
2303 ASSERT_GE(ctx
.efd
[0], 0);
2305 ctx
.efd
[1] = epoll_create(1);
2306 ASSERT_GE(ctx
.efd
[1], 0);
2308 e
.events
= EPOLLIN
| EPOLLET
;
2309 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2312 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2314 ctx
.main
= pthread_self();
2315 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1op
, &ctx
), 0);
2316 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
2318 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
2319 __sync_fetch_and_or(&ctx
.count
, 2);
2321 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2322 EXPECT_TRUE((ctx
.count
== 2) || (ctx
.count
== 3));
2324 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2325 pthread_kill(emitter
, SIGUSR1
);
2326 pthread_join(emitter
, NULL
);
2348 struct epoll_event e
;
2349 struct epoll_mtcontext ctx
= { 0 };
2351 signal(SIGUSR1
, signal_handler
);
2353 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
2355 ctx
.efd
[0] = epoll_create(1);
2356 ASSERT_GE(ctx
.efd
[0], 0);
2358 ctx
.efd
[1] = epoll_create(1);
2359 ASSERT_GE(ctx
.efd
[1], 0);
2362 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2364 e
.events
= EPOLLIN
| EPOLLET
;
2365 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2367 ctx
.main
= pthread_self();
2368 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
2369 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
2371 pfd
.fd
= ctx
.efd
[1];
2372 pfd
.events
= POLLIN
;
2373 if (poll(&pfd
, 1, -1) > 0) {
2374 if (epoll_wait(ctx
.efd
[1], &e
, 1, 0) > 0)
2375 __sync_fetch_and_add(&ctx
.count
, 1);
2378 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2379 EXPECT_EQ(ctx
.count
, 2);
2381 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2382 pthread_kill(emitter
, SIGUSR1
);
2383 pthread_join(emitter
, NULL
);
2404 struct epoll_event e
;
2405 struct epoll_mtcontext ctx
= { 0 };
2407 signal(SIGUSR1
, signal_handler
);
2409 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctx
.sfd
), 0);
2411 ctx
.efd
[0] = epoll_create(1);
2412 ASSERT_GE(ctx
.efd
[0], 0);
2414 ctx
.efd
[1] = epoll_create(1);
2415 ASSERT_GE(ctx
.efd
[1], 0);
2417 e
.events
= EPOLLIN
| EPOLLET
;
2418 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2420 e
.events
= EPOLLIN
| EPOLLET
;
2421 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2423 ctx
.main
= pthread_self();
2424 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1op
, &ctx
), 0);
2425 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry1
, &ctx
), 0);
2427 if (epoll_wait(ctx
.efd
[1], &e
, 1, -1) > 0)
2428 __sync_fetch_and_or(&ctx
.count
, 2);
2430 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2431 EXPECT_TRUE((ctx
.count
== 2) || (ctx
.count
== 3));
2433 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2434 pthread_kill(emitter
, SIGUSR1
);
2435 pthread_join(emitter
, NULL
);
2457 struct epoll_event events
[2];
2459 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
2460 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[2]), 0);
2462 efd
[0] = epoll_create(1);
2463 ASSERT_GE(efd
[0], 0);
2465 efd
[1] = epoll_create(1);
2466 ASSERT_GE(efd
[1], 0);
2468 efd
[2] = epoll_create(1);
2469 ASSERT_GE(efd
[2], 0);
2471 events
[0].events
= EPOLLIN
;
2472 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], events
), 0);
2474 events
[0].events
= EPOLLIN
;
2475 ASSERT_EQ(epoll_ctl(efd
[2], EPOLL_CTL_ADD
, sfd
[2], events
), 0);
2477 events
[0].events
= EPOLLIN
;
2478 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], events
), 0);
2480 events
[0].events
= EPOLLIN
;
2481 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[2], events
), 0);
2483 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
2484 ASSERT_EQ(write(sfd
[3], "w", 1), 1);
2486 EXPECT_EQ(epoll_wait(efd
[0], events
, 2, 0), 2);
2487 EXPECT_EQ(epoll_wait(efd
[0], events
, 2, 0), 2);
2511 struct epoll_event events
[2];
2513 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
2514 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[2]), 0);
2516 efd
[0] = epoll_create(1);
2517 ASSERT_GE(efd
[0], 0);
2519 efd
[1] = epoll_create(1);
2520 ASSERT_GE(efd
[1], 0);
2522 efd
[2] = epoll_create(1);
2523 ASSERT_GE(efd
[2], 0);
2525 events
[0].events
= EPOLLIN
;
2526 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], events
), 0);
2528 events
[0].events
= EPOLLIN
;
2529 ASSERT_EQ(epoll_ctl(efd
[2], EPOLL_CTL_ADD
, sfd
[2], events
), 0);
2531 events
[0].events
= EPOLLIN
| EPOLLET
;
2532 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], events
), 0);
2534 events
[0].events
= EPOLLIN
| EPOLLET
;
2535 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[2], events
), 0);
2537 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
2538 ASSERT_EQ(write(sfd
[3], "w", 1), 1);
2540 EXPECT_EQ(epoll_wait(efd
[0], events
, 2, 0), 2);
2541 EXPECT_EQ(epoll_wait(efd
[0], events
, 2, 0), 0);
2566 struct epoll_event events
[2];
2568 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
2569 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[2]), 0);
2571 efd
[0] = epoll_create(1);
2572 ASSERT_GE(efd
[0], 0);
2574 efd
[1] = epoll_create(1);
2575 ASSERT_GE(efd
[1], 0);
2577 efd
[2] = epoll_create(1);
2578 ASSERT_GE(efd
[2], 0);
2580 events
[0].events
= EPOLLIN
;
2581 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], events
), 0);
2583 events
[0].events
= EPOLLIN
;
2584 ASSERT_EQ(epoll_ctl(efd
[2], EPOLL_CTL_ADD
, sfd
[2], events
), 0);
2586 events
[0].events
= EPOLLIN
;
2587 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], events
), 0);
2589 events
[0].events
= EPOLLIN
;
2590 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[2], events
), 0);
2592 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
2593 ASSERT_EQ(write(sfd
[3], "w", 1), 1);
2596 pfd
.events
= POLLIN
;
2597 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
2598 EXPECT_EQ(epoll_wait(efd
[0], events
, 2, 0), 2);
2601 pfd
.events
= POLLIN
;
2602 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
2603 EXPECT_EQ(epoll_wait(efd
[0], events
, 2, 0), 2);
2628 struct epoll_event events
[2];
2630 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[0]), 0);
2631 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &sfd
[2]), 0);
2633 efd
[0] = epoll_create(1);
2634 ASSERT_GE(efd
[0], 0);
2636 efd
[1] = epoll_create(1);
2637 ASSERT_GE(efd
[1], 0);
2639 efd
[2] = epoll_create(1);
2640 ASSERT_GE(efd
[2], 0);
2642 events
[0].events
= EPOLLIN
;
2643 ASSERT_EQ(epoll_ctl(efd
[1], EPOLL_CTL_ADD
, sfd
[0], events
), 0);
2645 events
[0].events
= EPOLLIN
;
2646 ASSERT_EQ(epoll_ctl(efd
[2], EPOLL_CTL_ADD
, sfd
[2], events
), 0);
2648 events
[0].events
= EPOLLIN
| EPOLLET
;
2649 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[1], events
), 0);
2651 events
[0].events
= EPOLLIN
| EPOLLET
;
2652 ASSERT_EQ(epoll_ctl(efd
[0], EPOLL_CTL_ADD
, efd
[2], events
), 0);
2654 ASSERT_EQ(write(sfd
[1], "w", 1), 1);
2655 ASSERT_EQ(write(sfd
[3], "w", 1), 1);
2658 pfd
.events
= POLLIN
;
2659 EXPECT_EQ(poll(&pfd
, 1, 0), 1);
2660 EXPECT_EQ(epoll_wait(efd
[0], events
, 2, 0), 2);
2663 pfd
.events
= POLLIN
;
2664 EXPECT_EQ(poll(&pfd
, 1, 0), 0);
2665 EXPECT_EQ(epoll_wait(efd
[0], events
, 2, 0), 0);
2688 struct epoll_event e
;
2689 struct epoll_mtcontext ctx
= { 0 };
2691 signal(SIGUSR1
, signal_handler
);
2693 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
2694 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
2696 ctx
.efd
[0] = epoll_create(1);
2697 ASSERT_GE(ctx
.efd
[0], 0);
2699 ctx
.efd
[1] = epoll_create(1);
2700 ASSERT_GE(ctx
.efd
[1], 0);
2702 ctx
.efd
[2] = epoll_create(1);
2703 ASSERT_GE(ctx
.efd
[2], 0);
2706 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2709 ASSERT_EQ(epoll_ctl(ctx
.efd
[2], EPOLL_CTL_ADD
, ctx
.sfd
[2], &e
), 0);
2712 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2715 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[2], &e
), 0);
2717 ctx
.main
= pthread_self();
2718 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
2719 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
2721 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
2722 __sync_fetch_and_add(&ctx
.count
, 1);
2724 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2725 EXPECT_EQ(ctx
.count
, 2);
2727 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2728 pthread_kill(emitter
, SIGUSR1
);
2729 pthread_join(emitter
, NULL
);
2753 struct epoll_event e
;
2754 struct epoll_mtcontext ctx
= { 0 };
2756 signal(SIGUSR1
, signal_handler
);
2758 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
2759 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
2761 ctx
.efd
[0] = epoll_create(1);
2762 ASSERT_GE(ctx
.efd
[0], 0);
2764 ctx
.efd
[1] = epoll_create(1);
2765 ASSERT_GE(ctx
.efd
[1], 0);
2767 ctx
.efd
[2] = epoll_create(1);
2768 ASSERT_GE(ctx
.efd
[2], 0);
2771 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2774 ASSERT_EQ(epoll_ctl(ctx
.efd
[2], EPOLL_CTL_ADD
, ctx
.sfd
[2], &e
), 0);
2776 e
.events
= EPOLLIN
| EPOLLET
;
2777 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2779 e
.events
= EPOLLIN
| EPOLLET
;
2780 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[2], &e
), 0);
2782 ctx
.main
= pthread_self();
2783 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1a
, &ctx
), 0);
2784 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
2786 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
2787 __sync_fetch_and_add(&ctx
.count
, 1);
2789 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2790 EXPECT_EQ(ctx
.count
, 2);
2792 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2793 pthread_kill(emitter
, SIGUSR1
);
2794 pthread_join(emitter
, NULL
);
2818 struct epoll_event e
;
2819 struct epoll_mtcontext ctx
= { 0 };
2821 signal(SIGUSR1
, signal_handler
);
2823 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
2824 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
2826 ctx
.efd
[0] = epoll_create(1);
2827 ASSERT_GE(ctx
.efd
[0], 0);
2829 ctx
.efd
[1] = epoll_create(1);
2830 ASSERT_GE(ctx
.efd
[1], 0);
2832 ctx
.efd
[2] = epoll_create(1);
2833 ASSERT_GE(ctx
.efd
[2], 0);
2836 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2839 ASSERT_EQ(epoll_ctl(ctx
.efd
[2], EPOLL_CTL_ADD
, ctx
.sfd
[2], &e
), 0);
2842 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2845 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[2], &e
), 0);
2847 ctx
.main
= pthread_self();
2848 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
2849 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
2851 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
2852 __sync_fetch_and_add(&ctx
.count
, 1);
2854 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2855 EXPECT_EQ(ctx
.count
, 2);
2857 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2858 pthread_kill(emitter
, SIGUSR1
);
2859 pthread_join(emitter
, NULL
);
2883 struct epoll_event e
;
2884 struct epoll_mtcontext ctx
= { 0 };
2886 signal(SIGUSR1
, signal_handler
);
2888 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
2889 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
2891 ctx
.efd
[0] = epoll_create(1);
2892 ASSERT_GE(ctx
.efd
[0], 0);
2894 ctx
.efd
[1] = epoll_create(1);
2895 ASSERT_GE(ctx
.efd
[1], 0);
2897 ctx
.efd
[2] = epoll_create(1);
2898 ASSERT_GE(ctx
.efd
[2], 0);
2901 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2904 ASSERT_EQ(epoll_ctl(ctx
.efd
[2], EPOLL_CTL_ADD
, ctx
.sfd
[2], &e
), 0);
2906 e
.events
= EPOLLIN
| EPOLLET
;
2907 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2909 e
.events
= EPOLLIN
| EPOLLET
;
2910 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[2], &e
), 0);
2912 ctx
.main
= pthread_self();
2913 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
2914 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
2916 if (epoll_wait(ctx
.efd
[0], &e
, 1, -1) > 0)
2917 __sync_fetch_and_add(&ctx
.count
, 1);
2919 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2920 EXPECT_EQ(ctx
.count
, 2);
2922 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2923 pthread_kill(emitter
, SIGUSR1
);
2924 pthread_join(emitter
, NULL
);
2949 struct epoll_event e
;
2950 struct epoll_mtcontext ctx
= { 0 };
2952 signal(SIGUSR1
, signal_handler
);
2954 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
2955 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
2957 ctx
.efd
[0] = epoll_create(1);
2958 ASSERT_GE(ctx
.efd
[0], 0);
2960 ctx
.efd
[1] = epoll_create(1);
2961 ASSERT_GE(ctx
.efd
[1], 0);
2963 ctx
.efd
[2] = epoll_create(1);
2964 ASSERT_GE(ctx
.efd
[2], 0);
2967 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
2970 ASSERT_EQ(epoll_ctl(ctx
.efd
[2], EPOLL_CTL_ADD
, ctx
.sfd
[2], &e
), 0);
2973 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
2976 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[2], &e
), 0);
2978 ctx
.main
= pthread_self();
2979 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
2980 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
2982 pfd
.fd
= ctx
.efd
[0];
2983 pfd
.events
= POLLIN
;
2984 if (poll(&pfd
, 1, -1) > 0) {
2985 if (epoll_wait(ctx
.efd
[0], &e
, 1, 0) > 0)
2986 __sync_fetch_and_add(&ctx
.count
, 1);
2989 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
2990 EXPECT_EQ(ctx
.count
, 2);
2992 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
2993 pthread_kill(emitter
, SIGUSR1
);
2994 pthread_join(emitter
, NULL
);
3019 struct epoll_event e
;
3020 struct epoll_mtcontext ctx
= { 0 };
3022 signal(SIGUSR1
, signal_handler
);
3024 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[0]), 0);
3025 ASSERT_EQ(socketpair(AF_UNIX
, SOCK_STREAM
, 0, &ctx
.sfd
[2]), 0);
3027 ctx
.efd
[0] = epoll_create(1);
3028 ASSERT_GE(ctx
.efd
[0], 0);
3030 ctx
.efd
[1] = epoll_create(1);
3031 ASSERT_GE(ctx
.efd
[1], 0);
3033 ctx
.efd
[2] = epoll_create(1);
3034 ASSERT_GE(ctx
.efd
[2], 0);
3037 ASSERT_EQ(epoll_ctl(ctx
.efd
[1], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
3040 ASSERT_EQ(epoll_ctl(ctx
.efd
[2], EPOLL_CTL_ADD
, ctx
.sfd
[2], &e
), 0);
3042 e
.events
= EPOLLIN
| EPOLLET
;
3043 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[1], &e
), 0);
3045 e
.events
= EPOLLIN
| EPOLLET
;
3046 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.efd
[2], &e
), 0);
3048 ctx
.main
= pthread_self();
3049 ASSERT_EQ(pthread_create(&ctx
.waiter
, NULL
, waiter_entry1ap
, &ctx
), 0);
3050 ASSERT_EQ(pthread_create(&emitter
, NULL
, emitter_entry2
, &ctx
), 0);
3052 pfd
.fd
= ctx
.efd
[0];
3053 pfd
.events
= POLLIN
;
3054 if (poll(&pfd
, 1, -1) > 0) {
3055 if (epoll_wait(ctx
.efd
[0], &e
, 1, 0) > 0)
3056 __sync_fetch_and_add(&ctx
.count
, 1);
3059 ASSERT_EQ(pthread_join(ctx
.waiter
, NULL
), 0);
3060 EXPECT_EQ(ctx
.count
, 2);
3062 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
3063 pthread_kill(emitter
, SIGUSR1
);
3064 pthread_join(emitter
, NULL
);
3076 static void *epoll59_thread(void *ctx_
)
3078 struct epoll_mtcontext
*ctx
= ctx_
;
3079 struct epoll_event e
;
3082 for (i
= 0; i
< 100000; i
++) {
3083 while (ctx
->count
== 0)
3086 e
.events
= EPOLLIN
| EPOLLERR
| EPOLLET
;
3087 epoll_ctl(ctx
->efd
[0], EPOLL_CTL_MOD
, ctx
->sfd
[0], &e
);
3101 * Based on https://bugzilla.kernel.org/show_bug.cgi?id=205933
3107 struct epoll_event e
;
3108 struct epoll_mtcontext ctx
= { 0 };
3111 signal(SIGUSR1
, signal_handler
);
3113 ctx
.efd
[0] = epoll_create1(0);
3114 ASSERT_GE(ctx
.efd
[0], 0);
3116 ctx
.sfd
[0] = eventfd(1, 0);
3117 ASSERT_GE(ctx
.sfd
[0], 0);
3119 e
.events
= EPOLLIN
| EPOLLERR
| EPOLLET
;
3120 ASSERT_EQ(epoll_ctl(ctx
.efd
[0], EPOLL_CTL_ADD
, ctx
.sfd
[0], &e
), 0);
3122 ASSERT_EQ(pthread_create(&emitter
, NULL
, epoll59_thread
, &ctx
), 0);
3124 for (i
= 0; i
< 100000; i
++) {
3125 ret
= epoll_wait(ctx
.efd
[0], &e
, 1, 1000);
3128 while (ctx
.count
!= 0)
3132 if (pthread_tryjoin_np(emitter
, NULL
) < 0) {
3133 pthread_kill(emitter
, SIGUSR1
);
3134 pthread_join(emitter
, NULL
);
3141 EPOLL60_EVENTS_NR
= 10,
3144 struct epoll60_ctx
{
3145 volatile int stopped
;
3149 int evfd
[EPOLL60_EVENTS_NR
];
3152 static void *epoll60_wait_thread(void *ctx_
)
3154 struct epoll60_ctx
*ctx
= ctx_
;
3155 struct epoll_event e
;
3161 sigemptyset(&sigmask
);
3162 sigaddset(&sigmask
, SIGUSR1
);
3163 sigprocmask(SIG_SETMASK
, &sigmask
, NULL
);
3165 /* Prepare empty mask for epoll_pwait() */
3166 sigemptyset(&sigmask
);
3168 while (!ctx
->stopped
) {
3169 /* Mark we are ready */
3170 __atomic_fetch_add(&ctx
->ready
, 1, __ATOMIC_ACQUIRE
);
3172 /* Start when all are ready */
3173 while (__atomic_load_n(&ctx
->ready
, __ATOMIC_ACQUIRE
) &&
3176 /* Account this waiter */
3177 __atomic_fetch_add(&ctx
->waiters
, 1, __ATOMIC_ACQUIRE
);
3179 ret
= epoll_pwait(ctx
->epfd
, &e
, 1, 2000, &sigmask
);
3181 /* We expect only signal delivery on stop */
3182 assert(ret
< 0 && errno
== EINTR
&& "Lost wakeup!\n");
3183 assert(ctx
->stopped
);
3187 ret
= read(e
.data
.fd
, &v
, sizeof(v
));
3188 /* Since we are on ET mode, thus each thread gets its own fd. */
3189 assert(ret
== sizeof(v
));
3191 __atomic_fetch_sub(&ctx
->waiters
, 1, __ATOMIC_RELEASE
);
3197 static inline unsigned long long msecs(void)
3200 unsigned long long msecs
;
3202 clock_gettime(CLOCK_REALTIME
, &ts
);
3203 msecs
= ts
.tv_sec
* 1000ull;
3204 msecs
+= ts
.tv_nsec
/ 1000000ull;
3209 static inline int count_waiters(struct epoll60_ctx
*ctx
)
3211 return __atomic_load_n(&ctx
->waiters
, __ATOMIC_ACQUIRE
);
3216 struct epoll60_ctx ctx
= { 0 };
3217 pthread_t waiters
[ARRAY_SIZE(ctx
.evfd
)];
3218 struct epoll_event e
;
3221 signal(SIGUSR1
, signal_handler
);
3223 ctx
.epfd
= epoll_create1(0);
3224 ASSERT_GE(ctx
.epfd
, 0);
3226 /* Create event fds */
3227 for (i
= 0; i
< ARRAY_SIZE(ctx
.evfd
); i
++) {
3228 ctx
.evfd
[i
] = eventfd(0, EFD_NONBLOCK
);
3229 ASSERT_GE(ctx
.evfd
[i
], 0);
3231 e
.events
= EPOLLIN
| EPOLLET
;
3232 e
.data
.fd
= ctx
.evfd
[i
];
3233 ASSERT_EQ(epoll_ctl(ctx
.epfd
, EPOLL_CTL_ADD
, ctx
.evfd
[i
], &e
), 0);
3236 /* Create waiter threads */
3237 for (i
= 0; i
< ARRAY_SIZE(waiters
); i
++)
3238 ASSERT_EQ(pthread_create(&waiters
[i
], NULL
,
3239 epoll60_wait_thread
, &ctx
), 0);
3241 for (i
= 0; i
< 300; i
++) {
3244 /* Wait for all to be ready */
3245 while (__atomic_load_n(&ctx
.ready
, __ATOMIC_ACQUIRE
) !=
3246 ARRAY_SIZE(ctx
.evfd
))
3250 __atomic_fetch_sub(&ctx
.ready
, ARRAY_SIZE(ctx
.evfd
),
3253 /* Wait all have gone to kernel */
3254 while (count_waiters(&ctx
) != ARRAY_SIZE(ctx
.evfd
))
3257 /* 1ms should be enough to schedule away */
3260 /* Quickly signal all handles at once */
3261 for (n
= 0; n
< ARRAY_SIZE(ctx
.evfd
); n
++) {
3262 ret
= write(ctx
.evfd
[n
], &v
, sizeof(v
));
3263 ASSERT_EQ(ret
, sizeof(v
));
3266 /* Busy loop for 1s and wait for all waiters to wake up */
3268 while (count_waiters(&ctx
) && msecs() < ms
+ 1000)
3271 ASSERT_EQ(count_waiters(&ctx
), 0);
3275 for (i
= 0; i
< ARRAY_SIZE(waiters
); i
++)
3276 ret
= pthread_kill(waiters
[i
], SIGUSR1
);
3277 for (i
= 0; i
< ARRAY_SIZE(waiters
); i
++)
3278 pthread_join(waiters
[i
], NULL
);
3280 for (i
= 0; i
< ARRAY_SIZE(waiters
); i
++)