1997-09-16 23:25:59 +04:00
|
|
|
/*
|
2005-06-07 22:53:45 +04:00
|
|
|
** $Id: lgc.h,v 2.13 2005/04/25 19:24:10 roberto Exp roberto $
|
1997-09-16 23:25:59 +04:00
|
|
|
** Garbage Collector
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lgc_h
|
|
|
|
#define lgc_h
|
|
|
|
|
|
|
|
|
|
|
|
#include "lobject.h"
|
|
|
|
|
|
|
|
|
2003-12-01 19:33:30 +03:00
|
|
|
/*
|
|
|
|
** Possible states of the Garbage Collector
|
|
|
|
*/
|
2004-08-30 17:44:44 +04:00
|
|
|
#define GCSpause 0
|
|
|
|
#define GCSpropagate 1
|
|
|
|
#define GCSsweepstring 2
|
|
|
|
#define GCSsweep 3
|
|
|
|
#define GCSfinalize 4
|
2003-12-01 19:33:30 +03:00
|
|
|
|
|
|
|
|
2003-11-17 22:50:05 +03:00
|
|
|
/*
|
2003-12-03 23:03:07 +03:00
|
|
|
** some userful bit tricks
|
|
|
|
*/
|
2003-11-19 22:41:57 +03:00
|
|
|
#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m)))
|
|
|
|
#define setbits(x,m) ((x) |= (m))
|
|
|
|
#define testbits(x,m) ((x) & (m))
|
2003-11-17 22:50:05 +03:00
|
|
|
#define bitmask(b) (1<<(b))
|
2003-11-19 22:41:57 +03:00
|
|
|
#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
|
2005-02-23 20:30:22 +03:00
|
|
|
#define l_setbit(x,b) setbits(x, bitmask(b))
|
2003-11-19 22:41:57 +03:00
|
|
|
#define resetbit(x,b) resetbits(x, bitmask(b))
|
|
|
|
#define testbit(x,b) testbits(x, bitmask(b))
|
|
|
|
#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2)))
|
|
|
|
#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2)))
|
|
|
|
#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2)))
|
2003-11-17 22:50:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Layout for bit use in `marked' field:
|
2004-08-25 00:12:06 +04:00
|
|
|
** bit 0 - object is white (type 0)
|
|
|
|
** bit 1 - object is white (type 1)
|
|
|
|
** bit 2 - object is black
|
|
|
|
** bit 3 - for userdata: has been finalized
|
|
|
|
** bit 3 - for tables: has weak keys
|
|
|
|
** bit 4 - for tables: has weak values
|
|
|
|
** bit 5 - object is fixed (should not be collected)
|
2005-02-10 16:25:02 +03:00
|
|
|
** bit 6 - object is "super" fixed (only the main thread)
|
2003-11-17 22:50:05 +03:00
|
|
|
*/
|
|
|
|
|
2005-02-10 16:25:02 +03:00
|
|
|
|
2003-12-03 23:03:07 +03:00
|
|
|
#define WHITE0BIT 0
|
|
|
|
#define WHITE1BIT 1
|
|
|
|
#define BLACKBIT 2
|
|
|
|
#define FINALIZEDBIT 3
|
|
|
|
#define KEYWEAKBIT 3
|
|
|
|
#define VALUEWEAKBIT 4
|
|
|
|
#define FIXEDBIT 5
|
2005-02-10 16:25:02 +03:00
|
|
|
#define SFIXEDBIT 6
|
|
|
|
#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
|
2003-12-03 23:03:07 +03:00
|
|
|
|
2003-11-17 22:50:05 +03:00
|
|
|
|
2003-12-09 19:56:11 +03:00
|
|
|
#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
|
|
|
|
#define isblack(x) testbit((x)->gch.marked, BLACKBIT)
|
2004-03-16 00:04:33 +03:00
|
|
|
#define isgray(x) (!isblack(x) && !iswhite(x))
|
2003-12-09 19:56:11 +03:00
|
|
|
|
2005-02-10 16:25:02 +03:00
|
|
|
#define otherwhite(g) (g->currentwhite ^ WHITEBITS)
|
|
|
|
#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS)
|
2003-12-09 19:56:11 +03:00
|
|
|
|
2005-02-10 16:25:02 +03:00
|
|
|
#define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
|
2005-02-23 20:30:22 +03:00
|
|
|
#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
|
2003-12-09 19:56:11 +03:00
|
|
|
|
|
|
|
#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
|
|
|
|
|
2005-02-10 16:25:02 +03:00
|
|
|
#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
|
2003-11-17 22:50:05 +03:00
|
|
|
|
|
|
|
|
2004-08-30 17:44:44 +04:00
|
|
|
#define luaC_checkGC(L) { if (G(L)->totalbytes >= G(L)->GCthreshold) \
|
2003-12-09 19:56:11 +03:00
|
|
|
luaC_step(L); }
|
|
|
|
|
|
|
|
|
2003-12-10 15:13:36 +03:00
|
|
|
#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
|
|
|
|
luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
|
2001-06-05 23:41:24 +04:00
|
|
|
|
2005-06-07 22:53:45 +04:00
|
|
|
#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \
|
|
|
|
luaC_barrierback(L,t); }
|
2004-08-10 23:17:23 +04:00
|
|
|
|
2003-12-09 19:56:11 +03:00
|
|
|
#define luaC_objbarrier(L,p,o) \
|
2003-12-10 15:13:36 +03:00
|
|
|
{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
|
|
|
|
luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
|
2001-06-05 23:41:24 +04:00
|
|
|
|
2005-06-07 22:53:45 +04:00
|
|
|
#define luaC_objbarriert(L,t,o) \
|
|
|
|
{ if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
|
2004-09-16 00:38:15 +04:00
|
|
|
|
2005-04-25 23:24:10 +04:00
|
|
|
LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
|
|
|
|
LUAI_FUNC void luaC_callGCTM (lua_State *L);
|
|
|
|
LUAI_FUNC void luaC_freeall (lua_State *L);
|
|
|
|
LUAI_FUNC void luaC_step (lua_State *L);
|
|
|
|
LUAI_FUNC void luaC_fullgc (lua_State *L);
|
|
|
|
LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
|
|
|
|
LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
|
|
|
|
LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
|
2005-06-07 22:53:45 +04:00
|
|
|
LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
|
1997-09-16 23:25:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|