[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / rts / Storage.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Storage.h,v 1.2 1998/12/02 13:28:58 simonm Exp $
3  *
4  * External Storage Manger Interface
5  *
6  * ---------------------------------------------------------------------------*/
7
8 #ifndef STORAGE_H
9 #define STORAGE_H
10
11 #include "Block.h"
12 #include "BlockAlloc.h"
13 #include "StoragePriv.h"
14
15 /* -----------------------------------------------------------------------------
16    Initialisation / De-initialisation
17    -------------------------------------------------------------------------- */
18
19 extern void initStorage(void);
20 extern void exitStorage(void);
21
22 /* -----------------------------------------------------------------------------
23    Generic allocation
24
25    StgPtr allocate(int n)       Allocates a chunk of contiguous store
26                                 n words long, returning a pointer to
27                                 the first word.  Always succeeds.
28
29    rtsBool doYouWantToGC(void)  Returns True if the storage manager is
30                                 ready to perform a GC, False otherwise.
31
32    lnat  allocated_bytes(void)  Returns the number of bytes allocated
33                                 via allocate() since the last GC.
34                                 Used in the reoprting of statistics.
35    -------------------------------------------------------------------------- */
36
37 extern StgPtr  allocate(nat n);
38 static inline rtsBool doYouWantToGC(void)
39 {
40   return (alloc_blocks >= alloc_blocks_lim);
41 }
42 extern lnat allocated_bytes(void);
43
44 /* -----------------------------------------------------------------------------
45    ExtendNursery(hp,hplim)      When hplim is reached, try to grab
46                                 some more allocation space.  Returns
47                                 False if the allocation space is
48                                 exhausted, and the application should
49                                 call GarbageCollect().
50   -------------------------------------------------------------------------- */
51
52 #define ExtendNursery(hp,hplim)                 \
53   (current_nursery->free = (P_)(hp)+1,          \
54    current_nursery->link == NULL ? rtsFalse :   \
55    (current_nursery = current_nursery->link,    \
56     OpenNursery(hp,hplim),                      \
57     rtsTrue))
58
59 extern void PleaseStopAllocating(void);
60
61 /* -----------------------------------------------------------------------------
62    Performing Garbage Collection
63
64    GarbageCollect(get_roots)    Performs a garbage collection.  
65                                 'get_roots' is called to find all the 
66                                 roots that the system knows about.
67
68    StgClosure                   Called by get_roots on each root.       
69    MarkRoot(StgClosure *p)      Returns the new location of the root.
70    -------------------------------------------------------------------------- */
71
72 extern void   GarbageCollect(void (*get_roots)(void));
73 extern StgClosure *MarkRoot(StgClosure *p);
74
75 /* -----------------------------------------------------------------------------
76    Generational garbage collection support
77
78    RecordMutable(StgPtr p)       Informs the garbage collector that a
79                                  previously immutable object has
80                                  become (permanently) mutable.  Used
81                                  by thawArray and similar.
82
83    UpdateWithIndirection(p1,p2)  Updates the object at p1 with an
84                                  indirection pointing to p2.  This is
85                                  normally called for objects in an old
86                                  generation (>0) when they are updated.
87
88    -------------------------------------------------------------------------- */
89
90 extern void RecordMutable(StgPtr p);
91 extern void UpdateWithIndirection(StgPtr p1, StgPtr p2);
92
93 /* -----------------------------------------------------------------------------
94    The CAF list - used to let us revert CAFs
95
96    -------------------------------------------------------------------------- */
97
98 StgCAF* enteredCAFs;
99
100 #endif STORAGE_H
101