Thread: Adjust checks for whether current thread is the game thread

pull/288/head
Jonathan G Rennison 3 years ago
parent 4577b547ea
commit 87948d8029

@ -223,3 +223,4 @@ void PerThreadSetupInit() { }
bool IsMainThread() { return false; }
bool IsNonMainThread() { return false; }
bool IsGameThread() { return false; }
bool IsNonGameThread() { return false; }

@ -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

@ -757,6 +757,11 @@ bool IsGameThread()
return game_thread_id == GetCurrentThreadId();
}
bool IsNonGameThread()
{
return game_thread_id != GetCurrentThreadId();
}
static std::map<DWORD, std::string> _thread_name_map;
static std::mutex _thread_name_map_mutex;

@ -386,7 +386,7 @@ void NORETURN SlError(StringID string, const char *extra_msg, bool already_mallo
str = already_malloced ? const_cast<char *>(extra_msg) : stredup(extra_msg);
}
if (IsNonMainThread() && !IsGameThread() && _sl.action != SLA_SAVE) {
if (IsNonMainThread() && IsNonGameThread() && _sl.action != SLA_SAVE) {
throw ThreadSlErrorException{ string, extra_msg };
}

@ -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.

@ -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();

Loading…
Cancel
Save