1 // SPDX-License-Identifier: GPL-2.0
9 #include <sys/socket.h>
10 #include "../../kselftest_harness.h"
12 struct epoll_mtcontext
22 static void signal_handler(int signum)
26 static void kill_timeout(struct epoll_mtcontext *ctx)
29 pthread_kill(ctx->main, SIGUSR1);
30 pthread_kill(ctx->waiter, SIGUSR1);
33 static void *waiter_entry1a(void *data)
36 struct epoll_mtcontext *ctx = data;
38 if (epoll_wait(ctx->efd[0], &e, 1, -1) > 0)
39 __sync_fetch_and_add(&ctx->count, 1);
44 static void *waiter_entry1ap(void *data)
48 struct epoll_mtcontext *ctx = data;
52 if (poll(&pfd, 1, -1) > 0) {
53 if (epoll_wait(ctx->efd[0], &e, 1, 0) > 0)
54 __sync_fetch_and_add(&ctx->count, 1);
60 static void *waiter_entry1o(void *data)
63 struct epoll_mtcontext *ctx = data;
65 if (epoll_wait(ctx->efd[0], &e, 1, -1) > 0)
66 __sync_fetch_and_or(&ctx->count, 1);
71 static void *waiter_entry1op(void *data)
75 struct epoll_mtcontext *ctx = data;
79 if (poll(&pfd, 1, -1) > 0) {
80 if (epoll_wait(ctx->efd[0], &e, 1, 0) > 0)
81 __sync_fetch_and_or(&ctx->count, 1);
87 static void *waiter_entry2a(void *data)
89 struct epoll_event events[2];
90 struct epoll_mtcontext *ctx = data;
92 if (epoll_wait(ctx->efd[0], events, 2, -1) > 0)
93 __sync_fetch_and_add(&ctx->count, 1);
98 static void *waiter_entry2ap(void *data)
101 struct epoll_event events[2];
102 struct epoll_mtcontext *ctx = data;
104 pfd.fd = ctx->efd[0];
106 if (poll(&pfd, 1, -1) > 0) {
107 if (epoll_wait(ctx->efd[0], events, 2, 0) > 0)
108 __sync_fetch_and_add(&ctx->count, 1);
114 static void *emitter_entry1(void *data)
116 struct epoll_mtcontext *ctx = data;
119 write(ctx->sfd[1], "w", 1);
126 static void *emitter_entry2(void *data)
128 struct epoll_mtcontext *ctx = data;
131 write(ctx->sfd[1], "w", 1);
132 write(ctx->sfd[3], "w", 1);
150 struct epoll_event e;
152 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
154 efd = epoll_create(1);
158 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e), 0);
160 ASSERT_EQ(write(sfd[1], "w", 1), 1);
162 EXPECT_EQ(epoll_wait(efd, &e, 1, 0), 1);
163 EXPECT_EQ(epoll_wait(efd, &e, 1, 0), 1);
181 struct epoll_event e;
183 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
185 efd = epoll_create(1);
188 e.events = EPOLLIN | EPOLLET;
189 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e), 0);
191 ASSERT_EQ(write(sfd[1], "w", 1), 1);
193 EXPECT_EQ(epoll_wait(efd, &e, 1, 0), 1);
194 EXPECT_EQ(epoll_wait(efd, &e, 1, 0), 0);
212 struct epoll_event events[2];
214 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
215 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[2]), 0);
217 efd = epoll_create(1);
220 events[0].events = EPOLLIN;
221 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], events), 0);
223 events[0].events = EPOLLIN;
224 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[2], events), 0);
226 ASSERT_EQ(write(sfd[1], "w", 1), 1);
227 ASSERT_EQ(write(sfd[3], "w", 1), 1);
229 EXPECT_EQ(epoll_wait(efd, events, 2, 0), 2);
230 EXPECT_EQ(epoll_wait(efd, events, 2, 0), 2);
250 struct epoll_event events[2];
252 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
253 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[2]), 0);
255 efd = epoll_create(1);
258 events[0].events = EPOLLIN | EPOLLET;
259 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], events), 0);
261 events[0].events = EPOLLIN | EPOLLET;
262 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[2], events), 0);
264 ASSERT_EQ(write(sfd[1], "w", 1), 1);
265 ASSERT_EQ(write(sfd[3], "w", 1), 1);
267 EXPECT_EQ(epoll_wait(efd, events, 2, 0), 2);
268 EXPECT_EQ(epoll_wait(efd, events, 2, 0), 0);
289 struct epoll_event e;
291 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
293 efd = epoll_create(1);
297 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e), 0);
299 ASSERT_EQ(write(sfd[1], "w", 1), 1);
303 ASSERT_EQ(poll(&pfd, 1, 0), 1);
304 ASSERT_EQ(epoll_wait(efd, &e, 1, 0), 1);
308 ASSERT_EQ(poll(&pfd, 1, 0), 1);
309 ASSERT_EQ(epoll_wait(efd, &e, 1, 0), 1);
328 struct epoll_event e;
330 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
332 efd = epoll_create(1);
335 e.events = EPOLLIN | EPOLLET;
336 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e), 0);
338 ASSERT_EQ(write(sfd[1], "w", 1), 1);
342 ASSERT_EQ(poll(&pfd, 1, 0), 1);
343 ASSERT_EQ(epoll_wait(efd, &e, 1, 0), 1);
347 ASSERT_EQ(poll(&pfd, 1, 0), 0);
348 ASSERT_EQ(epoll_wait(efd, &e, 1, 0), 0);
368 struct epoll_event events[2];
370 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
371 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[2]), 0);
373 efd = epoll_create(1);
376 events[0].events = EPOLLIN;
377 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], events), 0);
379 events[0].events = EPOLLIN;
380 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[2], events), 0);
382 ASSERT_EQ(write(sfd[1], "w", 1), 1);
383 ASSERT_EQ(write(sfd[3], "w", 1), 1);
387 EXPECT_EQ(poll(&pfd, 1, 0), 1);
388 EXPECT_EQ(epoll_wait(efd, events, 2, 0), 2);
392 EXPECT_EQ(poll(&pfd, 1, 0), 1);
393 EXPECT_EQ(epoll_wait(efd, events, 2, 0), 2);
414 struct epoll_event events[2];
416 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
417 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[2]), 0);
419 efd = epoll_create(1);
422 events[0].events = EPOLLIN | EPOLLET;
423 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], events), 0);
425 events[0].events = EPOLLIN | EPOLLET;
426 ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[2], events), 0);
428 ASSERT_EQ(write(sfd[1], "w", 1), 1);
429 ASSERT_EQ(write(sfd[3], "w", 1), 1);
433 EXPECT_EQ(poll(&pfd, 1, 0), 1);
434 EXPECT_EQ(epoll_wait(efd, events, 2, 0), 2);
438 EXPECT_EQ(poll(&pfd, 1, 0), 0);
439 EXPECT_EQ(epoll_wait(efd, events, 2, 0), 0);
458 struct epoll_event e;
459 struct epoll_mtcontext ctx = { 0 };
461 signal(SIGUSR1, signal_handler);
463 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
465 ctx.efd[0] = epoll_create(1);
466 ASSERT_GE(ctx.efd[0], 0);
469 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
471 ctx.main = pthread_self();
472 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
473 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
475 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
476 __sync_fetch_and_add(&ctx.count, 1);
478 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
479 EXPECT_EQ(ctx.count, 2);
481 if (pthread_tryjoin_np(emitter, NULL) < 0) {
482 pthread_kill(emitter, SIGUSR1);
483 pthread_join(emitter, NULL);
501 struct epoll_event e;
502 struct epoll_mtcontext ctx = { 0 };
504 signal(SIGUSR1, signal_handler);
506 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
508 ctx.efd[0] = epoll_create(1);
509 ASSERT_GE(ctx.efd[0], 0);
511 e.events = EPOLLIN | EPOLLET;
512 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
514 ctx.main = pthread_self();
515 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
516 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
518 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
519 __sync_fetch_and_add(&ctx.count, 1);
521 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
522 EXPECT_EQ(ctx.count, 1);
524 if (pthread_tryjoin_np(emitter, NULL) < 0) {
525 pthread_kill(emitter, SIGUSR1);
526 pthread_join(emitter, NULL);
544 struct epoll_event events[2];
545 struct epoll_mtcontext ctx = { 0 };
547 signal(SIGUSR1, signal_handler);
549 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
550 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
552 ctx.efd[0] = epoll_create(1);
553 ASSERT_GE(ctx.efd[0], 0);
555 events[0].events = EPOLLIN;
556 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[0], events), 0);
558 events[0].events = EPOLLIN;
559 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[2], events), 0);
561 ctx.main = pthread_self();
562 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry2a, &ctx), 0);
563 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
565 if (epoll_wait(ctx.efd[0], events, 2, -1) > 0)
566 __sync_fetch_and_add(&ctx.count, 1);
568 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
569 EXPECT_EQ(ctx.count, 2);
571 if (pthread_tryjoin_np(emitter, NULL) < 0) {
572 pthread_kill(emitter, SIGUSR1);
573 pthread_join(emitter, NULL);
593 struct epoll_event events[2];
594 struct epoll_mtcontext ctx = { 0 };
596 signal(SIGUSR1, signal_handler);
598 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
599 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
601 ctx.efd[0] = epoll_create(1);
602 ASSERT_GE(ctx.efd[0], 0);
604 events[0].events = EPOLLIN | EPOLLET;
605 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[0], events), 0);
607 events[0].events = EPOLLIN | EPOLLET;
608 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[2], events), 0);
610 ctx.main = pthread_self();
611 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
612 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
614 if (epoll_wait(ctx.efd[0], events, 1, -1) > 0)
615 __sync_fetch_and_add(&ctx.count, 1);
617 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
618 EXPECT_EQ(ctx.count, 2);
620 if (pthread_tryjoin_np(emitter, NULL) < 0) {
621 pthread_kill(emitter, SIGUSR1);
622 pthread_join(emitter, NULL);
642 struct epoll_event e;
643 struct epoll_mtcontext ctx = { 0 };
645 signal(SIGUSR1, signal_handler);
647 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
649 ctx.efd[0] = epoll_create(1);
650 ASSERT_GE(ctx.efd[0], 0);
653 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
655 ctx.main = pthread_self();
656 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
657 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
659 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
660 __sync_fetch_and_add(&ctx.count, 1);
662 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
663 EXPECT_EQ(ctx.count, 2);
665 if (pthread_tryjoin_np(emitter, NULL) < 0) {
666 pthread_kill(emitter, SIGUSR1);
667 pthread_join(emitter, NULL);
685 struct epoll_event e;
686 struct epoll_mtcontext ctx = { 0 };
688 signal(SIGUSR1, signal_handler);
690 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
692 ctx.efd[0] = epoll_create(1);
693 ASSERT_GE(ctx.efd[0], 0);
695 e.events = EPOLLIN | EPOLLET;
696 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
698 ctx.main = pthread_self();
699 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
700 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
702 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
703 __sync_fetch_and_add(&ctx.count, 1);
705 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
706 EXPECT_EQ(ctx.count, 1);
708 if (pthread_tryjoin_np(emitter, NULL) < 0) {
709 pthread_kill(emitter, SIGUSR1);
710 pthread_join(emitter, NULL);
728 struct epoll_event events[2];
729 struct epoll_mtcontext ctx = { 0 };
731 signal(SIGUSR1, signal_handler);
733 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
734 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
736 ctx.efd[0] = epoll_create(1);
737 ASSERT_GE(ctx.efd[0], 0);
739 events[0].events = EPOLLIN;
740 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[0], events), 0);
742 events[0].events = EPOLLIN;
743 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[2], events), 0);
745 ctx.main = pthread_self();
746 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry2ap, &ctx), 0);
747 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
749 if (epoll_wait(ctx.efd[0], events, 2, -1) > 0)
750 __sync_fetch_and_add(&ctx.count, 1);
752 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
753 EXPECT_EQ(ctx.count, 2);
755 if (pthread_tryjoin_np(emitter, NULL) < 0) {
756 pthread_kill(emitter, SIGUSR1);
757 pthread_join(emitter, NULL);
777 struct epoll_event events[2];
778 struct epoll_mtcontext ctx = { 0 };
780 signal(SIGUSR1, signal_handler);
782 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
783 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
785 ctx.efd[0] = epoll_create(1);
786 ASSERT_GE(ctx.efd[0], 0);
788 events[0].events = EPOLLIN | EPOLLET;
789 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[0], events), 0);
791 events[0].events = EPOLLIN | EPOLLET;
792 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.sfd[2], events), 0);
794 ctx.main = pthread_self();
795 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
796 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
798 if (epoll_wait(ctx.efd[0], events, 1, -1) > 0)
799 __sync_fetch_and_add(&ctx.count, 1);
801 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
802 EXPECT_EQ(ctx.count, 2);
804 if (pthread_tryjoin_np(emitter, NULL) < 0) {
805 pthread_kill(emitter, SIGUSR1);
806 pthread_join(emitter, NULL);
829 struct epoll_event e;
831 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
833 efd[0] = epoll_create(1);
834 ASSERT_GE(efd[0], 0);
836 efd[1] = epoll_create(1);
837 ASSERT_GE(efd[1], 0);
840 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], &e), 0);
843 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], &e), 0);
845 ASSERT_EQ(write(sfd[1], "w", 1), 1);
847 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
848 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
869 struct epoll_event e;
871 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
873 efd[0] = epoll_create(1);
874 ASSERT_GE(efd[0], 0);
876 efd[1] = epoll_create(1);
877 ASSERT_GE(efd[1], 0);
879 e.events = EPOLLIN | EPOLLET;
880 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], &e), 0);
883 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], &e), 0);
885 ASSERT_EQ(write(sfd[1], "w", 1), 1);
887 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
888 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
909 struct epoll_event e;
911 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
913 efd[0] = epoll_create(1);
914 ASSERT_GE(efd[0], 0);
916 efd[1] = epoll_create(1);
917 ASSERT_GE(efd[1], 0);
920 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], &e), 0);
922 e.events = EPOLLIN | EPOLLET;
923 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], &e), 0);
925 ASSERT_EQ(write(sfd[1], "w", 1), 1);
927 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
928 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 0);
949 struct epoll_event e;
951 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
953 efd[0] = epoll_create(1);
954 ASSERT_GE(efd[0], 0);
956 efd[1] = epoll_create(1);
957 ASSERT_GE(efd[1], 0);
959 e.events = EPOLLIN | EPOLLET;
960 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], &e), 0);
962 e.events = EPOLLIN | EPOLLET;
963 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], &e), 0);
965 ASSERT_EQ(write(sfd[1], "w", 1), 1);
967 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
968 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 0);
990 struct epoll_event e;
992 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
994 efd[0] = epoll_create(1);
995 ASSERT_GE(efd[0], 0);
997 efd[1] = epoll_create(1);
998 ASSERT_GE(efd[1], 0);
1001 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], &e), 0);
1004 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], &e), 0);
1006 ASSERT_EQ(write(sfd[1], "w", 1), 1);
1009 pfd.events = POLLIN;
1010 EXPECT_EQ(poll(&pfd, 1, 0), 1);
1011 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
1014 pfd.events = POLLIN;
1015 EXPECT_EQ(poll(&pfd, 1, 0), 1);
1016 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
1038 struct epoll_event e;
1040 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
1042 efd[0] = epoll_create(1);
1043 ASSERT_GE(efd[0], 0);
1045 efd[1] = epoll_create(1);
1046 ASSERT_GE(efd[1], 0);
1048 e.events = EPOLLIN | EPOLLET;
1049 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], &e), 0);
1052 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], &e), 0);
1054 ASSERT_EQ(write(sfd[1], "w", 1), 1);
1057 pfd.events = POLLIN;
1058 EXPECT_EQ(poll(&pfd, 1, 0), 1);
1059 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
1062 pfd.events = POLLIN;
1063 EXPECT_EQ(poll(&pfd, 1, 0), 1);
1064 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
1086 struct epoll_event e;
1088 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
1090 efd[0] = epoll_create(1);
1091 ASSERT_GE(efd[0], 0);
1093 efd[1] = epoll_create(1);
1094 ASSERT_GE(efd[1], 0);
1097 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], &e), 0);
1099 e.events = EPOLLIN | EPOLLET;
1100 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], &e), 0);
1102 ASSERT_EQ(write(sfd[1], "w", 1), 1);
1105 pfd.events = POLLIN;
1106 EXPECT_EQ(poll(&pfd, 1, 0), 1);
1107 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
1110 pfd.events = POLLIN;
1111 EXPECT_EQ(poll(&pfd, 1, 0), 0);
1112 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 0);
1134 struct epoll_event e;
1136 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
1138 efd[0] = epoll_create(1);
1139 ASSERT_GE(efd[0], 0);
1141 efd[1] = epoll_create(1);
1142 ASSERT_GE(efd[1], 0);
1144 e.events = EPOLLIN | EPOLLET;
1145 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], &e), 0);
1147 e.events = EPOLLIN | EPOLLET;
1148 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], &e), 0);
1150 ASSERT_EQ(write(sfd[1], "w", 1), 1);
1153 pfd.events = POLLIN;
1154 EXPECT_EQ(poll(&pfd, 1, 0), 1);
1155 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 1);
1158 pfd.events = POLLIN;
1159 EXPECT_EQ(poll(&pfd, 1, 0), 0);
1160 EXPECT_EQ(epoll_wait(efd[0], &e, 1, 0), 0);
1180 struct epoll_event e;
1181 struct epoll_mtcontext ctx = { 0 };
1183 signal(SIGUSR1, signal_handler);
1185 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1187 ctx.efd[0] = epoll_create(1);
1188 ASSERT_GE(ctx.efd[0], 0);
1190 ctx.efd[1] = epoll_create(1);
1191 ASSERT_GE(ctx.efd[1], 0);
1194 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1197 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1199 ctx.main = pthread_self();
1200 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
1201 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1203 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
1204 __sync_fetch_and_add(&ctx.count, 1);
1206 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1207 EXPECT_EQ(ctx.count, 2);
1209 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1210 pthread_kill(emitter, SIGUSR1);
1211 pthread_join(emitter, NULL);
1232 struct epoll_event e;
1233 struct epoll_mtcontext ctx = { 0 };
1235 signal(SIGUSR1, signal_handler);
1237 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1239 ctx.efd[0] = epoll_create(1);
1240 ASSERT_GE(ctx.efd[0], 0);
1242 ctx.efd[1] = epoll_create(1);
1243 ASSERT_GE(ctx.efd[1], 0);
1245 e.events = EPOLLIN | EPOLLET;
1246 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1249 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1251 ctx.main = pthread_self();
1252 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
1253 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1255 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
1256 __sync_fetch_and_add(&ctx.count, 1);
1258 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1259 EXPECT_EQ(ctx.count, 2);
1261 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1262 pthread_kill(emitter, SIGUSR1);
1263 pthread_join(emitter, NULL);
1284 struct epoll_event e;
1285 struct epoll_mtcontext ctx = { 0 };
1287 signal(SIGUSR1, signal_handler);
1289 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1291 ctx.efd[0] = epoll_create(1);
1292 ASSERT_GE(ctx.efd[0], 0);
1294 ctx.efd[1] = epoll_create(1);
1295 ASSERT_GE(ctx.efd[1], 0);
1298 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1300 e.events = EPOLLIN | EPOLLET;
1301 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1303 ctx.main = pthread_self();
1304 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
1305 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1307 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
1308 __sync_fetch_and_add(&ctx.count, 1);
1310 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1311 EXPECT_EQ(ctx.count, 1);
1313 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1314 pthread_kill(emitter, SIGUSR1);
1315 pthread_join(emitter, NULL);
1336 struct epoll_event e;
1337 struct epoll_mtcontext ctx = { 0 };
1339 signal(SIGUSR1, signal_handler);
1341 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1343 ctx.efd[0] = epoll_create(1);
1344 ASSERT_GE(ctx.efd[0], 0);
1346 ctx.efd[1] = epoll_create(1);
1347 ASSERT_GE(ctx.efd[1], 0);
1349 e.events = EPOLLIN | EPOLLET;
1350 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1352 e.events = EPOLLIN | EPOLLET;
1353 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1355 ctx.main = pthread_self();
1356 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
1357 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1359 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
1360 __sync_fetch_and_add(&ctx.count, 1);
1362 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1363 EXPECT_EQ(ctx.count, 1);
1365 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1366 pthread_kill(emitter, SIGUSR1);
1367 pthread_join(emitter, NULL);
1388 struct epoll_event e;
1389 struct epoll_mtcontext ctx = { 0 };
1391 signal(SIGUSR1, signal_handler);
1393 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1395 ctx.efd[0] = epoll_create(1);
1396 ASSERT_GE(ctx.efd[0], 0);
1398 ctx.efd[1] = epoll_create(1);
1399 ASSERT_GE(ctx.efd[1], 0);
1402 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1405 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1407 ctx.main = pthread_self();
1408 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
1409 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1411 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
1412 __sync_fetch_and_add(&ctx.count, 1);
1414 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1415 EXPECT_EQ(ctx.count, 2);
1417 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1418 pthread_kill(emitter, SIGUSR1);
1419 pthread_join(emitter, NULL);
1439 struct epoll_event e;
1440 struct epoll_mtcontext ctx = { 0 };
1442 signal(SIGUSR1, signal_handler);
1444 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1446 ctx.efd[0] = epoll_create(1);
1447 ASSERT_GE(ctx.efd[0], 0);
1449 ctx.efd[1] = epoll_create(1);
1450 ASSERT_GE(ctx.efd[1], 0);
1452 e.events = EPOLLIN | EPOLLET;
1453 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1456 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1458 ctx.main = pthread_self();
1459 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
1460 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1462 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
1463 __sync_fetch_and_add(&ctx.count, 1);
1465 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1466 EXPECT_EQ(ctx.count, 2);
1468 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1469 pthread_kill(emitter, SIGUSR1);
1470 pthread_join(emitter, NULL);
1490 struct epoll_event e;
1491 struct epoll_mtcontext ctx = { 0 };
1493 signal(SIGUSR1, signal_handler);
1495 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1497 ctx.efd[0] = epoll_create(1);
1498 ASSERT_GE(ctx.efd[0], 0);
1500 ctx.efd[1] = epoll_create(1);
1501 ASSERT_GE(ctx.efd[1], 0);
1504 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1506 e.events = EPOLLIN | EPOLLET;
1507 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1509 ctx.main = pthread_self();
1510 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
1511 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1513 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
1514 __sync_fetch_and_add(&ctx.count, 1);
1516 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1517 EXPECT_EQ(ctx.count, 1);
1519 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1520 pthread_kill(emitter, SIGUSR1);
1521 pthread_join(emitter, NULL);
1541 struct epoll_event e;
1542 struct epoll_mtcontext ctx = { 0 };
1544 signal(SIGUSR1, signal_handler);
1546 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1548 ctx.efd[0] = epoll_create(1);
1549 ASSERT_GE(ctx.efd[0], 0);
1551 ctx.efd[1] = epoll_create(1);
1552 ASSERT_GE(ctx.efd[1], 0);
1554 e.events = EPOLLIN | EPOLLET;
1555 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1557 e.events = EPOLLIN | EPOLLET;
1558 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1560 ctx.main = pthread_self();
1561 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
1562 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1564 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
1565 __sync_fetch_and_add(&ctx.count, 1);
1567 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1568 EXPECT_EQ(ctx.count, 1);
1570 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1571 pthread_kill(emitter, SIGUSR1);
1572 pthread_join(emitter, NULL);
1592 struct epoll_event e;
1593 struct epoll_mtcontext ctx = { 0 };
1595 signal(SIGUSR1, signal_handler);
1597 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1599 ctx.efd[0] = epoll_create(1);
1600 ASSERT_GE(ctx.efd[0], 0);
1602 ctx.efd[1] = epoll_create(1);
1603 ASSERT_GE(ctx.efd[1], 0);
1606 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1609 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1611 ctx.main = pthread_self();
1612 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
1613 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1615 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
1616 __sync_fetch_and_add(&ctx.count, 1);
1618 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1619 EXPECT_EQ(ctx.count, 2);
1621 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1622 pthread_kill(emitter, SIGUSR1);
1623 pthread_join(emitter, NULL);
1644 struct epoll_event e;
1645 struct epoll_mtcontext ctx = { 0 };
1647 signal(SIGUSR1, signal_handler);
1649 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1651 ctx.efd[0] = epoll_create(1);
1652 ASSERT_GE(ctx.efd[0], 0);
1654 ctx.efd[1] = epoll_create(1);
1655 ASSERT_GE(ctx.efd[1], 0);
1657 e.events = EPOLLIN | EPOLLET;
1658 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1661 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1663 ctx.main = pthread_self();
1664 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1o, &ctx), 0);
1665 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1667 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
1668 __sync_fetch_and_or(&ctx.count, 2);
1670 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1671 EXPECT_TRUE((ctx.count == 2) || (ctx.count == 3));
1673 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1674 pthread_kill(emitter, SIGUSR1);
1675 pthread_join(emitter, NULL);
1696 struct epoll_event e;
1697 struct epoll_mtcontext ctx = { 0 };
1699 signal(SIGUSR1, signal_handler);
1701 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1703 ctx.efd[0] = epoll_create(1);
1704 ASSERT_GE(ctx.efd[0], 0);
1706 ctx.efd[1] = epoll_create(1);
1707 ASSERT_GE(ctx.efd[1], 0);
1710 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1712 e.events = EPOLLIN | EPOLLET;
1713 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1715 ctx.main = pthread_self();
1716 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
1717 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1719 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
1720 __sync_fetch_and_add(&ctx.count, 1);
1722 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1723 EXPECT_EQ(ctx.count, 2);
1725 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1726 pthread_kill(emitter, SIGUSR1);
1727 pthread_join(emitter, NULL);
1748 struct epoll_event e;
1749 struct epoll_mtcontext ctx = { 0 };
1751 signal(SIGUSR1, signal_handler);
1753 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1755 ctx.efd[0] = epoll_create(1);
1756 ASSERT_GE(ctx.efd[0], 0);
1758 ctx.efd[1] = epoll_create(1);
1759 ASSERT_GE(ctx.efd[1], 0);
1761 e.events = EPOLLIN | EPOLLET;
1762 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1764 e.events = EPOLLIN | EPOLLET;
1765 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1767 ctx.main = pthread_self();
1768 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1o, &ctx), 0);
1769 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1771 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
1772 __sync_fetch_and_or(&ctx.count, 2);
1774 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1775 EXPECT_TRUE((ctx.count == 2) || (ctx.count == 3));
1777 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1778 pthread_kill(emitter, SIGUSR1);
1779 pthread_join(emitter, NULL);
1801 struct epoll_event e;
1802 struct epoll_mtcontext ctx = { 0 };
1804 signal(SIGUSR1, signal_handler);
1806 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1808 ctx.efd[0] = epoll_create(1);
1809 ASSERT_GE(ctx.efd[0], 0);
1811 ctx.efd[1] = epoll_create(1);
1812 ASSERT_GE(ctx.efd[1], 0);
1815 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1818 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1820 ctx.main = pthread_self();
1821 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
1822 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1824 pfd.fd = ctx.efd[1];
1825 pfd.events = POLLIN;
1826 if (poll(&pfd, 1, -1) > 0) {
1827 if (epoll_wait(ctx.efd[1], &e, 1, 0) > 0)
1828 __sync_fetch_and_add(&ctx.count, 1);
1831 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1832 EXPECT_EQ(ctx.count, 2);
1834 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1835 pthread_kill(emitter, SIGUSR1);
1836 pthread_join(emitter, NULL);
1858 struct epoll_event e;
1859 struct epoll_mtcontext ctx = { 0 };
1861 signal(SIGUSR1, signal_handler);
1863 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1865 ctx.efd[0] = epoll_create(1);
1866 ASSERT_GE(ctx.efd[0], 0);
1868 ctx.efd[1] = epoll_create(1);
1869 ASSERT_GE(ctx.efd[1], 0);
1871 e.events = EPOLLIN | EPOLLET;
1872 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1875 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1877 ctx.main = pthread_self();
1878 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1o, &ctx), 0);
1879 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1881 pfd.fd = ctx.efd[1];
1882 pfd.events = POLLIN;
1883 if (poll(&pfd, 1, -1) > 0) {
1884 if (epoll_wait(ctx.efd[1], &e, 1, 0) > 0)
1885 __sync_fetch_and_or(&ctx.count, 2);
1888 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1889 EXPECT_TRUE((ctx.count == 2) || (ctx.count == 3));
1891 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1892 pthread_kill(emitter, SIGUSR1);
1893 pthread_join(emitter, NULL);
1915 struct epoll_event e;
1916 struct epoll_mtcontext ctx = { 0 };
1918 signal(SIGUSR1, signal_handler);
1920 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1922 ctx.efd[0] = epoll_create(1);
1923 ASSERT_GE(ctx.efd[0], 0);
1925 ctx.efd[1] = epoll_create(1);
1926 ASSERT_GE(ctx.efd[1], 0);
1929 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1931 e.events = EPOLLIN | EPOLLET;
1932 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1934 ctx.main = pthread_self();
1935 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
1936 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1938 pfd.fd = ctx.efd[1];
1939 pfd.events = POLLIN;
1940 if (poll(&pfd, 1, -1) > 0) {
1941 if (epoll_wait(ctx.efd[1], &e, 1, 0) > 0)
1942 __sync_fetch_and_add(&ctx.count, 1);
1945 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
1946 EXPECT_EQ(ctx.count, 2);
1948 if (pthread_tryjoin_np(emitter, NULL) < 0) {
1949 pthread_kill(emitter, SIGUSR1);
1950 pthread_join(emitter, NULL);
1972 struct epoll_event e;
1973 struct epoll_mtcontext ctx = { 0 };
1975 signal(SIGUSR1, signal_handler);
1977 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
1979 ctx.efd[0] = epoll_create(1);
1980 ASSERT_GE(ctx.efd[0], 0);
1982 ctx.efd[1] = epoll_create(1);
1983 ASSERT_GE(ctx.efd[1], 0);
1985 e.events = EPOLLIN | EPOLLET;
1986 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
1988 e.events = EPOLLIN | EPOLLET;
1989 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
1991 ctx.main = pthread_self();
1992 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1o, &ctx), 0);
1993 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
1995 pfd.fd = ctx.efd[1];
1996 pfd.events = POLLIN;
1997 if (poll(&pfd, 1, -1) > 0) {
1998 if (epoll_wait(ctx.efd[1], &e, 1, 0) > 0)
1999 __sync_fetch_and_or(&ctx.count, 2);
2002 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2003 EXPECT_TRUE((ctx.count == 2) || (ctx.count == 3));
2005 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2006 pthread_kill(emitter, SIGUSR1);
2007 pthread_join(emitter, NULL);
2028 struct epoll_event e;
2029 struct epoll_mtcontext ctx = { 0 };
2031 signal(SIGUSR1, signal_handler);
2033 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
2035 ctx.efd[0] = epoll_create(1);
2036 ASSERT_GE(ctx.efd[0], 0);
2038 ctx.efd[1] = epoll_create(1);
2039 ASSERT_GE(ctx.efd[1], 0);
2042 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2045 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2047 ctx.main = pthread_self();
2048 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
2049 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
2051 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
2052 __sync_fetch_and_add(&ctx.count, 1);
2054 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2055 EXPECT_EQ(ctx.count, 2);
2057 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2058 pthread_kill(emitter, SIGUSR1);
2059 pthread_join(emitter, NULL);
2080 struct epoll_event e;
2081 struct epoll_mtcontext ctx = { 0 };
2083 signal(SIGUSR1, signal_handler);
2085 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
2087 ctx.efd[0] = epoll_create(1);
2088 ASSERT_GE(ctx.efd[0], 0);
2090 ctx.efd[1] = epoll_create(1);
2091 ASSERT_GE(ctx.efd[1], 0);
2093 e.events = EPOLLIN | EPOLLET;
2094 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2097 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2099 ctx.main = pthread_self();
2100 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1op, &ctx), 0);
2101 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
2103 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
2104 __sync_fetch_and_or(&ctx.count, 2);
2106 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2107 EXPECT_TRUE((ctx.count == 2) || (ctx.count == 3));
2109 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2110 pthread_kill(emitter, SIGUSR1);
2111 pthread_join(emitter, NULL);
2132 struct epoll_event e;
2133 struct epoll_mtcontext ctx = { 0 };
2135 signal(SIGUSR1, signal_handler);
2137 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
2139 ctx.efd[0] = epoll_create(1);
2140 ASSERT_GE(ctx.efd[0], 0);
2142 ctx.efd[1] = epoll_create(1);
2143 ASSERT_GE(ctx.efd[1], 0);
2146 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2148 e.events = EPOLLIN | EPOLLET;
2149 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2151 ctx.main = pthread_self();
2152 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
2153 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
2155 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
2156 __sync_fetch_and_add(&ctx.count, 1);
2158 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2159 EXPECT_EQ(ctx.count, 2);
2161 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2162 pthread_kill(emitter, SIGUSR1);
2163 pthread_join(emitter, NULL);
2184 struct epoll_event e;
2185 struct epoll_mtcontext ctx = { 0 };
2187 signal(SIGUSR1, signal_handler);
2189 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
2191 ctx.efd[0] = epoll_create(1);
2192 ASSERT_GE(ctx.efd[0], 0);
2194 ctx.efd[1] = epoll_create(1);
2195 ASSERT_GE(ctx.efd[1], 0);
2197 e.events = EPOLLIN | EPOLLET;
2198 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2200 e.events = EPOLLIN | EPOLLET;
2201 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2203 ctx.main = pthread_self();
2204 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1op, &ctx), 0);
2205 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
2207 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
2208 __sync_fetch_and_or(&ctx.count, 2);
2210 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2211 EXPECT_TRUE((ctx.count == 2) || (ctx.count == 3));
2213 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2214 pthread_kill(emitter, SIGUSR1);
2215 pthread_join(emitter, NULL);
2237 struct epoll_event e;
2238 struct epoll_mtcontext ctx = { 0 };
2240 signal(SIGUSR1, signal_handler);
2242 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
2244 ctx.efd[0] = epoll_create(1);
2245 ASSERT_GE(ctx.efd[0], 0);
2247 ctx.efd[1] = epoll_create(1);
2248 ASSERT_GE(ctx.efd[1], 0);
2251 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2254 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2256 ctx.main = pthread_self();
2257 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
2258 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
2260 pfd.fd = ctx.efd[1];
2261 pfd.events = POLLIN;
2262 if (poll(&pfd, 1, -1) > 0) {
2263 if (epoll_wait(ctx.efd[1], &e, 1, 0) > 0)
2264 __sync_fetch_and_add(&ctx.count, 1);
2267 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2268 EXPECT_EQ(ctx.count, 2);
2270 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2271 pthread_kill(emitter, SIGUSR1);
2272 pthread_join(emitter, NULL);
2293 struct epoll_event e;
2294 struct epoll_mtcontext ctx = { 0 };
2296 signal(SIGUSR1, signal_handler);
2298 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
2300 ctx.efd[0] = epoll_create(1);
2301 ASSERT_GE(ctx.efd[0], 0);
2303 ctx.efd[1] = epoll_create(1);
2304 ASSERT_GE(ctx.efd[1], 0);
2306 e.events = EPOLLIN | EPOLLET;
2307 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2310 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2312 ctx.main = pthread_self();
2313 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1op, &ctx), 0);
2314 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
2316 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
2317 __sync_fetch_and_or(&ctx.count, 2);
2319 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2320 EXPECT_TRUE((ctx.count == 2) || (ctx.count == 3));
2322 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2323 pthread_kill(emitter, SIGUSR1);
2324 pthread_join(emitter, NULL);
2346 struct epoll_event e;
2347 struct epoll_mtcontext ctx = { 0 };
2349 signal(SIGUSR1, signal_handler);
2351 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
2353 ctx.efd[0] = epoll_create(1);
2354 ASSERT_GE(ctx.efd[0], 0);
2356 ctx.efd[1] = epoll_create(1);
2357 ASSERT_GE(ctx.efd[1], 0);
2360 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2362 e.events = EPOLLIN | EPOLLET;
2363 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2365 ctx.main = pthread_self();
2366 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
2367 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
2369 pfd.fd = ctx.efd[1];
2370 pfd.events = POLLIN;
2371 if (poll(&pfd, 1, -1) > 0) {
2372 if (epoll_wait(ctx.efd[1], &e, 1, 0) > 0)
2373 __sync_fetch_and_add(&ctx.count, 1);
2376 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2377 EXPECT_EQ(ctx.count, 2);
2379 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2380 pthread_kill(emitter, SIGUSR1);
2381 pthread_join(emitter, NULL);
2402 struct epoll_event e;
2403 struct epoll_mtcontext ctx = { 0 };
2405 signal(SIGUSR1, signal_handler);
2407 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, ctx.sfd), 0);
2409 ctx.efd[0] = epoll_create(1);
2410 ASSERT_GE(ctx.efd[0], 0);
2412 ctx.efd[1] = epoll_create(1);
2413 ASSERT_GE(ctx.efd[1], 0);
2415 e.events = EPOLLIN | EPOLLET;
2416 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2418 e.events = EPOLLIN | EPOLLET;
2419 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2421 ctx.main = pthread_self();
2422 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1op, &ctx), 0);
2423 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry1, &ctx), 0);
2425 if (epoll_wait(ctx.efd[1], &e, 1, -1) > 0)
2426 __sync_fetch_and_or(&ctx.count, 2);
2428 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2429 EXPECT_TRUE((ctx.count == 2) || (ctx.count == 3));
2431 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2432 pthread_kill(emitter, SIGUSR1);
2433 pthread_join(emitter, NULL);
2455 struct epoll_event events[2];
2457 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
2458 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[2]), 0);
2460 efd[0] = epoll_create(1);
2461 ASSERT_GE(efd[0], 0);
2463 efd[1] = epoll_create(1);
2464 ASSERT_GE(efd[1], 0);
2466 efd[2] = epoll_create(1);
2467 ASSERT_GE(efd[2], 0);
2469 events[0].events = EPOLLIN;
2470 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], events), 0);
2472 events[0].events = EPOLLIN;
2473 ASSERT_EQ(epoll_ctl(efd[2], EPOLL_CTL_ADD, sfd[2], events), 0);
2475 events[0].events = EPOLLIN;
2476 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], events), 0);
2478 events[0].events = EPOLLIN;
2479 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[2], events), 0);
2481 ASSERT_EQ(write(sfd[1], "w", 1), 1);
2482 ASSERT_EQ(write(sfd[3], "w", 1), 1);
2484 EXPECT_EQ(epoll_wait(efd[0], events, 2, 0), 2);
2485 EXPECT_EQ(epoll_wait(efd[0], events, 2, 0), 2);
2509 struct epoll_event events[2];
2511 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
2512 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[2]), 0);
2514 efd[0] = epoll_create(1);
2515 ASSERT_GE(efd[0], 0);
2517 efd[1] = epoll_create(1);
2518 ASSERT_GE(efd[1], 0);
2520 efd[2] = epoll_create(1);
2521 ASSERT_GE(efd[2], 0);
2523 events[0].events = EPOLLIN;
2524 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], events), 0);
2526 events[0].events = EPOLLIN;
2527 ASSERT_EQ(epoll_ctl(efd[2], EPOLL_CTL_ADD, sfd[2], events), 0);
2529 events[0].events = EPOLLIN | EPOLLET;
2530 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], events), 0);
2532 events[0].events = EPOLLIN | EPOLLET;
2533 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[2], events), 0);
2535 ASSERT_EQ(write(sfd[1], "w", 1), 1);
2536 ASSERT_EQ(write(sfd[3], "w", 1), 1);
2538 EXPECT_EQ(epoll_wait(efd[0], events, 2, 0), 2);
2539 EXPECT_EQ(epoll_wait(efd[0], events, 2, 0), 0);
2564 struct epoll_event events[2];
2566 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
2567 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[2]), 0);
2569 efd[0] = epoll_create(1);
2570 ASSERT_GE(efd[0], 0);
2572 efd[1] = epoll_create(1);
2573 ASSERT_GE(efd[1], 0);
2575 efd[2] = epoll_create(1);
2576 ASSERT_GE(efd[2], 0);
2578 events[0].events = EPOLLIN;
2579 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], events), 0);
2581 events[0].events = EPOLLIN;
2582 ASSERT_EQ(epoll_ctl(efd[2], EPOLL_CTL_ADD, sfd[2], events), 0);
2584 events[0].events = EPOLLIN;
2585 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], events), 0);
2587 events[0].events = EPOLLIN;
2588 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[2], events), 0);
2590 ASSERT_EQ(write(sfd[1], "w", 1), 1);
2591 ASSERT_EQ(write(sfd[3], "w", 1), 1);
2594 pfd.events = POLLIN;
2595 EXPECT_EQ(poll(&pfd, 1, 0), 1);
2596 EXPECT_EQ(epoll_wait(efd[0], events, 2, 0), 2);
2599 pfd.events = POLLIN;
2600 EXPECT_EQ(poll(&pfd, 1, 0), 1);
2601 EXPECT_EQ(epoll_wait(efd[0], events, 2, 0), 2);
2626 struct epoll_event events[2];
2628 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[0]), 0);
2629 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &sfd[2]), 0);
2631 efd[0] = epoll_create(1);
2632 ASSERT_GE(efd[0], 0);
2634 efd[1] = epoll_create(1);
2635 ASSERT_GE(efd[1], 0);
2637 efd[2] = epoll_create(1);
2638 ASSERT_GE(efd[2], 0);
2640 events[0].events = EPOLLIN;
2641 ASSERT_EQ(epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], events), 0);
2643 events[0].events = EPOLLIN;
2644 ASSERT_EQ(epoll_ctl(efd[2], EPOLL_CTL_ADD, sfd[2], events), 0);
2646 events[0].events = EPOLLIN | EPOLLET;
2647 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], events), 0);
2649 events[0].events = EPOLLIN | EPOLLET;
2650 ASSERT_EQ(epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[2], events), 0);
2652 ASSERT_EQ(write(sfd[1], "w", 1), 1);
2653 ASSERT_EQ(write(sfd[3], "w", 1), 1);
2656 pfd.events = POLLIN;
2657 EXPECT_EQ(poll(&pfd, 1, 0), 1);
2658 EXPECT_EQ(epoll_wait(efd[0], events, 2, 0), 2);
2661 pfd.events = POLLIN;
2662 EXPECT_EQ(poll(&pfd, 1, 0), 0);
2663 EXPECT_EQ(epoll_wait(efd[0], events, 2, 0), 0);
2686 struct epoll_event e;
2687 struct epoll_mtcontext ctx = { 0 };
2689 signal(SIGUSR1, signal_handler);
2691 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
2692 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
2694 ctx.efd[0] = epoll_create(1);
2695 ASSERT_GE(ctx.efd[0], 0);
2697 ctx.efd[1] = epoll_create(1);
2698 ASSERT_GE(ctx.efd[1], 0);
2700 ctx.efd[2] = epoll_create(1);
2701 ASSERT_GE(ctx.efd[2], 0);
2704 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2707 ASSERT_EQ(epoll_ctl(ctx.efd[2], EPOLL_CTL_ADD, ctx.sfd[2], &e), 0);
2710 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2713 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[2], &e), 0);
2715 ctx.main = pthread_self();
2716 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
2717 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
2719 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
2720 __sync_fetch_and_add(&ctx.count, 1);
2722 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2723 EXPECT_EQ(ctx.count, 2);
2725 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2726 pthread_kill(emitter, SIGUSR1);
2727 pthread_join(emitter, NULL);
2751 struct epoll_event e;
2752 struct epoll_mtcontext ctx = { 0 };
2754 signal(SIGUSR1, signal_handler);
2756 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
2757 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
2759 ctx.efd[0] = epoll_create(1);
2760 ASSERT_GE(ctx.efd[0], 0);
2762 ctx.efd[1] = epoll_create(1);
2763 ASSERT_GE(ctx.efd[1], 0);
2765 ctx.efd[2] = epoll_create(1);
2766 ASSERT_GE(ctx.efd[2], 0);
2769 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2772 ASSERT_EQ(epoll_ctl(ctx.efd[2], EPOLL_CTL_ADD, ctx.sfd[2], &e), 0);
2774 e.events = EPOLLIN | EPOLLET;
2775 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2777 e.events = EPOLLIN | EPOLLET;
2778 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[2], &e), 0);
2780 ctx.main = pthread_self();
2781 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1a, &ctx), 0);
2782 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
2784 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
2785 __sync_fetch_and_add(&ctx.count, 1);
2787 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2788 EXPECT_EQ(ctx.count, 2);
2790 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2791 pthread_kill(emitter, SIGUSR1);
2792 pthread_join(emitter, NULL);
2816 struct epoll_event e;
2817 struct epoll_mtcontext ctx = { 0 };
2819 signal(SIGUSR1, signal_handler);
2821 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
2822 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
2824 ctx.efd[0] = epoll_create(1);
2825 ASSERT_GE(ctx.efd[0], 0);
2827 ctx.efd[1] = epoll_create(1);
2828 ASSERT_GE(ctx.efd[1], 0);
2830 ctx.efd[2] = epoll_create(1);
2831 ASSERT_GE(ctx.efd[2], 0);
2834 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2837 ASSERT_EQ(epoll_ctl(ctx.efd[2], EPOLL_CTL_ADD, ctx.sfd[2], &e), 0);
2840 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2843 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[2], &e), 0);
2845 ctx.main = pthread_self();
2846 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
2847 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
2849 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
2850 __sync_fetch_and_add(&ctx.count, 1);
2852 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2853 EXPECT_EQ(ctx.count, 2);
2855 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2856 pthread_kill(emitter, SIGUSR1);
2857 pthread_join(emitter, NULL);
2881 struct epoll_event e;
2882 struct epoll_mtcontext ctx = { 0 };
2884 signal(SIGUSR1, signal_handler);
2886 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
2887 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
2889 ctx.efd[0] = epoll_create(1);
2890 ASSERT_GE(ctx.efd[0], 0);
2892 ctx.efd[1] = epoll_create(1);
2893 ASSERT_GE(ctx.efd[1], 0);
2895 ctx.efd[2] = epoll_create(1);
2896 ASSERT_GE(ctx.efd[2], 0);
2899 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2902 ASSERT_EQ(epoll_ctl(ctx.efd[2], EPOLL_CTL_ADD, ctx.sfd[2], &e), 0);
2904 e.events = EPOLLIN | EPOLLET;
2905 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2907 e.events = EPOLLIN | EPOLLET;
2908 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[2], &e), 0);
2910 ctx.main = pthread_self();
2911 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
2912 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
2914 if (epoll_wait(ctx.efd[0], &e, 1, -1) > 0)
2915 __sync_fetch_and_add(&ctx.count, 1);
2917 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2918 EXPECT_EQ(ctx.count, 2);
2920 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2921 pthread_kill(emitter, SIGUSR1);
2922 pthread_join(emitter, NULL);
2947 struct epoll_event e;
2948 struct epoll_mtcontext ctx = { 0 };
2950 signal(SIGUSR1, signal_handler);
2952 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
2953 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
2955 ctx.efd[0] = epoll_create(1);
2956 ASSERT_GE(ctx.efd[0], 0);
2958 ctx.efd[1] = epoll_create(1);
2959 ASSERT_GE(ctx.efd[1], 0);
2961 ctx.efd[2] = epoll_create(1);
2962 ASSERT_GE(ctx.efd[2], 0);
2965 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
2968 ASSERT_EQ(epoll_ctl(ctx.efd[2], EPOLL_CTL_ADD, ctx.sfd[2], &e), 0);
2971 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
2974 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[2], &e), 0);
2976 ctx.main = pthread_self();
2977 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
2978 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
2980 pfd.fd = ctx.efd[0];
2981 pfd.events = POLLIN;
2982 if (poll(&pfd, 1, -1) > 0) {
2983 if (epoll_wait(ctx.efd[0], &e, 1, 0) > 0)
2984 __sync_fetch_and_add(&ctx.count, 1);
2987 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
2988 EXPECT_EQ(ctx.count, 2);
2990 if (pthread_tryjoin_np(emitter, NULL) < 0) {
2991 pthread_kill(emitter, SIGUSR1);
2992 pthread_join(emitter, NULL);
3017 struct epoll_event e;
3018 struct epoll_mtcontext ctx = { 0 };
3020 signal(SIGUSR1, signal_handler);
3022 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[0]), 0);
3023 ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, &ctx.sfd[2]), 0);
3025 ctx.efd[0] = epoll_create(1);
3026 ASSERT_GE(ctx.efd[0], 0);
3028 ctx.efd[1] = epoll_create(1);
3029 ASSERT_GE(ctx.efd[1], 0);
3031 ctx.efd[2] = epoll_create(1);
3032 ASSERT_GE(ctx.efd[2], 0);
3035 ASSERT_EQ(epoll_ctl(ctx.efd[1], EPOLL_CTL_ADD, ctx.sfd[0], &e), 0);
3038 ASSERT_EQ(epoll_ctl(ctx.efd[2], EPOLL_CTL_ADD, ctx.sfd[2], &e), 0);
3040 e.events = EPOLLIN | EPOLLET;
3041 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[1], &e), 0);
3043 e.events = EPOLLIN | EPOLLET;
3044 ASSERT_EQ(epoll_ctl(ctx.efd[0], EPOLL_CTL_ADD, ctx.efd[2], &e), 0);
3046 ctx.main = pthread_self();
3047 ASSERT_EQ(pthread_create(&ctx.waiter, NULL, waiter_entry1ap, &ctx), 0);
3048 ASSERT_EQ(pthread_create(&emitter, NULL, emitter_entry2, &ctx), 0);
3050 pfd.fd = ctx.efd[0];
3051 pfd.events = POLLIN;
3052 if (poll(&pfd, 1, -1) > 0) {
3053 if (epoll_wait(ctx.efd[0], &e, 1, 0) > 0)
3054 __sync_fetch_and_add(&ctx.count, 1);
3057 ASSERT_EQ(pthread_join(ctx.waiter, NULL), 0);
3058 EXPECT_EQ(ctx.count, 2);
3060 if (pthread_tryjoin_np(emitter, NULL) < 0) {
3061 pthread_kill(emitter, SIGUSR1);
3062 pthread_join(emitter, NULL);