diff options
author | Duncan Coutts <duncan@well-typed.com> | 2020-12-29 16:39:36 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-22 02:06:17 -0500 |
commit | 5cf709c541a46a17ef2e36d589ba13d949d058e1 (patch) | |
tree | dbd2e595dbd3af2a3f904b084de3aa74e2099a8e /rts/PrimOps.cmm | |
parent | 8901285ef64ab4aa16aa34096a1e2be42d4be246 (diff) | |
download | haskell-5cf709c541a46a17ef2e36d589ba13d949d058e1.tar.gz |
Move APPEND_TO_BLOCKED_QUEUE from cmm to C
The I/O and delay blocking primitives for the non-threaded way
currently access the blocked_queue and sleeping_queue directly.
We want to move where those queues are to make their ownership clearer:
to have them clearly belong to the I/O manager impls rather than to the
scheduler. Ultimately we will want to change their representation too.
It's inconvenient to do that if these queues are accessed directly from
cmm code. So as a first step, replace the APPEND_TO_BLOCKED_QUEUE with a
C version appendToIOBlockedQueue(), and replace the open-coded
sleeping_queue insertion with insertIntoSleepingQueue().
Diffstat (limited to 'rts/PrimOps.cmm')
-rw-r--r-- | rts/PrimOps.cmm | 42 |
1 files changed, 7 insertions, 35 deletions
diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm index fe74b3fa81..537050857d 100644 --- a/rts/PrimOps.cmm +++ b/rts/PrimOps.cmm @@ -2571,18 +2571,6 @@ stg_whereFromzh (P_ clos) Thread I/O blocking primitives -------------------------------------------------------------------------- */ -/* Add a thread to the end of the blocked queue. (C-- version of the C - * macro in Schedule.h). - */ -#define APPEND_TO_BLOCKED_QUEUE(tso) \ - ASSERT(StgTSO__link(tso) == END_TSO_QUEUE); \ - if (W_[blocked_queue_hd] == END_TSO_QUEUE) { \ - W_[blocked_queue_hd] = tso; \ - } else { \ - ccall setTSOLink(MyCapability() "ptr", W_[blocked_queue_tl] "ptr", tso); \ - } \ - W_[blocked_queue_tl] = tso; - stg_waitReadzh ( W_ fd ) { #if defined(THREADED_RTS) @@ -2594,7 +2582,7 @@ stg_waitReadzh ( W_ fd ) StgTSO_block_info(CurrentTSO) = fd; // No locking - we're not going to use this interface in the // threaded RTS anyway. - APPEND_TO_BLOCKED_QUEUE(CurrentTSO); + ccall appendToIOBlockedQueue(CurrentTSO "ptr"); jump stg_block_noregs(); #endif } @@ -2610,7 +2598,7 @@ stg_waitWritezh ( W_ fd ) StgTSO_block_info(CurrentTSO) = fd; // No locking - we're not going to use this interface in the // threaded RTS anyway. - APPEND_TO_BLOCKED_QUEUE(CurrentTSO); + ccall appendToIOBlockedQueue(CurrentTSO "ptr"); jump stg_block_noregs(); #endif } @@ -2647,32 +2635,16 @@ stg_delayzh ( W_ us_delay ) * delayed thread on the blocked_queue. */ StgTSO_why_blocked(CurrentTSO) = BlockedOnDoProc::I16; - APPEND_TO_BLOCKED_QUEUE(CurrentTSO); + ccall appendToIOBlockedQueue(CurrentTSO "ptr"); jump stg_block_async_void(); #else - (target) = ccall getDelayTarget(us_delay); StgTSO_block_info(CurrentTSO) = target; - /* Insert the new thread in the sleeping queue. */ - prev = NULL; - t = W_[sleeping_queue]; -while: - if (t != END_TSO_QUEUE && StgTSO_block_info(t) < target) { - prev = t; - t = StgTSO__link(t); - goto while; - } - - StgTSO__link(CurrentTSO) = t; - if (prev == NULL) { - W_[sleeping_queue] = CurrentTSO; - } else { - ccall setTSOLink(MyCapability() "ptr", prev "ptr", CurrentTSO); - } + ccall insertIntoSleepingQueue(CurrentTSO "ptr", target); jump stg_block_noregs(); #endif #endif /* !THREADED_RTS */ @@ -2700,7 +2672,7 @@ stg_asyncReadzh ( W_ fd, W_ is_sock, W_ len, W_ buf ) StgAsyncIOResult_len(ares) = 0; StgAsyncIOResult_errCode(ares) = 0; StgTSO_block_info(CurrentTSO) = ares; - APPEND_TO_BLOCKED_QUEUE(CurrentTSO); + ccall appendToIOBlockedQueue(CurrentTSO "ptr"); jump stg_block_async(); #endif } @@ -2725,7 +2697,7 @@ stg_asyncWritezh ( W_ fd, W_ is_sock, W_ len, W_ buf ) StgAsyncIOResult_len(ares) = 0; StgAsyncIOResult_errCode(ares) = 0; StgTSO_block_info(CurrentTSO) = ares; - APPEND_TO_BLOCKED_QUEUE(CurrentTSO); + ccall appendToIOBlockedQueue(CurrentTSO "ptr"); jump stg_block_async(); #endif } @@ -2750,7 +2722,7 @@ stg_asyncDoProczh ( W_ proc, W_ param ) StgAsyncIOResult_len(ares) = 0; StgAsyncIOResult_errCode(ares) = 0; StgTSO_block_info(CurrentTSO) = ares; - APPEND_TO_BLOCKED_QUEUE(CurrentTSO); + ccall appendToIOBlockedQueue(CurrentTSO "ptr"); jump stg_block_async(); #endif } |