GRegex: fix thread-unsafe initialiser code

This commit is contained in:
Ryan Lortie 2011-09-09 19:54:06 -04:00
parent f1494c156d
commit 066c7b8121

View File

@ -1187,7 +1187,7 @@ g_regex_new (const gchar *pattern,
gint erroffset; gint erroffset;
gint errcode; gint errcode;
gboolean optimize = FALSE; gboolean optimize = FALSE;
static gboolean initialized = FALSE; static gsize initialised;
unsigned long int pcre_compile_options; unsigned long int pcre_compile_options;
g_return_val_if_fail (pattern != NULL, NULL); g_return_val_if_fail (pattern != NULL, NULL);
@ -1195,7 +1195,7 @@ g_regex_new (const gchar *pattern,
g_return_val_if_fail ((compile_options & ~G_REGEX_COMPILE_MASK) == 0, NULL); g_return_val_if_fail ((compile_options & ~G_REGEX_COMPILE_MASK) == 0, NULL);
g_return_val_if_fail ((match_options & ~G_REGEX_MATCH_MASK) == 0, NULL); g_return_val_if_fail ((match_options & ~G_REGEX_MATCH_MASK) == 0, NULL);
if (!initialized) if (g_once_init_enter (&initialised))
{ {
gint support; gint support;
const gchar *msg; const gchar *msg;
@ -1218,7 +1218,7 @@ g_regex_new (const gchar *pattern,
return NULL; return NULL;
} }
initialized = TRUE; g_once_init_leave (&initialised, TRUE);
} }
/* G_REGEX_OPTIMIZE has the same numeric value of PCRE_NO_UTF8_CHECK, /* G_REGEX_OPTIMIZE has the same numeric value of PCRE_NO_UTF8_CHECK,