diff --git a/src/os/os2/os2.cpp b/src/os/os2/os2.cpp index 5d35eca451..0b2d8de6a5 100644 --- a/src/os/os2/os2.cpp +++ b/src/os/os2/os2.cpp @@ -223,3 +223,4 @@ void PerThreadSetupInit() { } bool IsMainThread() { return false; } bool IsNonMainThread() { return false; } bool IsGameThread() { return false; } +bool IsNonGameThread() { return false; } diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index 2479c6fe8c..0f53fb1727 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -380,6 +380,15 @@ bool IsGameThread() { #if !defined(NO_THREADS) return game_thread == pthread_self(); +#else + return true; +#endif +} + +bool IsNonGameThread() +{ +#if !defined(NO_THREADS) + return game_thread != pthread_self(); #else return false; #endif diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index afef3313c7..70716e8f3b 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -757,6 +757,11 @@ bool IsGameThread() return game_thread_id == GetCurrentThreadId(); } +bool IsNonGameThread() +{ + return game_thread_id != GetCurrentThreadId(); +} + static std::map _thread_name_map; static std::mutex _thread_name_map_mutex; diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index e28f8b0b76..98bcd02a4c 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -386,7 +386,7 @@ void NORETURN SlError(StringID string, const char *extra_msg, bool already_mallo str = already_malloced ? const_cast(extra_msg) : stredup(extra_msg); } - if (IsNonMainThread() && !IsGameThread() && _sl.action != SLA_SAVE) { + if (IsNonMainThread() && IsNonGameThread() && _sl.action != SLA_SAVE) { throw ThreadSlErrorException{ string, extra_msg }; } diff --git a/src/thread.h b/src/thread.h index 7860bfaf78..66581b7573 100644 --- a/src/thread.h +++ b/src/thread.h @@ -76,6 +76,11 @@ bool IsNonMainThread(); */ bool IsGameThread(); +/** + * @return true if the current thread is definitely a "non-game" thread. If in doubt returns false. + */ +bool IsNonGameThread(); + /** * Start a new thread. diff --git a/src/video/null_v.cpp b/src/video/null_v.cpp index e5fc79faee..78b660258f 100644 --- a/src/video/null_v.cpp +++ b/src/video/null_v.cpp @@ -11,6 +11,7 @@ #include "../gfx_func.h" #include "../blitter/factory.hpp" #include "../window_func.h" +#include "../thread.h" #include "null_v.h" #include "../safeguards.h" @@ -48,6 +49,7 @@ void VideoDriver_Null::MakeDirty(int left, int top, int width, int height) {} void VideoDriver_Null::MainLoop() { + SetSelfAsGameThread(); if (this->until_exit) { while (!_exit_game) { ::GameLoop();