Commit 570b3393 authored by Austin Seipp's avatar Austin Seipp
Browse files

[skip ci] rts: Detabify Threads.c


Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
parent 6aa6ca89
...@@ -35,11 +35,11 @@ static StgThreadID next_thread_id = 1; ...@@ -35,11 +35,11 @@ static StgThreadID next_thread_id = 1;
* RESERVED_STACK_WORDS (so we can get back from the stack overflow) * RESERVED_STACK_WORDS (so we can get back from the stack overflow)
* + sizeofW(StgStopFrame) (the stg_stop_thread_info frame) * + sizeofW(StgStopFrame) (the stg_stop_thread_info frame)
* + 1 (the closure to enter) * + 1 (the closure to enter)
* + 1 (stg_ap_v_ret) * + 1 (stg_ap_v_ret)
* + 1 (spare slot req'd by stg_ap_v_ret) * + 1 (spare slot req'd by stg_ap_v_ret)
* *
* A thread with this stack will bomb immediately with a stack * A thread with this stack will bomb immediately with a stack
* overflow, which will increase its stack size. * overflow, which will increase its stack size.
*/ */
#define MIN_STACK_WORDS (RESERVED_STACK_WORDS + sizeofW(StgStopFrame) + 3) #define MIN_STACK_WORDS (RESERVED_STACK_WORDS + sizeofW(StgStopFrame) + 3)
...@@ -106,7 +106,7 @@ createThread(Capability *cap, W_ size) ...@@ -106,7 +106,7 @@ createThread(Capability *cap, W_ size)
tso->saved_errno = 0; tso->saved_errno = 0;
tso->bound = NULL; tso->bound = NULL;
tso->cap = cap; tso->cap = cap;
tso->stackobj = stack; tso->stackobj = stack;
tso->tot_stack_size = stack->stack_size; tso->tot_stack_size = stack->stack_size;
...@@ -115,7 +115,7 @@ createThread(Capability *cap, W_ size) ...@@ -115,7 +115,7 @@ createThread(Capability *cap, W_ size)
#ifdef PROFILING #ifdef PROFILING
tso->prof.cccs = CCS_MAIN; tso->prof.cccs = CCS_MAIN;
#endif #endif
// put a stop frame on the stack // put a stop frame on the stack
stack->sp -= sizeofW(StgStopFrame); stack->sp -= sizeofW(StgStopFrame);
SET_HDR((StgClosure*)stack->sp, SET_HDR((StgClosure*)stack->sp,
...@@ -128,7 +128,7 @@ createThread(Capability *cap, W_ size) ...@@ -128,7 +128,7 @@ createThread(Capability *cap, W_ size)
tso->global_link = g0->threads; tso->global_link = g0->threads;
g0->threads = tso; g0->threads = tso;
RELEASE_LOCK(&sched_mutex); RELEASE_LOCK(&sched_mutex);
// ToDo: report the stack size in the event? // ToDo: report the stack size in the event?
traceEventCreateThread(cap, tso); traceEventCreateThread(cap, tso);
...@@ -143,11 +143,11 @@ createThread(Capability *cap, W_ size) ...@@ -143,11 +143,11 @@ createThread(Capability *cap, W_ size)
* ------------------------------------------------------------------------ */ * ------------------------------------------------------------------------ */
int int
cmp_thread(StgPtr tso1, StgPtr tso2) cmp_thread(StgPtr tso1, StgPtr tso2)
{ {
StgThreadID id1 = ((StgTSO *)tso1)->id; StgThreadID id1 = ((StgTSO *)tso1)->id;
StgThreadID id2 = ((StgTSO *)tso2)->id; StgThreadID id2 = ((StgTSO *)tso2)->id;
if (id1 < id2) return (-1); if (id1 < id2) return (-1);
if (id1 > id2) return 1; if (id1 > id2) return 1;
return 0; return 0;
...@@ -159,7 +159,7 @@ cmp_thread(StgPtr tso1, StgPtr tso2) ...@@ -159,7 +159,7 @@ cmp_thread(StgPtr tso1, StgPtr tso2)
* This is used in the implementation of Show for ThreadIds. * This is used in the implementation of Show for ThreadIds.
* ------------------------------------------------------------------------ */ * ------------------------------------------------------------------------ */
int int
rts_getThreadId(StgPtr tso) rts_getThreadId(StgPtr tso)
{ {
return ((StgTSO *)tso)->id; return ((StgTSO *)tso)->id;
} }
...@@ -176,23 +176,23 @@ removeThreadFromQueue (Capability *cap, StgTSO **queue, StgTSO *tso) ...@@ -176,23 +176,23 @@ removeThreadFromQueue (Capability *cap, StgTSO **queue, StgTSO *tso)
prev = NULL; prev = NULL;
for (t = *queue; t != END_TSO_QUEUE; prev = t, t = t->_link) { for (t = *queue; t != END_TSO_QUEUE; prev = t, t = t->_link) {
if (t == tso) { if (t == tso) {
if (prev) { if (prev) {
setTSOLink(cap,prev,t->_link); setTSOLink(cap,prev,t->_link);
t->_link = END_TSO_QUEUE; t->_link = END_TSO_QUEUE;
return rtsFalse; return rtsFalse;
} else { } else {
*queue = t->_link; *queue = t->_link;
t->_link = END_TSO_QUEUE; t->_link = END_TSO_QUEUE;
return rtsTrue; return rtsTrue;
} }
} }
} }
barf("removeThreadFromQueue: not found"); barf("removeThreadFromQueue: not found");
} }
rtsBool // returns True if we modified head or tail rtsBool // returns True if we modified head or tail
removeThreadFromDeQueue (Capability *cap, removeThreadFromDeQueue (Capability *cap,
StgTSO **head, StgTSO **tail, StgTSO *tso) StgTSO **head, StgTSO **tail, StgTSO *tso)
{ {
StgTSO *t, *prev; StgTSO *t, *prev;
...@@ -200,26 +200,26 @@ removeThreadFromDeQueue (Capability *cap, ...@@ -200,26 +200,26 @@ removeThreadFromDeQueue (Capability *cap,
prev = NULL; prev = NULL;
for (t = *head; t != END_TSO_QUEUE; prev = t, t = t->_link) { for (t = *head; t != END_TSO_QUEUE; prev = t, t = t->_link) {
if (t == tso) { if (t == tso) {
if (prev) { if (prev) {
setTSOLink(cap,prev,t->_link); setTSOLink(cap,prev,t->_link);
flag = rtsFalse; flag = rtsFalse;
} else { } else {
*head = t->_link; *head = t->_link;
flag = rtsTrue; flag = rtsTrue;
} }
t->_link = END_TSO_QUEUE; t->_link = END_TSO_QUEUE;
if (*tail == tso) { if (*tail == tso) {
if (prev) { if (prev) {
*tail = prev; *tail = prev;
} else { } else {
*tail = END_TSO_QUEUE; *tail = END_TSO_QUEUE;
} }
return rtsTrue; return rtsTrue;
} else { } else {
return flag; return flag;
} }
} }
} }
barf("removeThreadFromDeQueue: not found"); barf("removeThreadFromDeQueue: not found");
} }
...@@ -268,7 +268,7 @@ tryWakeupThread (Capability *cap, StgTSO *tso) ...@@ -268,7 +268,7 @@ tryWakeupThread (Capability *cap, StgTSO *tso)
case BlockedOnMsgThrowTo: case BlockedOnMsgThrowTo:
{ {
const StgInfoTable *i; const StgInfoTable *i;
i = lockClosure(tso->block_info.closure); i = lockClosure(tso->block_info.closure);
unlockClosure(tso->block_info.closure, i); unlockClosure(tso->block_info.closure, i);
if (i != &stg_MSG_NULL_info) { if (i != &stg_MSG_NULL_info) {
...@@ -343,7 +343,7 @@ wakeBlockingQueue(Capability *cap, StgBlockingQueue *bq) ...@@ -343,7 +343,7 @@ wakeBlockingQueue(Capability *cap, StgBlockingQueue *bq)
ASSERT(bq->header.info == &stg_BLOCKING_QUEUE_DIRTY_info || ASSERT(bq->header.info == &stg_BLOCKING_QUEUE_DIRTY_info ||
bq->header.info == &stg_BLOCKING_QUEUE_CLEAN_info ); bq->header.info == &stg_BLOCKING_QUEUE_CLEAN_info );
for (msg = bq->queue; msg != (MessageBlackHole*)END_TSO_QUEUE; for (msg = bq->queue; msg != (MessageBlackHole*)END_TSO_QUEUE;
msg = msg->link) { msg = msg->link) {
i = msg->header.info; i = msg->header.info;
if (i != &stg_IND_info) { if (i != &stg_IND_info) {
...@@ -377,7 +377,7 @@ checkBlockingQueues (Capability *cap, StgTSO *tso) ...@@ -377,7 +377,7 @@ checkBlockingQueues (Capability *cap, StgTSO *tso)
debugTraceCap(DEBUG_sched, cap, debugTraceCap(DEBUG_sched, cap,
"collision occurred; checking blocking queues for thread %ld", "collision occurred; checking blocking queues for thread %ld",
(W_)tso->id); (W_)tso->id);
for (bq = tso->bq; bq != (StgBlockingQueue*)END_TSO_QUEUE; bq = next) { for (bq = tso->bq; bq != (StgBlockingQueue*)END_TSO_QUEUE; bq = next) {
next = bq->link; next = bq->link;
...@@ -386,14 +386,14 @@ checkBlockingQueues (Capability *cap, StgTSO *tso) ...@@ -386,14 +386,14 @@ checkBlockingQueues (Capability *cap, StgTSO *tso)
// traversing this IND multiple times. // traversing this IND multiple times.
continue; continue;
} }
p = bq->bh; p = bq->bh;
if (p->header.info != &stg_BLACKHOLE_info || if (p->header.info != &stg_BLACKHOLE_info ||
((StgInd *)p)->indirectee != (StgClosure*)bq) ((StgInd *)p)->indirectee != (StgClosure*)bq)
{ {
wakeBlockingQueue(cap,bq); wakeBlockingQueue(cap,bq);
} }
} }
} }
...@@ -420,7 +420,7 @@ updateThunk (Capability *cap, StgTSO *tso, StgClosure *thunk, StgClosure *val) ...@@ -420,7 +420,7 @@ updateThunk (Capability *cap, StgTSO *tso, StgClosure *thunk, StgClosure *val)
updateWithIndirection(cap, thunk, val); updateWithIndirection(cap, thunk, val);
return; return;
} }
v = ((StgInd*)thunk)->indirectee; v = ((StgInd*)thunk)->indirectee;
updateWithIndirection(cap, thunk, val); updateWithIndirection(cap, thunk, val);
...@@ -457,7 +457,7 @@ updateThunk (Capability *cap, StgTSO *tso, StgClosure *thunk, StgClosure *val) ...@@ -457,7 +457,7 @@ updateThunk (Capability *cap, StgTSO *tso, StgClosure *thunk, StgClosure *val)
* rtsSupportsBoundThreads(): is the RTS built to support bound threads? * rtsSupportsBoundThreads(): is the RTS built to support bound threads?
* used by Control.Concurrent for error checking. * used by Control.Concurrent for error checking.
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
HsBool HsBool
rtsSupportsBoundThreads(void) rtsSupportsBoundThreads(void)
{ {
...@@ -471,7 +471,7 @@ rtsSupportsBoundThreads(void) ...@@ -471,7 +471,7 @@ rtsSupportsBoundThreads(void)
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* isThreadBound(tso): check whether tso is bound to an OS thread. * isThreadBound(tso): check whether tso is bound to an OS thread.
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
StgBool StgBool
isThreadBound(StgTSO* tso USED_IF_THREADS) isThreadBound(StgTSO* tso USED_IF_THREADS)
{ {
...@@ -558,7 +558,7 @@ threadStackOverflow (Capability *cap, StgTSO *tso) ...@@ -558,7 +558,7 @@ threadStackOverflow (Capability *cap, StgTSO *tso)
// we squeezed is not enough to run the thread, we'll come back // we squeezed is not enough to run the thread, we'll come back
// here (no squeezing will have occurred and thus we'll enlarge the // here (no squeezing will have occurred and thus we'll enlarge the
// stack.) // stack.)
if ((tso->flags & TSO_SQUEEZED) && if ((tso->flags & TSO_SQUEEZED) &&
((W_)(tso->stackobj->sp - tso->stackobj->stack) >= BLOCK_SIZE_W)) { ((W_)(tso->stackobj->sp - tso->stackobj->stack) >= BLOCK_SIZE_W)) {
return; return;
} }
...@@ -787,7 +787,7 @@ printThreadBlockage(StgTSO *tso) ...@@ -787,7 +787,7 @@ printThreadBlockage(StgTSO *tso)
debugBelch("is blocked on atomic MVar read @ %p", tso->block_info.closure); debugBelch("is blocked on atomic MVar read @ %p", tso->block_info.closure);
break; break;
case BlockedOnBlackHole: case BlockedOnBlackHole:
debugBelch("is blocked on a black hole %p", debugBelch("is blocked on a black hole %p",
((StgBlockingQueue*)tso->block_info.bh->bh)); ((StgBlockingQueue*)tso->block_info.bh->bh));
break; break;
case BlockedOnMsgThrowTo: case BlockedOnMsgThrowTo:
...@@ -810,7 +810,7 @@ printThreadBlockage(StgTSO *tso) ...@@ -810,7 +810,7 @@ printThreadBlockage(StgTSO *tso)
break; break;
default: default:
barf("printThreadBlockage: strange tso->why_blocked: %d for TSO %d (%d)", barf("printThreadBlockage: strange tso->why_blocked: %d for TSO %d (%d)",
tso->why_blocked, tso->id, tso); tso->why_blocked, tso->id, tso);
} }
} }
...@@ -824,19 +824,19 @@ printThreadStatus(StgTSO *t) ...@@ -824,19 +824,19 @@ printThreadStatus(StgTSO *t)
if (label) debugBelch("[\"%s\"] ",(char *)label); if (label) debugBelch("[\"%s\"] ",(char *)label);
} }
switch (t->what_next) { switch (t->what_next) {
case ThreadKilled: case ThreadKilled:
debugBelch("has been killed"); debugBelch("has been killed");
break; break;
case ThreadComplete: case ThreadComplete:
debugBelch("has completed"); debugBelch("has completed");
break; break;
default: default:
printThreadBlockage(t); printThreadBlockage(t);
} }
if (t->dirty) { if (t->dirty) {
debugBelch(" (TSO_DIRTY)"); debugBelch(" (TSO_DIRTY)");
} }
debugBelch("\n"); debugBelch("\n");
} }
void void
...@@ -852,7 +852,7 @@ printAllThreads(void) ...@@ -852,7 +852,7 @@ printAllThreads(void)
cap = capabilities[i]; cap = capabilities[i];
debugBelch("threads on capability %d:\n", cap->no); debugBelch("threads on capability %d:\n", cap->no);
for (t = cap->run_queue_hd; t != END_TSO_QUEUE; t = t->_link) { for (t = cap->run_queue_hd; t != END_TSO_QUEUE; t = t->_link) {
printThreadStatus(t); printThreadStatus(t);
} }
} }
...@@ -860,7 +860,7 @@ printAllThreads(void) ...@@ -860,7 +860,7 @@ printAllThreads(void)
for (g = 0; g < RtsFlags.GcFlags.generations; g++) { for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
for (t = generations[g].threads; t != END_TSO_QUEUE; t = next) { for (t = generations[g].threads; t != END_TSO_QUEUE; t = next) {
if (t->why_blocked != NotBlocked) { if (t->why_blocked != NotBlocked) {
printThreadStatus(t); printThreadStatus(t);
} }
next = t->global_link; next = t->global_link;
} }
...@@ -868,13 +868,13 @@ printAllThreads(void) ...@@ -868,13 +868,13 @@ printAllThreads(void)
} }
// useful from gdb // useful from gdb
void void
printThreadQueue(StgTSO *t) printThreadQueue(StgTSO *t)
{ {
nat i = 0; nat i = 0;
for (; t != END_TSO_QUEUE; t = t->_link) { for (; t != END_TSO_QUEUE; t = t->_link) {
printThreadStatus(t); printThreadStatus(t);
i++; i++;
} }
debugBelch("%d threads on queue\n", i); debugBelch("%d threads on queue\n", i);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment