Thread: Adjust checks for whether current thread is the game thread
This commit is contained in:
@@ -223,3 +223,4 @@ void PerThreadSetupInit() { }
|
|||||||
bool IsMainThread() { return false; }
|
bool IsMainThread() { return false; }
|
||||||
bool IsNonMainThread() { return false; }
|
bool IsNonMainThread() { return false; }
|
||||||
bool IsGameThread() { return false; }
|
bool IsGameThread() { return false; }
|
||||||
|
bool IsNonGameThread() { return false; }
|
||||||
|
@@ -380,6 +380,15 @@ bool IsGameThread()
|
|||||||
{
|
{
|
||||||
#if !defined(NO_THREADS)
|
#if !defined(NO_THREADS)
|
||||||
return game_thread == pthread_self();
|
return game_thread == pthread_self();
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsNonGameThread()
|
||||||
|
{
|
||||||
|
#if !defined(NO_THREADS)
|
||||||
|
return game_thread != pthread_self();
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
@@ -757,6 +757,11 @@ bool IsGameThread()
|
|||||||
return game_thread_id == GetCurrentThreadId();
|
return game_thread_id == GetCurrentThreadId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsNonGameThread()
|
||||||
|
{
|
||||||
|
return game_thread_id != GetCurrentThreadId();
|
||||||
|
}
|
||||||
|
|
||||||
static std::map<DWORD, std::string> _thread_name_map;
|
static std::map<DWORD, std::string> _thread_name_map;
|
||||||
static std::mutex _thread_name_map_mutex;
|
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);
|
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 };
|
throw ThreadSlErrorException{ string, extra_msg };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -76,6 +76,11 @@ bool IsNonMainThread();
|
|||||||
*/
|
*/
|
||||||
bool IsGameThread();
|
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.
|
* Start a new thread.
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#include "../gfx_func.h"
|
#include "../gfx_func.h"
|
||||||
#include "../blitter/factory.hpp"
|
#include "../blitter/factory.hpp"
|
||||||
#include "../window_func.h"
|
#include "../window_func.h"
|
||||||
|
#include "../thread.h"
|
||||||
#include "null_v.h"
|
#include "null_v.h"
|
||||||
|
|
||||||
#include "../safeguards.h"
|
#include "../safeguards.h"
|
||||||
@@ -48,6 +49,7 @@ void VideoDriver_Null::MakeDirty(int left, int top, int width, int height) {}
|
|||||||
|
|
||||||
void VideoDriver_Null::MainLoop()
|
void VideoDriver_Null::MainLoop()
|
||||||
{
|
{
|
||||||
|
SetSelfAsGameThread();
|
||||||
if (this->until_exit) {
|
if (this->until_exit) {
|
||||||
while (!_exit_game) {
|
while (!_exit_game) {
|
||||||
::GameLoop();
|
::GameLoop();
|
||||||
|
Reference in New Issue
Block a user