Mercurial > vba-clojure
diff src/lua/lgc.h @ 11:27763b933818
raise lua sources up one level
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 11:07:39 -0600 |
parents | src/lua/src/lgc.h@f9f4f1b99eed |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/lua/lgc.h Sat Mar 03 11:07:39 2012 -0600 1.3 @@ -0,0 +1,110 @@ 1.4 +/* 1.5 +** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ 1.6 +** Garbage Collector 1.7 +** See Copyright Notice in lua.h 1.8 +*/ 1.9 + 1.10 +#ifndef lgc_h 1.11 +#define lgc_h 1.12 + 1.13 + 1.14 +#include "lobject.h" 1.15 + 1.16 + 1.17 +/* 1.18 +** Possible states of the Garbage Collector 1.19 +*/ 1.20 +#define GCSpause 0 1.21 +#define GCSpropagate 1 1.22 +#define GCSsweepstring 2 1.23 +#define GCSsweep 3 1.24 +#define GCSfinalize 4 1.25 + 1.26 + 1.27 +/* 1.28 +** some userful bit tricks 1.29 +*/ 1.30 +#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) 1.31 +#define setbits(x,m) ((x) |= (m)) 1.32 +#define testbits(x,m) ((x) & (m)) 1.33 +#define bitmask(b) (1<<(b)) 1.34 +#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 1.35 +#define l_setbit(x,b) setbits(x, bitmask(b)) 1.36 +#define resetbit(x,b) resetbits(x, bitmask(b)) 1.37 +#define testbit(x,b) testbits(x, bitmask(b)) 1.38 +#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) 1.39 +#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) 1.40 +#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) 1.41 + 1.42 + 1.43 + 1.44 +/* 1.45 +** Layout for bit use in `marked' field: 1.46 +** bit 0 - object is white (type 0) 1.47 +** bit 1 - object is white (type 1) 1.48 +** bit 2 - object is black 1.49 +** bit 3 - for userdata: has been finalized 1.50 +** bit 3 - for tables: has weak keys 1.51 +** bit 4 - for tables: has weak values 1.52 +** bit 5 - object is fixed (should not be collected) 1.53 +** bit 6 - object is "super" fixed (only the main thread) 1.54 +*/ 1.55 + 1.56 + 1.57 +#define WHITE0BIT 0 1.58 +#define WHITE1BIT 1 1.59 +#define BLACKBIT 2 1.60 +#define FINALIZEDBIT 3 1.61 +#define KEYWEAKBIT 3 1.62 +#define VALUEWEAKBIT 4 1.63 +#define FIXEDBIT 5 1.64 +#define SFIXEDBIT 6 1.65 +#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 1.66 + 1.67 + 1.68 +#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) 1.69 +#define isblack(x) testbit((x)->gch.marked, BLACKBIT) 1.70 +#define isgray(x) (!isblack(x) && !iswhite(x)) 1.71 + 1.72 +#define otherwhite(g) (g->currentwhite ^ WHITEBITS) 1.73 +#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) 1.74 + 1.75 +#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) 1.76 +#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) 1.77 + 1.78 +#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) 1.79 + 1.80 +#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 1.81 + 1.82 + 1.83 +#define luaC_checkGC(L) { \ 1.84 + condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ 1.85 + if (G(L)->totalbytes >= G(L)->GCthreshold) \ 1.86 + luaC_step(L); } 1.87 + 1.88 + 1.89 +#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ 1.90 + luaC_barrierf(L,obj2gco(p),gcvalue(v)); } 1.91 + 1.92 +#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ 1.93 + luaC_barrierback(L,t); } 1.94 + 1.95 +#define luaC_objbarrier(L,p,o) \ 1.96 + { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ 1.97 + luaC_barrierf(L,obj2gco(p),obj2gco(o)); } 1.98 + 1.99 +#define luaC_objbarriert(L,t,o) \ 1.100 + { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } 1.101 + 1.102 +LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); 1.103 +LUAI_FUNC void luaC_callGCTM (lua_State *L); 1.104 +LUAI_FUNC void luaC_freeall (lua_State *L); 1.105 +LUAI_FUNC void luaC_step (lua_State *L); 1.106 +LUAI_FUNC void luaC_fullgc (lua_State *L); 1.107 +LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); 1.108 +LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); 1.109 +LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); 1.110 +LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); 1.111 + 1.112 + 1.113 +#endif