summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/lapi.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/lapi.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/lapi.c')
-rw-r--r--apps/plugins/lua/lapi.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/apps/plugins/lua/lapi.c b/apps/plugins/lua/lapi.c
index 487d6b173a..6426cd94a9 100644
--- a/apps/plugins/lua/lapi.c
+++ b/apps/plugins/lua/lapi.c
@@ -547,7 +547,9 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
547 lua_lock(L); 547 lua_lock(L);
548 t = index2adr(L, idx); 548 t = index2adr(L, idx);
549 api_checkvalidindex(L, t); 549 api_checkvalidindex(L, t);
550 fixedstack(L);
550 setsvalue(L, &key, luaS_new(L, k)); 551 setsvalue(L, &key, luaS_new(L, k));
552 unfixedstack(L);
551 luaV_gettable(L, t, &key, L->top); 553 luaV_gettable(L, t, &key, L->top);
552 api_incr_top(L); 554 api_incr_top(L);
553 lua_unlock(L); 555 lua_unlock(L);
@@ -656,14 +658,14 @@ LUA_API void lua_settable (lua_State *L, int idx) {
656 658
657LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { 659LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
658 StkId t; 660 StkId t;
659 TValue key;
660 lua_lock(L); 661 lua_lock(L);
661 api_checknelems(L, 1); 662 api_checknelems(L, 1);
662 t = index2adr(L, idx); 663 t = index2adr(L, idx);
663 api_checkvalidindex(L, t); 664 api_checkvalidindex(L, t);
664 setsvalue(L, &key, luaS_new(L, k)); 665 setsvalue2s(L, L->top, luaS_new(L, k));
665 luaV_settable(L, t, &key, L->top - 1); 666 api_incr_top(L);
666 L->top--; /* pop value */ 667 luaV_settable(L, t, L->top - 1, L->top - 2);
668 L->top -= 2; /* pop key and value */
667 lua_unlock(L); 669 lua_unlock(L);
668} 670}
669 671
@@ -674,7 +676,9 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
674 api_checknelems(L, 2); 676 api_checknelems(L, 2);
675 t = index2adr(L, idx); 677 t = index2adr(L, idx);
676 api_check(L, ttistable(t)); 678 api_check(L, ttistable(t));
679 fixedstack(L);
677 setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); 680 setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
681 unfixedstack(L);
678 luaC_barriert(L, hvalue(t), L->top-1); 682 luaC_barriert(L, hvalue(t), L->top-1);
679 L->top -= 2; 683 L->top -= 2;
680 lua_unlock(L); 684 lua_unlock(L);
@@ -687,7 +691,9 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
687 api_checknelems(L, 1); 691 api_checknelems(L, 1);
688 o = index2adr(L, idx); 692 o = index2adr(L, idx);
689 api_check(L, ttistable(o)); 693 api_check(L, ttistable(o));
694 fixedstack(L);
690 setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); 695 setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);
696 unfixedstack(L);
691 luaC_barriert(L, hvalue(o), L->top-1); 697 luaC_barriert(L, hvalue(o), L->top-1);
692 L->top--; 698 L->top--;
693 lua_unlock(L); 699 lua_unlock(L);
@@ -903,11 +909,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
903 g = G(L); 909 g = G(L);
904 switch (what) { 910 switch (what) {
905 case LUA_GCSTOP: { 911 case LUA_GCSTOP: {
906 g->GCthreshold = MAX_LUMEM; 912 set_block_gc(L);
907 break; 913 break;
908 } 914 }
909 case LUA_GCRESTART: { 915 case LUA_GCRESTART: {
910 g->GCthreshold = g->totalbytes; 916 unset_block_gc(L);
911 break; 917 break;
912 } 918 }
913 case LUA_GCCOLLECT: { 919 case LUA_GCCOLLECT: {
@@ -924,6 +930,10 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
924 break; 930 break;
925 } 931 }
926 case LUA_GCSTEP: { 932 case LUA_GCSTEP: {
933 if(is_block_gc(L)) {
934 res = 1; /* gc is block so we need to pretend that the collection cycle finished. */
935 break;
936 }
927 lu_mem a = (cast(lu_mem, data) << 10); 937 lu_mem a = (cast(lu_mem, data) << 10);
928 if (a <= g->totalbytes) 938 if (a <= g->totalbytes)
929 g->GCthreshold = g->totalbytes - a; 939 g->GCthreshold = g->totalbytes - a;