Stable.h 2.33 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
23
24
25
/* -----------------------------------------------------------------------------
   External C Interface
   -------------------------------------------------------------------------- */

extern StgPtr         deRefStablePtr(StgStablePtr stable_ptr);
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);

sof's avatar
sof committed
43
44
#if defined(__GNUC__)
# ifndef RTS_STABLE_C
45
extern inline
sof's avatar
sof committed
46
# endif
47
StgPtr deRefStablePtr(StgStablePtr sp)
48
{
49
50
    ASSERT(stable_ptr_table[(StgWord)sp].ref > 0);
    return stable_ptr_table[(StgWord)sp].addr;
51
}
sof's avatar
sof committed
52
53
54
55
#else
/* No support for 'extern inline' */
extern StgPtr deRefStablePtr(StgStablePtr sp);
#endif
56

57
extern void    initStablePtrTable    ( void );
58
extern void    exitStablePtrTable    ( void );
59
60
61
extern void    enlargeStablePtrTable ( void );
extern StgWord lookupStableName      ( StgPtr p );

62
63
extern void    markStablePtrTable    ( evac_fn evac, void *user );
extern void    threadStablePtrTable  ( evac_fn evac, void *user );
64
65
66
extern void    gcStablePtrTable      ( void );
extern void    updateStablePtrTable  ( rtsBool full );

67
68
extern void    exitHashTable         ( void );

69
#endif