summaryrefslogtreecommitdiffstats
path: root/src/jv_dtoa_tsd.c
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2021-09-03 09:49:34 -0500
committerNicolas Williams <nico@cryptonector.com>2021-09-03 14:18:18 -0500
commit34182cca7babec086bbc93dec209275be896ca9e (patch)
tree847a8968e4a5863b96480e25ad4ad9de23e8f1cf /src/jv_dtoa_tsd.c
parentd18b2d078c2383d9472d0a0a226e07009025574f (diff)
Fix Windows build for 1.7 release (pthread stuff)
Diffstat (limited to 'src/jv_dtoa_tsd.c')
-rw-r--r--src/jv_dtoa_tsd.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/jv_dtoa_tsd.c b/src/jv_dtoa_tsd.c
index 85d5beb4..cafd141e 100644
--- a/src/jv_dtoa_tsd.c
+++ b/src/jv_dtoa_tsd.c
@@ -1,15 +1,16 @@
#include <stdlib.h>
#include <stdio.h>
-#include <pthread.h>
+#include "jv_thread.h"
#include "jv_dtoa_tsd.h"
#include "jv_dtoa.h"
#include "jv_alloc.h"
-
-static pthread_key_t dtoa_ctx_key;
+#ifndef WIN32
static pthread_once_t dtoa_ctx_once = PTHREAD_ONCE_INIT;
+#endif
+static pthread_key_t dtoa_ctx_key;
static void tsd_dtoa_ctx_dtor(void *ctx) {
if (ctx) {
jvp_dtoa_context_free((struct dtoa_context *)ctx);
@@ -17,22 +18,32 @@ static void tsd_dtoa_ctx_dtor(void *ctx) {
}
}
-static void tsd_dtoa_ctx_fini() {
+#ifndef WIN32
+static
+#endif
+void tsd_dtoa_ctx_fini() {
struct dtoa_context *ctx = pthread_getspecific(dtoa_ctx_key);
tsd_dtoa_ctx_dtor(ctx);
pthread_setspecific(dtoa_ctx_key, NULL);
}
-static void tsd_dtoa_ctx_init() {
+#ifndef WIN32
+static
+#endif
+void tsd_dtoa_ctx_init() {
if (pthread_key_create(&dtoa_ctx_key, tsd_dtoa_ctx_dtor) != 0) {
fprintf(stderr, "error: cannot create thread specific key");
abort();
}
+#ifndef WIN32
atexit(tsd_dtoa_ctx_fini);
+#endif
}
inline struct dtoa_context *tsd_dtoa_context_get() {
+#ifndef WIN32
pthread_once(&dtoa_ctx_once, tsd_dtoa_ctx_init); // cannot fail
+#endif
struct dtoa_context *ctx = (struct dtoa_context*)pthread_getspecific(dtoa_ctx_key);
if (!ctx) {
ctx = malloc(sizeof(struct dtoa_context));
@@ -43,4 +54,4 @@ inline struct dtoa_context *tsd_dtoa_context_get() {
}
}
return ctx;
-} \ No newline at end of file
+}