diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-07-11 12:53:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-07-11 12:53:29 -0300 |
commit | 3ca9af51a4f060cf2178901a67a21f8269af3224 (patch) | |
tree | 4f1bb541280aa8b4960b16d0925eca60adb2b1a8 /lstate.c | |
parent | c7b89dd28097296bbc14d9b47b4cea72514b2b76 (diff) | |
download | lua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.gz lua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.bz2 lua-3ca9af51a4f060cf2178901a67a21f8269af3224.zip |
emergency garbage collector (core forces a GC when allocation fails)
Diffstat (limited to 'lstate.c')
-rw-r--r-- | lstate.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.35 2005/10/06 20:46:25 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.36 2006/05/24 14:15:50 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include "lua.h" | 13 | #include "lua.h" |
14 | 14 | ||
15 | #include "lapi.h" | ||
15 | #include "ldebug.h" | 16 | #include "ldebug.h" |
16 | #include "ldo.h" | 17 | #include "ldo.h" |
17 | #include "lfunc.h" | 18 | #include "lfunc.h" |
@@ -71,8 +72,8 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
71 | global_State *g = G(L); | 72 | global_State *g = G(L); |
72 | UNUSED(ud); | 73 | UNUSED(ud); |
73 | stack_init(L, L); /* init stack */ | 74 | stack_init(L, L); /* init stack */ |
74 | sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ | 75 | sethvalue(L, gt(L), luaH_new(L)); /* table of globals */ |
75 | sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ | 76 | sethvalue(L, registry(L), luaH_new(L)); /* registry */ |
76 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ | 77 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ |
77 | luaT_init(L); | 78 | luaT_init(L); |
78 | luaX_init(L); | 79 | luaX_init(L); |
@@ -116,9 +117,14 @@ static void close_state (lua_State *L) { | |||
116 | } | 117 | } |
117 | 118 | ||
118 | 119 | ||
119 | lua_State *luaE_newthread (lua_State *L) { | 120 | LUA_API lua_State *lua_newthread (lua_State *L) { |
120 | lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); | 121 | lua_State *L1; |
122 | lua_lock(L); | ||
123 | luaC_checkGC(L); | ||
124 | L1 = tostate(luaM_malloc(L, state_size(lua_State))); | ||
121 | luaC_link(L, obj2gco(L1), LUA_TTHREAD); | 125 | luaC_link(L, obj2gco(L1), LUA_TTHREAD); |
126 | setthvalue(L, L->top, L1); | ||
127 | api_incr_top(L); | ||
122 | preinit_state(L1, G(L)); | 128 | preinit_state(L1, G(L)); |
123 | stack_init(L1, L); /* init stack */ | 129 | stack_init(L1, L); /* init stack */ |
124 | setobj2n(L, gt(L1), gt(L)); /* share table of globals */ | 130 | setobj2n(L, gt(L1), gt(L)); /* share table of globals */ |
@@ -127,6 +133,8 @@ lua_State *luaE_newthread (lua_State *L) { | |||
127 | L1->hook = L->hook; | 133 | L1->hook = L->hook; |
128 | resethookcount(L1); | 134 | resethookcount(L1); |
129 | lua_assert(iswhite(obj2gco(L1))); | 135 | lua_assert(iswhite(obj2gco(L1))); |
136 | lua_unlock(L); | ||
137 | luai_userstatethread(L, L1); | ||
130 | return L1; | 138 | return L1; |
131 | } | 139 | } |
132 | 140 | ||
@@ -152,6 +160,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
152 | L->tt = LUA_TTHREAD; | 160 | L->tt = LUA_TTHREAD; |
153 | g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); | 161 | g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); |
154 | L->marked = luaC_white(g); | 162 | L->marked = luaC_white(g); |
163 | g->emergencygc = 0; | ||
155 | set2bits(L->marked, FIXEDBIT, SFIXEDBIT); | 164 | set2bits(L->marked, FIXEDBIT, SFIXEDBIT); |
156 | preinit_state(L, g); | 165 | preinit_state(L, g); |
157 | g->frealloc = f; | 166 | g->frealloc = f; |
@@ -159,7 +168,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
159 | g->mainthread = L; | 168 | g->mainthread = L; |
160 | g->uvhead.u.l.prev = &g->uvhead; | 169 | g->uvhead.u.l.prev = &g->uvhead; |
161 | g->uvhead.u.l.next = &g->uvhead; | 170 | g->uvhead.u.l.next = &g->uvhead; |
162 | g->GCthreshold = 0; /* mark it as unfinished state */ | 171 | g->GCthreshold = MAX_LUMEM; /* no GC while building state */ |
163 | g->strt.size = 0; | 172 | g->strt.size = 0; |
164 | g->strt.nuse = 0; | 173 | g->strt.nuse = 0; |
165 | g->strt.hash = NULL; | 174 | g->strt.hash = NULL; |