From db85c428bd5bd38e958849ae0cc1ade3ab5e9428 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Sun, 6 Oct 2024 15:18:06 -0300 Subject: [PATCH] Don't lock or unlock script mutex if there is only one thread --- source/Engine/Bytecode/ScriptManager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/Engine/Bytecode/ScriptManager.cpp b/source/Engine/Bytecode/ScriptManager.cpp index 407ef1b..1bb7ef9 100644 --- a/source/Engine/Bytecode/ScriptManager.cpp +++ b/source/Engine/Bytecode/ScriptManager.cpp @@ -612,10 +612,14 @@ PUBLIC STATIC void ScriptManager::FreeValue(VMValue value) { // #region GlobalFuncs PUBLIC STATIC bool ScriptManager::Lock() { - return (SDL_LockMutex(GlobalLock) == 0); + if (ScriptManager::ThreadCount == 1) + return true; + + return SDL_LockMutex(GlobalLock) == 0; } PUBLIC STATIC void ScriptManager::Unlock() { - SDL_UnlockMutex(GlobalLock); + if (ScriptManager::ThreadCount > 1) + SDL_UnlockMutex(GlobalLock); } PUBLIC STATIC void ScriptManager::DefineMethod(VMThread* thread, ObjFunction* function, Uint32 hash) {