Nut/OS  4.10.3
API Reference
lgc.h
Go to the documentation of this file.
00001 /*
00002 ** $Id: lgc.h 2345 2008-10-10 11:52:25Z haraldkipp $
00003 ** Garbage Collector
00004 ** See Copyright Notice in lua.h
00005 */
00006 
00007 #ifndef lgc_h
00008 #define lgc_h
00009 
00010 
00011 #include <lua/lobject.h>
00012 
00013 
00014 /*
00015 ** Possible states of the Garbage Collector
00016 */
00017 #define GCSpause        0
00018 #define GCSpropagate    1
00019 #define GCSsweepstring  2
00020 #define GCSsweep        3
00021 #define GCSfinalize     4
00022 
00023 
00024 /*
00025 ** some userful bit tricks
00026 */
00027 #define resetbits(x,m)  ((x) &= cast(lu_byte, ~(m)))
00028 #define setbits(x,m)    ((x) |= (m))
00029 #define testbits(x,m)   ((x) & (m))
00030 #define bitmask(b)      (1<<(b))
00031 #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
00032 #define l_setbit(x,b)   setbits(x, bitmask(b))
00033 #define resetbit(x,b)   resetbits(x, bitmask(b))
00034 #define testbit(x,b)    testbits(x, bitmask(b))
00035 #define set2bits(x,b1,b2)       setbits(x, (bit2mask(b1, b2)))
00036 #define reset2bits(x,b1,b2)     resetbits(x, (bit2mask(b1, b2)))
00037 #define test2bits(x,b1,b2)      testbits(x, (bit2mask(b1, b2)))
00038 
00039 
00040 
00041 /*
00042 ** Layout for bit use in `marked' field:
00043 ** bit 0 - object is white (type 0)
00044 ** bit 1 - object is white (type 1)
00045 ** bit 2 - object is black
00046 ** bit 3 - for userdata: has been finalized
00047 ** bit 3 - for tables: has weak keys
00048 ** bit 4 - for tables: has weak values
00049 ** bit 5 - object is fixed (should not be collected)
00050 ** bit 6 - object is "super" fixed (only the main thread)
00051 */
00052 
00053 
00054 #define WHITE0BIT       0
00055 #define WHITE1BIT       1
00056 #define BLACKBIT        2
00057 #define FINALIZEDBIT    3
00058 #define KEYWEAKBIT      3
00059 #define VALUEWEAKBIT    4
00060 #define FIXEDBIT        5
00061 #define SFIXEDBIT       6
00062 #define WHITEBITS       bit2mask(WHITE0BIT, WHITE1BIT)
00063 
00064 
00065 #define iswhite(x)      test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
00066 #define isblack(x)      testbit((x)->gch.marked, BLACKBIT)
00067 #define isgray(x)       (!isblack(x) && !iswhite(x))
00068 
00069 #define otherwhite(g)   (g->currentwhite ^ WHITEBITS)
00070 #define isdead(g,v)     ((v)->gch.marked & otherwhite(g) & WHITEBITS)
00071 
00072 #define changewhite(x)  ((x)->gch.marked ^= WHITEBITS)
00073 #define gray2black(x)   l_setbit((x)->gch.marked, BLACKBIT)
00074 
00075 #define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))
00076 
00077 #define luaC_white(g)   cast(lu_byte, (g)->currentwhite & WHITEBITS)
00078 
00079 
00080 #define luaC_checkGC(L) { \
00081   condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
00082   if (G(L)->totalbytes >= G(L)->GCthreshold) \
00083         luaC_step(L); }
00084 
00085 
00086 #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p)))  \
00087         luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
00088 
00089 #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t)))  \
00090         luaC_barrierback(L,t); }
00091 
00092 #define luaC_objbarrier(L,p,o)  \
00093         { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
00094                 luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
00095 
00096 #define luaC_objbarriert(L,t,o)  \
00097    { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
00098 
00099 LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
00100 LUAI_FUNC void luaC_callGCTM (lua_State *L);
00101 LUAI_FUNC void luaC_freeall (lua_State *L);
00102 LUAI_FUNC void luaC_step (lua_State *L);
00103 LUAI_FUNC void luaC_fullgc (lua_State *L);
00104 LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
00105 LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
00106 LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
00107 LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
00108 
00109 
00110 #endif