Skip to content

Commit

Permalink
Don't lock or unlock script mutex if there is only one thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Lactozilla committed Oct 6, 2024
1 parent eaadf74 commit db85c42
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/Engine/Bytecode/ScriptManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit db85c42

Please sign in to comment.