summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorArmada <jules.blok@gmail.com>2013-06-15 13:21:57 +0200
committerArmada <jules.blok@gmail.com>2013-06-16 12:33:13 +0200
commitfc7099a9057ee962ea4fd43bf049396d86065cf0 (patch)
treeccdaf5bdbce24c9366fae3bbd1a988b4e1886d3b /Source/Core/VideoCommon
parent825c5ca09a999aa492bd1137babef5540ff5956e (diff)
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.
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.cpp9
-rw-r--r--Source/Core/VideoCommon/Src/TextureConversionShader.cpp9
-rw-r--r--Source/Core/VideoCommon/Src/VertexShaderGen.cpp9
3 files changed, 21 insertions, 6 deletions
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
index e6a0512d7f..100cac5976 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
@@ -6,6 +6,9 @@
#include <cmath>
#include <assert.h>
#include <locale.h>
+#ifdef __APPLE__
+ #include <xlocale.h>
+#endif
#include "LightingShaderGen.h"
#include "PixelShaderGen.h"
@@ -513,7 +516,8 @@ const char *WriteLocation(API_TYPE ApiType)
const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
{
- 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
BuildSwapModeTable(); // Needed for WriteStage
@@ -886,7 +890,8 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("PixelShader generator - buffer too small, canary has been eaten!");
- setlocale(LC_NUMERIC, ""); // restore locale
+ uselocale(old_locale); // restore locale
+ freelocale(locale);
return text;
}
diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
index 539d8799f9..573713a198 100644
--- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
+++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
@@ -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;
}
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
index f2f72251ef..aede4aa2bd 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
@@ -4,6 +4,9 @@
#include <math.h>
#include <locale.h>
+#ifdef __APPLE__
+ #include <xlocale.h>
+#endif
#include "NativeVertexFormat.h"
@@ -173,7 +176,8 @@ extern const char *WriteLocation(API_TYPE ApiType);
const char *GenerateVertexShaderCode(u32 components, 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
_assert_(bpmem.genMode.numtexgens == xfregs.numTexGen.numTexGens);
@@ -640,6 +644,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
- setlocale(LC_NUMERIC, ""); // restore locale
+ uselocale(old_locale); // restore locale
+ freelocale(locale);
return text;
}