[project @ 1999-03-02 19:50:12 by sof]
[ghc-hetmet.git] / ghc / includes / Updates.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Updates.h,v 1.8 1999/03/02 19:44:23 sof Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Definitions related to updates.
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #ifndef UPDATES_H
11 #define UPDATES_H
12
13 /* -----------------------------------------------------------------------------
14    Update a closure with an indirection.  This may also involve waking
15    up a queue of blocked threads waiting on the result of this
16    computation.
17    -------------------------------------------------------------------------- */
18
19 /* ToDo: overwrite slop words with something safe in case sanity checking 
20  *       is turned on.  
21  *       (I think the fancy version of the GC is supposed to do this too.)
22  */
23
24 /* This expands to a fair chunk of code, what with waking up threads 
25  * and checking whether we're updating something in a old generation.
26  * preferably don't use this macro inline in compiled code.
27  */
28
29 #define UPD_IND(updclosure, heapptr)                            \
30         AWAKEN_BQ(updclosure);                                  \
31         updateWithIndirection((StgClosure *)updclosure,         \
32                               (StgClosure *)heapptr);
33
34 /* -----------------------------------------------------------------------------
35    Awaken any threads waiting on this computation
36    -------------------------------------------------------------------------- */
37
38 extern void awaken_blocked_queue(StgTSO *q);
39
40 #define AWAKEN_BQ(closure)                                              \
41         if (closure->header.info == &BLACKHOLE_BQ_info) {               \
42                 StgTSO *bq = ((StgBlockingQueue *)closure)->blocking_queue;\
43                 if (bq != (StgTSO *)&END_TSO_QUEUE_closure) {           \
44                         STGCALL1(awaken_blocked_queue, bq);             \
45                 }                                                       \
46         }
47
48
49 /* -----------------------------------------------------------------------------
50    Push an update frame on the stack.
51    -------------------------------------------------------------------------- */
52
53 #if defined(PROFILING)
54 #define PUSH_STD_CCCS(frame) frame->header.prof.ccs = CCCS
55 #else
56 #define PUSH_STD_CCCS(frame)
57 #endif
58
59 extern DLL_IMPORT_DATA const StgPolyInfoTable Upd_frame_info; 
60
61 #define PUSH_UPD_FRAME(target, Sp_offset)                       \
62         {                                                       \
63                 StgUpdateFrame *__frame;                        \
64                 TICK_UPDF_PUSHED();                             \
65                 __frame = stgCast(StgUpdateFrame*,Sp + (Sp_offset)) - 1; \
66                 SET_INFO(__frame,stgCast(StgInfoTable*,&Upd_frame_info));   \
67                 __frame->link = Su;                             \
68                 __frame->updatee = (StgClosure *)(target);      \
69                 PUSH_STD_CCCS(__frame);                         \
70                 Su = __frame;                                   \
71         }
72
73 /* -----------------------------------------------------------------------------
74    Entering CAFs
75
76    When a CAF is first entered, it creates a black hole in the heap,
77    and updates itself with an indirection to this new black hole.
78
79    We update the CAF with an indirection to a newly-allocated black
80    hole in the heap.  We also set the blocking queue on the newly
81    allocated black hole to be empty.
82
83    Why do we make a black hole in the heap when we enter a CAF?
84       
85        - for a  generational garbage collector, which needs a fast
86          test for whether an updatee is in an old generation or not
87
88        - for the parallel system, which can implement updates more
89          easily if the updatee is always in the heap. (allegedly).
90
91    When debugging, we maintain a separate CAF list so we can tell when
92    a CAF has been garbage collected.
93    -------------------------------------------------------------------------- */
94    
95 /* ToDo: only call newCAF when debugging. */
96
97 extern void newCAF(StgClosure*);
98
99 #define UPD_CAF(cafptr, bhptr)                                  \
100   {                                                             \
101     SET_INFO((StgInd *)cafptr,(const StgInfoTable*)&IND_STATIC_info);           \
102     ((StgInd *)cafptr)->indirectee   = (StgClosure *)(bhptr);   \
103     STGCALL1(newCAF,(StgClosure *)cafptr);                      \
104   }
105
106 /* -----------------------------------------------------------------------------
107    Update-related prototypes
108    -------------------------------------------------------------------------- */
109
110 DLL_IMPORT_RTS extern STGFUN(Upd_frame_entry);
111
112 extern DLL_IMPORT_DATA const StgInfoTable PAP_info;
113 DLL_IMPORT_RTS STGFUN(PAP_entry);
114
115 EXTFUN_RTS(stg_update_PAP);
116
117 extern DLL_IMPORT_DATA const StgInfoTable AP_UPD_info;
118 DLL_IMPORT_RTS STGFUN(AP_UPD_entry);
119
120 extern DLL_IMPORT_DATA const StgInfoTable raise_info;
121
122 #endif /* UPDATES_H */