release.sh changes & fixes
[minix3.git] / external / mit / lua / dist / src / lgc.h
blob212e1f202acccfdb3b48a93567a2361d03c0e6b3
1 /* $NetBSD: lgc.h,v 1.1.1.2 2012/03/15 00:08:10 alnsn Exp $ */
3 /*
4 ** $Id: lgc.h,v 1.1.1.2 2012/03/15 00:08:10 alnsn Exp $
5 ** Garbage Collector
6 ** See Copyright Notice in lua.h
7 */
9 #ifndef lgc_h
10 #define lgc_h
13 #include "lobject.h"
17 ** Possible states of the Garbage Collector
19 #define GCSpause 0
20 #define GCSpropagate 1
21 #define GCSsweepstring 2
22 #define GCSsweep 3
23 #define GCSfinalize 4
27 ** some userful bit tricks
29 #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m)))
30 #define setbits(x,m) ((x) |= (m))
31 #define testbits(x,m) ((x) & (m))
32 #define bitmask(b) (1<<(b))
33 #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
34 #define l_setbit(x,b) setbits(x, bitmask(b))
35 #define resetbit(x,b) resetbits(x, bitmask(b))
36 #define testbit(x,b) testbits(x, bitmask(b))
37 #define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2)))
38 #define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2)))
39 #define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2)))
44 ** Layout for bit use in `marked' field:
45 ** bit 0 - object is white (type 0)
46 ** bit 1 - object is white (type 1)
47 ** bit 2 - object is black
48 ** bit 3 - for userdata: has been finalized
49 ** bit 3 - for tables: has weak keys
50 ** bit 4 - for tables: has weak values
51 ** bit 5 - object is fixed (should not be collected)
52 ** bit 6 - object is "super" fixed (only the main thread)
56 #define WHITE0BIT 0
57 #define WHITE1BIT 1
58 #define BLACKBIT 2
59 #define FINALIZEDBIT 3
60 #define KEYWEAKBIT 3
61 #define VALUEWEAKBIT 4
62 #define FIXEDBIT 5
63 #define SFIXEDBIT 6
64 #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
67 #define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
68 #define isblack(x) testbit((x)->gch.marked, BLACKBIT)
69 #define isgray(x) (!isblack(x) && !iswhite(x))
71 #define otherwhite(g) (g->currentwhite ^ WHITEBITS)
72 #define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS)
74 #define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
75 #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
77 #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
79 #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
82 #define luaC_checkGC(L) { \
83 condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
84 if (G(L)->totalbytes >= G(L)->GCthreshold) \
85 luaC_step(L); }
88 #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
89 luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
91 #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \
92 luaC_barrierback(L,t); }
94 #define luaC_objbarrier(L,p,o) \
95 { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
96 luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
98 #define luaC_objbarriert(L,t,o) \
99 { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
101 LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
102 LUAI_FUNC void luaC_callGCTM (lua_State *L);
103 LUAI_FUNC void luaC_freeall (lua_State *L);
104 LUAI_FUNC void luaC_step (lua_State *L);
105 LUAI_FUNC void luaC_fullgc (lua_State *L);
106 LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
107 LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
108 LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
109 LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
112 #endif