Stable.h 2.18 KB
Newer Older
1
/* -----------------------------------------------------------------------------
2
 *
3
 * (c) The GHC Team, 1998-2004
4
 *
5
6
7
 * Stable Pointers: A stable pointer is represented as an index into
 * the stable pointer table in the low BITS_PER_WORD-8 bits with a
 * weight in the upper 8 bits.
8
 *
9
10
11
12
13
 * SUP: StgStablePtr used to be a synonym for StgWord, but stable pointers
 * are guaranteed to be void* on the C-side, so we have to do some occasional
 * casting. Size is not a matter, because StgWord is always the same size as
 * a void*.
 *
14
15
16
17
 * ---------------------------------------------------------------------------*/

#ifndef STABLE_H
#define STABLE_H
18

19
20
21
22
/* -----------------------------------------------------------------------------
   External C Interface
   -------------------------------------------------------------------------- */

23
EXTERN_INLINE StgPtr  deRefStablePtr(StgStablePtr stable_ptr);
24
25
extern void           freeStablePtr(StgStablePtr sp);
extern StgStablePtr   splitStablePtr(StgStablePtr sp);
26
extern StgStablePtr   getStablePtr(StgPtr p);
27
28
29
30
31
32

/* -----------------------------------------------------------------------------
   PRIVATE from here.
   -------------------------------------------------------------------------- */

typedef struct { 
33
  StgPtr  addr;			/* Haskell object, free list, or NULL */
34
  StgPtr  old;			/* old Haskell object, used during GC */
35
  StgWord ref;			/* used for reference counting */
36
  StgClosure *sn_obj;		/* the StableName object (or NULL) */
37
38
} snEntry;

sof's avatar
sof committed
39
extern DLL_IMPORT_RTS snEntry *stable_ptr_table;
40

41
42
extern void freeStablePtr(StgStablePtr sp);

43
EXTERN_INLINE
44
StgPtr deRefStablePtr(StgStablePtr sp)
45
{
46
47
    ASSERT(stable_ptr_table[(StgWord)sp].ref > 0);
    return stable_ptr_table[(StgWord)sp].addr;
48
}
49

50
extern void    initStablePtrTable    ( void );
51
extern void    exitStablePtrTable    ( void );
52
53
54
extern void    enlargeStablePtrTable ( void );
extern StgWord lookupStableName      ( StgPtr p );

55
56
extern void    markStablePtrTable    ( evac_fn evac, void *user );
extern void    threadStablePtrTable  ( evac_fn evac, void *user );
57
58
59
extern void    gcStablePtrTable      ( void );
extern void    updateStablePtrTable  ( rtsBool full );

60
61
extern void    exitHashTable         ( void );

62
#endif