]> git.draconx.ca Git - cdecl99.git/blobdiff - src/error.c
libcdecl: Punt gnulib lock module.
[cdecl99.git] / src / error.c
index 0ff31ee0a4f6871e5eaadac892aed76c4b2b7878..eb85b89c1bcbb4b015a0c36a9df33922da31d025 100644 (file)
 
 #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;
 
@@ -69,16 +45,43 @@ static void set_err(unsigned code, struct cdecl_error *err)
        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;
@@ -109,8 +112,7 @@ static struct err_state *get_err_state(void)
 {
        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()))