mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Set the locale per-thread instead of globally when generating shaders. Add cross-compatible versions of newlocale, uselocale and freelocale.
This commit fixes a rare race condition when generating shaders because setlocale is global.
This commit is contained in:
@ -6,6 +6,9 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <locale.h>
|
||||
#ifdef __APPLE__
|
||||
#include <xlocale.h>
|
||||
#endif
|
||||
|
||||
#include "TextureConversionShader.h"
|
||||
#include "TextureDecoder.h"
|
||||
@ -804,7 +807,8 @@ void WriteZ24Encoder(char* p, API_TYPE ApiType)
|
||||
|
||||
const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
|
||||
{
|
||||
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
||||
locale_t locale = newlocale(LC_NUMERIC_MASK, "C", NULL); // New locale for compilation
|
||||
locale_t old_locale = uselocale(locale); // Apply the locale for this thread
|
||||
text[sizeof(text) - 1] = 0x7C; // canary
|
||||
|
||||
char *p = text;
|
||||
@ -888,7 +892,8 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
|
||||
if (text[sizeof(text) - 1] != 0x7C)
|
||||
PanicAlert("TextureConversionShader generator - buffer too small, canary has been eaten!");
|
||||
|
||||
setlocale(LC_NUMERIC, ""); // restore locale
|
||||
uselocale(old_locale); // restore locale
|
||||
freelocale(locale);
|
||||
return text;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user