summaryrefslogtreecommitdiff
path: root/libs/lua
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2018-03-19 01:33:13 +0100
committerRobin Gareus <robin@gareus.org>2019-10-29 05:45:43 +0100
commit78cf0e5235a4138cc1c118dd4c2e202320d74b21 (patch)
tree7ea838fe85f798d0ad56186eea5753a6615f93b0 /libs/lua
parent130211a4bdbaa5374a4fa5782125407764a32cfe (diff)
Customize Lua GC, add object-memory-lock API.
Add custom API to prevent Lua Objects from being garbage collected. This is intended to for Ardour LuaBridge bindings (~1MB Objects: tables, functions and userdata). The bindings are persistent and the gc can skip them in mark & sweep phases. This is a significant performance improvement for garbage collection. Note. The next version of Lua (5.4) will come with a generational-gc rather than an incremental, so extending the API at this point in time is acceptable.
Diffstat (limited to 'libs/lua')
-rw-r--r--libs/lua/lua-5.3.5/lgc.c15
-rw-r--r--libs/lua/lua-5.3.5/lstate.c1
-rw-r--r--libs/lua/lua-5.3.5/lstate.h1
-rw-r--r--libs/lua/lua-5.3.5/lua.h2
4 files changed, 16 insertions, 3 deletions
diff --git a/libs/lua/lua-5.3.5/lgc.c b/libs/lua/lua-5.3.5/lgc.c
index db4df82922..c4ea0e979d 100644
--- a/libs/lua/lua-5.3.5/lgc.c
+++ b/libs/lua/lua-5.3.5/lgc.c
@@ -210,8 +210,14 @@ GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {
GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));
o->marked = luaC_white(g);
o->tt = tt;
- o->next = g->allgc;
- g->allgc = o;
+ if (g->gcmlock) {
+ white2gray(o); /* gray forever */
+ o->next = g->fixedgc;
+ g->fixedgc = o;
+ } else {
+ o->next = g->allgc;
+ g->allgc = o;
+ }
return o;
}
@@ -1176,4 +1182,7 @@ void luaC_fullgc (lua_State *L, int isemergency) {
/* }====================================================== */
-
+LUA_API void lua_mlock (lua_State *L, int en) {
+ global_State *g = G(L);
+ g->gcmlock = en;
+}
diff --git a/libs/lua/lua-5.3.5/lstate.c b/libs/lua/lua-5.3.5/lstate.c
index c1a76643c3..06b505b6f3 100644
--- a/libs/lua/lua-5.3.5/lstate.c
+++ b/libs/lua/lua-5.3.5/lstate.c
@@ -328,6 +328,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
g->gcfinnum = 0;
g->gcpause = LUAI_GCPAUSE;
g->gcstepmul = LUAI_GCMUL;
+ g->gcmlock = 0;
for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
/* memory allocation error: free partial state */
diff --git a/libs/lua/lua-5.3.5/lstate.h b/libs/lua/lua-5.3.5/lstate.h
index 56b3741000..0e8e4d0277 100644
--- a/libs/lua/lua-5.3.5/lstate.h
+++ b/libs/lua/lua-5.3.5/lstate.h
@@ -162,6 +162,7 @@ typedef struct global_State {
unsigned int gcfinnum; /* number of finalizers to call in each GC step */
int gcpause; /* size of pause between successive GCs */
int gcstepmul; /* GC 'granularity' */
+ int gcmlock; /* memory lock new objects - fixedgc */
lua_CFunction panic; /* to be called in unprotected errors */
struct lua_State *mainthread;
const lua_Number *version; /* pointer to version number */
diff --git a/libs/lua/lua-5.3.5/lua.h b/libs/lua/lua-5.3.5/lua.h
index c236e36095..b56fa91c8a 100644
--- a/libs/lua/lua-5.3.5/lua.h
+++ b/libs/lua/lua-5.3.5/lua.h
@@ -311,6 +311,8 @@ LUA_API int (lua_isyieldable) (lua_State *L);
LUA_API int (lua_gc) (lua_State *L, int what, int data);
+LUA_API void (lua_mlock) (lua_State *L, int enable);
+
/*
** miscellaneous functions