#include "cdecl.h"
#include "cdecl-internal.h"
-
-#include <glthread/lock.h>
-
#include "errmsg.h"
-#if USE_POSIX_THREADS
-# include "thread-posix.h"
-#elif USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS
-# include "thread-stdc.h"
-#elif USE_WINDOWS_THREADS
-# include "thread-w32.h"
-#else
-static void *tls_key;
-enum { tls_key_valid = 1 };
-
-#define tls_key_init() ((void)0)
-#define tls_get() tls_key
-#define tls_set(a) (tls_key = (a), 1)
-#endif
-
-struct err_state {
- struct cdecl_error err;
- size_t nstr;
- char str[FLEXIBLE_ARRAY_MEMBER];
-};
-
/* This pre-initialized error is reserved for dire out-of-memory conditions. */
static struct cdecl_error err_no_mem;
err->str = _(&errmsgs[code]);
}
-static void initialize_cb(void)
+static void init_once_cb(void)
{
#if ENABLE_NLS
bindtextdomain(PACKAGE, LOCALEDIR);
bindtextdomain("bison-runtime", BISON_LOCALEDIR);
#endif
set_err(CDECL__ENOMEM, &err_no_mem);
- tls_key_init();
}
+#if USE_POSIX_THREADS
+# include "thread-posix.h"
+#elif USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS
+# include "thread-stdc.h"
+#elif USE_WINDOWS_THREADS
+# include "thread-w32.h"
+#else
+static void *tls_key;
+enum { tls_key_valid = 1 };
+
+#define tls_get() tls_key
+#define tls_set(a) ((tls_key = (a)), 1)
+
+static int init_once(void)
+{
+ if (!err_no_mem.code)
+ init_once_cb();
+ return 1;
+}
+
+#endif
+
+struct err_state {
+ struct cdecl_error err;
+ size_t nstr;
+ char str[FLEXIBLE_ARRAY_MEMBER];
+};
+
static void *alloc_err_state(void *old, size_t buf_size)
{
struct err_state *state;
{
void *state;
- gl_once_define(static, tls_initialized)
- if (glthread_once(&tls_initialized, initialize_cb) || !tls_key_valid)
+ if (!init_once())
return NULL;
if (!(state = tls_get()))