1 /* -----------------------------------------------------------------------------
2 * $Id: TSO.h,v 1.10 2000/01/13 14:34:01 hwloidl Exp $
4 * (c) The GHC Team, 1998-1999
6 * The definitions for Thread State Objects.
8 * ---------------------------------------------------------------------------*/
13 #if defined(GRAN) || defined(PAR)
14 // magic marker for TSOs; debugging only
15 #define TSO_MAGIC 4321
37 #if defined(PROFILING)
39 CostCentreStack *CCCS; /* thread's current CCS */
41 #else /* !PROFILING */
44 #endif /* PROFILING */
47 typedef StgTSOStatBuf StgTSOParInfo;
54 typedef StgTSOStatBuf StgTSOGranInfo;
64 #else /* !TICKY_TICKY */
67 #endif /* TICKY_TICKY */
83 * We are completely paranoid and make thread IDs 64 bits to avoid
84 * having to worry about overflow. A little calculation shows that
85 * even doing 10^6 forks per second would take 35 million years to
86 * overflow a 64 bit thread ID :-)
89 typedef StgWord32 StgThreadID;
92 * This type is returned to the scheduler by a thread that has
93 * stopped for one reason or another.
97 HeapOverflow, /* might also be StackOverflow */
102 } StgThreadReturnCode;
105 * Threads may be blocked for several reasons. A blocked thread will
106 * have the reason in the why_blocked field of the TSO, and some
107 * further info (such as the closure the thread is blocked on, or the
108 * file descriptor if the thread is waiting on I/O) in the block_info
121 , BlockedOnGA // blocked on a remote closure represented by a Global Address
136 * TSOs live on the heap, and therefore look just like heap objects.
137 * Large TSOs will live in their own "block group" allocated by the
138 * storage manager, and won't be copied during garbage collection.
141 typedef struct StgTSO_ {
143 struct StgTSO_* link;
144 /* SDM and HWL agree that it would be cool to have a list of all TSOs */
145 StgMutClosure * mut_link; /* TSO's are mutable of course! */
146 StgTSOWhatNext whatNext;
147 StgTSOBlockReason why_blocked;
148 StgTSOBlockInfo block_info;
149 struct StgTSO_* blocked_exceptions;
151 StgTSOTickyInfo ticky;
156 /* The thread stack... */
157 StgWord stack_size; /* stack size in *words* */
158 StgWord max_stack_size; /* maximum stack size in *words* */
166 /* -----------------------------------------------------------------------------
169 An active thread has the following properties:
171 tso->stack < tso->sp < tso->stack+tso->stack_size
172 tso->stack_size <= tso->max_stack_size
173 tso->splim == tso->stack + RESERVED_STACK_WORDS;
175 RESERVED_STACK_WORDS is large enough for any heap-check or
178 The size of the TSO struct plus the stack is either
179 (a) smaller than a block, or
180 (b) a multiple of BLOCK_SIZE
182 tso->block_reason tso->block_info location
183 ----------------------------------------------------------------------
184 NotBlocked NULL runnable_queue, or running
186 BlockedOnBlackHole the BLACKHOLE_BQ the BLACKHOLE_BQ's queue
188 BlockedOnMVar the MVAR the MVAR's queue
190 BlockedOnException the TSO TSO->blocked_exception
192 BlockedOnRead NULL blocked_queue
193 BlockedOnWrite NULL blocked_queue
194 BlockedOnDelay NULL blocked_queue
196 tso->link == END_TSO_QUEUE, if the thread is currently running.
198 A zombie thread has the following properties:
200 tso->whatNext == ThreadComplete or ThreadKilled
201 tso->link == (could be on some queue somewhere)
202 tso->su == tso->stack + tso->stack_size
203 tso->sp == tso->stack + tso->stack_size - 1 (i.e. top stack word)
204 tso->sp[0] == return value of thread, if whatNext == ThreadComplete,
205 exception , if whatNext == ThreadKilled
207 (tso->sp is left pointing at the top word on the stack so that
208 the return value or exception will be retained by a GC).
210 tso->blocked_exceptions is either:
212 NULL if async exceptions are unblocked.
214 END_TSO_QUEUE if async exceptions are blocked, but no threads
215 are currently waiting to deliver.
217 (StgTSO *)tso if threads are currently awaiting delivery of
218 exceptions to this thread.
220 ---------------------------------------------------------------------------- */
222 /* Workaround for a bug/quirk in gcc on certain architectures.
223 * symptom is that (&tso->stack - &tso->header) /= sizeof(StgTSO)
224 * in other words, gcc pads the structure at the end.
227 extern StgTSO dummy_tso;
229 #define TSO_STRUCT_SIZE \
230 ((int)&(dummy_tso).stack - (int)&(dummy_tso).header)
232 #define TSO_STRUCT_SIZEW (TSO_STRUCT_SIZE / sizeof(W_))