mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Fix Lua scripting synchronization
For several years now, the lua script lock has been completely broken. This commit fixes the main issue (creation of a temporary rather than scoped object), and fixes a subsequent deadlock issue caused by nested script API calls by adding support for recursive mutexes.
This commit is contained in:
parent
d198e420ec
commit
52e5b513ed
5 changed files with 57 additions and 17 deletions
|
@ -67,10 +67,11 @@ public:
|
|||
ScriptApiBase
|
||||
*/
|
||||
|
||||
ScriptApiBase::ScriptApiBase()
|
||||
ScriptApiBase::ScriptApiBase() :
|
||||
m_luastackmutex(true)
|
||||
{
|
||||
#ifdef SCRIPTAPI_LOCK_DEBUG
|
||||
m_locked = false;
|
||||
m_lock_recursion_count = 0;
|
||||
#endif
|
||||
|
||||
m_luastack = luaL_newstate();
|
||||
|
@ -157,9 +158,14 @@ void ScriptApiBase::loadScript(const std::string &script_path)
|
|||
// - runs the callbacks
|
||||
// - replaces the table and arguments with the return value,
|
||||
// computed depending on mode
|
||||
// This function must only be called with scriptlock held (i.e. inside of a
|
||||
// code block with SCRIPTAPI_PRECHECKHEADER declared)
|
||||
void ScriptApiBase::runCallbacksRaw(int nargs,
|
||||
RunCallbacksMode mode, const char *fxn)
|
||||
{
|
||||
#ifdef SCRIPTAPI_LOCK_DEBUG
|
||||
assert(m_lock_recursion_count > 0);
|
||||
#endif
|
||||
lua_State *L = getStack();
|
||||
FATAL_ERROR_IF(lua_gettop(L) < nargs + 1, "Not enough arguments");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue