From 9d046af47a0edf8566140082e0208ba389cc1645 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 15 May 2024 19:45:13 +0200 Subject: [PATCH] Update Lua allocator for sessions scripts * increase memory pool (bindings alone require 1.5 MB), and all session scripts have a shared memory pool. * use TLSF (like Lua DSP processors) - this fixes an issue with atomics (notably int62_t, temporal) on macOS and ARM, which need to be aligned. --- libs/ardour/ardour/luaproc.h | 1 - libs/ardour/ardour/session.h | 10 +++++++++- libs/ardour/session.cc | 8 +++++++- libs/ardour/wscript | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libs/ardour/ardour/luaproc.h b/libs/ardour/ardour/luaproc.h index 38d4961480..06478503f5 100644 --- a/libs/ardour/ardour/luaproc.h +++ b/libs/ardour/ardour/luaproc.h @@ -30,7 +30,6 @@ #include #include -#define USE_TLSF #ifdef USE_TLSF # include "pbd/tlsf.h" #else diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index fa61c27f32..5c510473b1 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -60,11 +60,15 @@ #include "pbd/event_loop.h" #include "pbd/file_archive.h" #include "pbd/rcu.h" -#include "pbd/reallocpool.h" #include "pbd/statefuldestructible.h" #include "pbd/signals.h" #include "pbd/undo.h" +#ifdef USE_TLSF +# include "pbd/tlsf.h" +#else +# include "pbd/reallocpool.h" +#endif #include "lua/luastate.h" #include "temporal/range.h" @@ -1652,7 +1656,11 @@ private: bool pending_abort; bool pending_auto_loop; +#ifdef USE_TLSF + PBD::TLSF _mempool; +#else PBD::ReallocPool _mempool; +#endif LuaState lua; mutable Glib::Threads::Mutex lua_lock; luabridge::LuaRef * _lua_run; diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 8dab2704e3..4839b1067b 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -258,8 +258,14 @@ Session::Session (AudioEngine &eng, , _last_roll_or_reversal_location (0) , _last_record_location (0) , pending_auto_loop (false) - , _mempool ("Session", 3145728) + , _mempool ("Session", 4194304) +#ifdef USE_TLSF + , lua (lua_newstate (&PBD::TLSF::lalloc, &_mempool)) +#elif defined USE_MALLOC + , lua (lua_newstate (true, true)) +#else , lua (lua_newstate (&PBD::ReallocPool::lalloc, &_mempool)) +#endif , _lua_run (0) , _lua_add (0) , _lua_del (0) diff --git a/libs/ardour/wscript b/libs/ardour/wscript index 777a0325f1..4743a4eb75 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -321,6 +321,8 @@ def configure(conf): atleast_version='0.24.2', mandatory=True) conf.define ('LV2_SUPPORT', 1) + conf.define ('USE_TLSF', 1) + # non-standard LV2 extention -- TODO: add option to disable?? if conf.is_defined ('HAVE_LV2_1_10_0'): conf.define ('LV2_EXTENDED', 1)