summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/lstate.c
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2019-07-12 05:23:52 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2019-07-28 15:17:48 +0200
commit45bd14b392622cb58e967a24e4652c510b3d43e4 (patch)
tree22bd2e5cafc2d82ecc4773f83de7f86515b4db43 /apps/plugins/lua/lstate.c
parent4beafe16fafc2e5c59734ef065a6f8d23766520d (diff)
downloadrockbox-45bd14b392622cb58e967a24e4652c510b3d43e4.tar.gz
rockbox-45bd14b392622cb58e967a24e4652c510b3d43e4.zip
Lua Add Emergency Garbage Collector
Derivative of work by RobertGabrielJakabosky http://lua-users.org/wiki/EmergencyGarbageCollector I've only implemented the not enough memory part and expanded this idea to adding a mechanism to signal the OOM condition of the plugin buffer which allows us to only grab the playback buffer after garbage collection fails (SO THE MUSIC KEEPS PLAYING AS LONG AS POSSIBLE) Change-Id: I684fb98b540ffc01f7ba324ab5b761ceb59b9f9b
Diffstat (limited to 'apps/plugins/lua/lstate.c')
-rw-r--r--apps/plugins/lua/lstate.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/apps/plugins/lua/lstate.c b/apps/plugins/lua/lstate.c
index 4313b83a0c..67921d84a1 100644
--- a/apps/plugins/lua/lstate.c
+++ b/apps/plugins/lua/lstate.c
@@ -119,6 +119,8 @@ static void close_state (lua_State *L) {
119lua_State *luaE_newthread (lua_State *L) { 119lua_State *luaE_newthread (lua_State *L) {
120 lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); 120 lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
121 luaC_link(L, obj2gco(L1), LUA_TTHREAD); 121 luaC_link(L, obj2gco(L1), LUA_TTHREAD);
122 setthvalue(L, L->top, L1); /* put thread on stack */
123 incr_top(L);
122 preinit_state(L1, G(L)); 124 preinit_state(L1, G(L));
123 stack_init(L1, L); /* init stack */ 125 stack_init(L1, L); /* init stack */
124 setobj2n(L, gt(L1), gt(L)); /* share table of globals */ 126 setobj2n(L, gt(L1), gt(L)); /* share table of globals */
@@ -126,7 +128,8 @@ lua_State *luaE_newthread (lua_State *L) {
126 L1->basehookcount = L->basehookcount; 128 L1->basehookcount = L->basehookcount;
127 L1->hook = L->hook; 129 L1->hook = L->hook;
128 resethookcount(L1); 130 resethookcount(L1);
129 lua_assert(iswhite(obj2gco(L1))); 131 lua_assert(!isdead(G(L), obj2gco(L1)));
132 L->top--; /* remove thread from stack */
130 return L1; 133 return L1;
131} 134}
132 135
@@ -160,6 +163,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
160 g->uvhead.u.l.prev = &g->uvhead; 163 g->uvhead.u.l.prev = &g->uvhead;
161 g->uvhead.u.l.next = &g->uvhead; 164 g->uvhead.u.l.next = &g->uvhead;
162 g->GCthreshold = 0; /* mark it as unfinished state */ 165 g->GCthreshold = 0; /* mark it as unfinished state */
166 g->estimate = 0;
163 g->strt.size = 0; 167 g->strt.size = 0;
164 g->strt.nuse = 0; 168 g->strt.nuse = 0;
165 g->strt.hash = NULL; 169 g->strt.hash = NULL;
@@ -167,6 +171,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
167 luaZ_initbuffer(L, &g->buff); 171 luaZ_initbuffer(L, &g->buff);
168 g->panic = NULL; 172 g->panic = NULL;
169 g->gcstate = GCSpause; 173 g->gcstate = GCSpause;
174 g->gcflags = GCFlagsNone;
170 g->rootgc = obj2gco(L); 175 g->rootgc = obj2gco(L);
171 g->sweepstrgc = 0; 176 g->sweepstrgc = 0;
172 g->sweepgc = &g->rootgc; 177 g->sweepgc = &g->rootgc;