[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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user