From de63bb18a68d1ff386fb43bac7c36336f0e85bd5 Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Tue, 10 Feb 2026 00:18:54 +0900 Subject: [PATCH] [Base] Use function-local static for global_mutex File-scope static initialization order is undefined across translation units. Code that acquires the global critical region during early startup could run before the mutex constructor, operating on uninitialized state. A function-local static is constructed on first use, guaranteeing the mutex is initialized before any caller can access it. --- src/xenia/base/mutex.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/xenia/base/mutex.cc b/src/xenia/base/mutex.cc index b975e4bc3..4fc37de9b 100644 --- a/src/xenia/base/mutex.cc +++ b/src/xenia/base/mutex.cc @@ -65,9 +65,9 @@ bool xe_fast_mutex::try_lock() { return TryEnterCriticalSection(fast_crit(this)); } #endif -// chrispy: moved this out of body of function to eliminate the initialization -// guards -static global_mutex_type global_mutex; -global_mutex_type& global_critical_region::mutex() { return global_mutex; } +global_mutex_type& global_critical_region::mutex() { + static global_mutex_type global_mutex; + return global_mutex; +} } // namespace xe