Skip to content

Commit 7a1f1d0

Browse files
committed
Some minor cleanup.
1 parent 7e91f0c commit 7a1f1d0

12 files changed

Lines changed: 33419 additions & 5416 deletions

File tree

generated/mhs.c

Lines changed: 33050 additions & 5232 deletions
Large diffs are not rendered by default.

lib/Foreign/C/Error.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ instance Eq Errno where
9999
| isValidErrno errno1 = no1 == no2
100100
| otherwise = False
101101

102+
instance Show Errno where
103+
showsPrec p (Errno e) = showsPrec p e
104+
102105
eOK :: Errno
103106
eOK = Errno 0
104107

lib/System/IO/FD.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ waitForReadFD :: Int -> IO Int
66
waitForReadFD = primWaitReadFD
77

88
waitForWriteFD :: Int -> IO Int
9-
waitForWriteFD = primWaitWriteFD
9+
waitForWriteFD = primWaitWriteFD

src/runtime/eval.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
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
*/
11401141
static 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)
16431644
void
16441645
pause_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;

src/runtime/io_poll.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* OS-agnostic interface for non-blocking IO polling.
77
* Platform-specific implementations live in <platform>/io_poll_impl.c and
88
* are included into eval.c via #include "io_poll_impl.c".
9-
*
109
*/
1110

1211
#define IO_POLL_READ 1

src/runtime/unix/config.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@
8989
* Linux uses epoll
9090
* The backend is selected in unix/io_poll_impl.c.
9191
*/
92-
#if defined(__linux__)
93-
#define MHS_IO_POLL 1
94-
#else
95-
#define MHS_IO_POLL 0
96-
#endif
92+
#define WANT_IO_POLL 1
9793

9894
/*
9995
* Use CPU counters.

src/runtime/unix/io_poll_epoll.c

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)