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