From c334230bb00f3d9a7dff8fab2ed6d78cc29d18a0 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 15 Aug 2020 20:53:32 -0700 Subject: [PATCH] CONS_Printf: don't blit the screen during startup if this isn't the main thread --- src/console.c | 7 +++++++ src/i_threads.h | 2 ++ src/sdl/i_threads.c | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/console.c b/src/console.c index 11a7961e..7d82a1c4 100644 --- a/src/console.c +++ b/src/console.c @@ -1452,6 +1452,13 @@ void CONS_Printf(const char *fmt, ...) Unlock_state(); +#ifdef HAVE_THREADS + if (! I_on_main_thread()) + { + return; + } +#endif + // if not in display loop, force screen update if (startup) { diff --git a/src/i_threads.h b/src/i_threads.h index 45a3dcc3..2e02713a 100644 --- a/src/i_threads.h +++ b/src/i_threads.h @@ -27,6 +27,8 @@ void I_spawn_thread (const char *name, I_thread_fn, void *userdata); /* check in your thread whether to return early */ int I_thread_is_stopped (void); +int I_on_main_thread (void); + void I_lock_mutex (I_mutex *); void I_unlock_mutex (I_mutex); diff --git a/src/sdl/i_threads.c b/src/sdl/i_threads.c index b9927bab..e35e77ad 100644 --- a/src/sdl/i_threads.c +++ b/src/sdl/i_threads.c @@ -47,6 +47,8 @@ static I_mutex i_cond_pool_mutex; static SDL_atomic_t i_threads_running = {1}; +static SDL_threadID i_main_thread_id; + static Link Insert_link ( Link * head, @@ -197,6 +199,12 @@ I_thread_is_stopped (void) return ( ! SDL_AtomicGet(&i_threads_running) ); } +int +I_on_main_thread (void) +{ + return ( SDL_ThreadID() == i_main_thread_id ); +} + void I_start_threads (void) { @@ -211,6 +219,8 @@ I_start_threads (void) )){ abort(); } + + i_main_thread_id = SDL_ThreadID(); } void