misc/liblua/lgc.h
author koda
Tue, 20 Jul 2010 05:37:58 +0200
changeset 3660 bc125bea5849
parent 2812 0a24853de796
child 10017 de822cd3df3a
permissions -rw-r--r--
complete settings page rework
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     1
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     2
** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     3
** Garbage Collector
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     4
** See Copyright Notice in lua.h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     5
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     6
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     7
#ifndef lgc_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     8
#define lgc_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     9
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    10
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    11
#include "lobject.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    12
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    13
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    14
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    15
** Possible states of the Garbage Collector
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    16
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    17
#define GCSpause	0
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    18
#define GCSpropagate	1
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    19
#define GCSsweepstring	2
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    20
#define GCSsweep	3
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    21
#define GCSfinalize	4
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    22
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    23
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    24
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    25
** some userful bit tricks
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    26
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    27
#define resetbits(x,m)	((x) &= cast(lu_byte, ~(m)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    28
#define setbits(x,m)	((x) |= (m))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    29
#define testbits(x,m)	((x) & (m))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    30
#define bitmask(b)	(1<<(b))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    31
#define bit2mask(b1,b2)	(bitmask(b1) | bitmask(b2))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    32
#define l_setbit(x,b)	setbits(x, bitmask(b))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    33
#define resetbit(x,b)	resetbits(x, bitmask(b))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    34
#define testbit(x,b)	testbits(x, bitmask(b))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    35
#define set2bits(x,b1,b2)	setbits(x, (bit2mask(b1, b2)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    36
#define reset2bits(x,b1,b2)	resetbits(x, (bit2mask(b1, b2)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    37
#define test2bits(x,b1,b2)	testbits(x, (bit2mask(b1, b2)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    38
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    39
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    40
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    41
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    42
** Layout for bit use in `marked' field:
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    43
** bit 0 - object is white (type 0)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    44
** bit 1 - object is white (type 1)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    45
** bit 2 - object is black
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    46
** bit 3 - for userdata: has been finalized
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    47
** bit 3 - for tables: has weak keys
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    48
** bit 4 - for tables: has weak values
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    49
** bit 5 - object is fixed (should not be collected)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    50
** bit 6 - object is "super" fixed (only the main thread)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    51
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    52
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    53
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    54
#define WHITE0BIT	0
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    55
#define WHITE1BIT	1
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    56
#define BLACKBIT	2
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    57
#define FINALIZEDBIT	3
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    58
#define KEYWEAKBIT	3
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    59
#define VALUEWEAKBIT	4
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    60
#define FIXEDBIT	5
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    61
#define SFIXEDBIT	6
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    62
#define WHITEBITS	bit2mask(WHITE0BIT, WHITE1BIT)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    63
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    64
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    65
#define iswhite(x)      test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    66
#define isblack(x)      testbit((x)->gch.marked, BLACKBIT)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    67
#define isgray(x)	(!isblack(x) && !iswhite(x))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    68
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    69
#define otherwhite(g)	(g->currentwhite ^ WHITEBITS)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    70
#define isdead(g,v)	((v)->gch.marked & otherwhite(g) & WHITEBITS)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    71
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    72
#define changewhite(x)	((x)->gch.marked ^= WHITEBITS)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    73
#define gray2black(x)	l_setbit((x)->gch.marked, BLACKBIT)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    74
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    75
#define valiswhite(x)	(iscollectable(x) && iswhite(gcvalue(x)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    76
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    77
#define luaC_white(g)	cast(lu_byte, (g)->currentwhite & WHITEBITS)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    78
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    79
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    80
#define luaC_checkGC(L) { \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    81
  condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    82
  if (G(L)->totalbytes >= G(L)->GCthreshold) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    83
	luaC_step(L); }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    84
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    85
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    86
#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p)))  \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    87
	luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    88
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    89
#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t)))  \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    90
	luaC_barrierback(L,t); }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    91
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    92
#define luaC_objbarrier(L,p,o)  \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    93
	{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    94
		luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    95
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    96
#define luaC_objbarriert(L,t,o)  \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    97
   { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    98
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    99
LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   100
LUAI_FUNC void luaC_callGCTM (lua_State *L);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   101
LUAI_FUNC void luaC_freeall (lua_State *L);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   102
LUAI_FUNC void luaC_step (lua_State *L);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   103
LUAI_FUNC void luaC_fullgc (lua_State *L);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   104
LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   105
LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   106
LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   107
LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   108
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   109
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   110
#endif