4242#if WANT_SIGINT
4343#include <signal.h>
4444#endif
45- #if MHS_IO_POLL
45+ #if WANT_IO_POLL
4646#include "io_poll.h"
4747#endif
4848
@@ -938,8 +938,9 @@ struct mthread {
938938 NODEPTR mt_mval ; /* filled after waiting for take/read */
939939 bool mt_mark ; /* marked as accessible */
940940 uvalue_t mt_id ; /* thread number, thread 1 is the main thread */
941- #if MHS_IO_POLL
942- int mt_fd ; /* The file descriptor that we are waiting on (will be either IO_POLL_WAITING_FOR_NONE or IO_POLL_EVENT_HAS_HAPPENED) */
941+ #if WANT_IO_POLL
942+ int mt_fd ; /* The file descriptor that we are waiting on
943+ (will be either IO_POLL_WAITING_FOR_NONE or IO_POLL_EVENT_HAS_HAPPENED) */
943944 int mt_events ; /* IO_POLL_READ or IO_POLL_WRITE */
944945#endif
945946#if defined(CLOCK_INIT )
@@ -1133,8 +1134,8 @@ add_runq_tail(struct mthread *mt)
11331134 add_q_tail (& runq , mt );
11341135}
11351136
1136- #if MHS_IO_POLL
1137- /* this is the callback that is sent to the io_poll framework.
1137+ #if WANT_IO_POLL
1138+ /* This is the callback that is sent to the io_poll framework.
11381139 * It is invoked when an event a thread is waiting for becomes ready.
11391140 */
11401141static void
@@ -1334,10 +1335,10 @@ yield(void)
13341335 check_thrown (false);
13351336 check_sigint ();
13361337
1337- #if MHS_IO_POLL
1338+ #if WANT_IO_POLL
13381339 if (io_waiter_count () > 0 ) {
13391340 /* Check if any threads blocked on IO can be scheduled. Since we pass in a delay of 0, checking
1340- for the events should not block. */
1341+ * for the events will not block. */
13411342 io_poll (0 , io_thread_ready );
13421343 }
13431344#endif
@@ -1387,7 +1388,7 @@ new_thread(NODEPTR root)
13871388 mt -> mt_mark = false;
13881389 mt -> mt_num_slices = 0 ;
13891390 mt -> mt_id = num_thread_create ++ ;
1390- #if MHS_IO_POLL
1391+ #if WANT_IO_POLL
13911392 mt -> mt_fd = IO_POLL_WAITING_FOR_NONE ;
13921393 mt -> mt_events = -1 ;
13931394#endif
@@ -1643,13 +1644,14 @@ thread_delay(uvalue_t usecs)
16431644void
16441645pause_exec (void )
16451646{
1646- /* End up here if the run queue is empty. If there is no thread waiting for
1647+ /*
1648+ * We end up here if the run queue is empty. If there is no thread waiting for
16471649 * a delay to expire, we will never resume operation and we are deadlocked. However, if
1648- * we compile with MHS_IO_POLL there might be threads waiting for IO events, so in
1650+ * we compile with WANT_IO_POLL there might be threads waiting for IO events, so in
16491651 * that case we check for them as well. If there is no thread waiting for a delay or an
16501652 * IO event, we are deadlocked.
16511653 */
1652- #if MHS_IO_POLL
1654+ #if WANT_IO_POLL
16531655
16541656 /* Check for deadlock situation */
16551657 if (io_waiter_count () == 0
@@ -1663,12 +1665,12 @@ pause_exec(void)
16631665 int timeout_ms = -1 ; /* block indefinitely if only io_waiters */
16641666#if defined(CLOCK_INIT )
16651667 /* If there are threads blocked on delays, recompute the timeout_ms to account
1666- for that. */
1668+ * for that. */
16671669 if (timeq .mq_head ) {
16681670 CLOCK_T delta = timeq .mq_head -> mt_at - CLOCK_GET ();
16691671 /* +999 emulates a ceiling function, adding at most 0.999 ms. io_poll wants milliseconds,
1670- not microseconds as delta represents. When delta is < 1000, without +999, we'll truncate
1671- to zero and enter a loop at full CPU speed. */
1672+ * not microseconds as delta represents. When delta is < 1000, without +999, we'll truncate
1673+ * to zero and enter a loop at full CPU speed. */
16721674 timeout_ms = (delta > 0 ) ? (int )((delta + 999 ) / 1000 ) : 0 ;
16731675 }
16741676#endif
@@ -1678,7 +1680,7 @@ pause_exec(void)
16781680#endif
16791681 }
16801682
1681- #else /* !MHS_IO_POLL */
1683+ #else /* !WANT_IO_POLL */
16821684
16831685#if defined(CLOCK_INIT )
16841686 if (timeq .mq_head ) {
@@ -1717,7 +1719,7 @@ pause_exec(void)
17171719#else /* CLOCK_INIT */
17181720 ERR ("no clock" );
17191721#endif /* CLOCK_INIT */
1720- #endif /* MHS_IO_POLL */
1722+ #endif /* WANT_IO_POLL */
17211723}
17221724
17231725/* Interrupt a sleeping thread in a throwTo/threadDelay */
@@ -1905,7 +1907,7 @@ new_ap(NODEPTR f, NODEPTR a)
19051907 return n ;
19061908}
19071909
1908- #if MHS_IO_POLL
1910+ #if WANT_IO_POLL
19091911#include "io_poll_impl.c"
19101912#endif
19111913
@@ -1923,7 +1925,7 @@ start_exec(NODEPTR root)
19231925 mt -> mt_id = MAIN_THREAD ; /* make it the main thread in case this is foreign export calling */
19241926 main_thread = mt ;
19251927
1926- #if MHS_IO_POLL
1928+ #if WANT_IO_POLL
19271929 io_init ();
19281930#endif
19291931
@@ -6090,14 +6092,12 @@ evali(NODEPTR an)
60906092 }
60916093 case T_IO_WAITRDFD :
60926094 case T_IO_WAITWRFD : {
6093- #if MHS_IO_POLL
6095+ #if WANT_IO_POLL
60946096 CHKARG2NP ; /* x = the filedescriptor, y = RealWorld; no pop yet */
60956097
60966098 /* io_thread_ready sets mt_fd=IO_POLL_EVENT_HAS_HAPPENED when waking the thread.
6097- If we did not do this check we would just register again.
6098-
6099- This seems to be how T_IO_THREADDELAY works, with mt_at == -1.
6100- */
6099+ * If we did not do this check we would just register again.
6100+ */
61016101 if (runq .mq_head -> mt_fd == IO_POLL_EVENT_HAS_HAPPENED ) {
61026102 runq .mq_head -> mt_fd = IO_POLL_WAITING_FOR_NONE ;
61036103 POP (2 );
@@ -6109,7 +6109,8 @@ evali(NODEPTR an)
61096109 int events = (tag == T_IO_WAITRDFD ) ? IO_POLL_READ : IO_POLL_WRITE ;
61106110
61116111 /* Set up the waiting thread's state, preparing it to leave the run queue
6112- until an event is ready for it */
6112+ * until an event is ready for it.
6113+ */
61136114 struct mthread * mt = remove_q_head (& runq );
61146115 mt -> mt_fd = fd ;
61156116 mt -> mt_events = events ;
0 commit comments