summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/al/lib.h6
-rw-r--r--include/al/log.h2
-rw-r--r--src/array.c1
-rw-r--r--src/log.c17
4 files changed, 17 insertions, 9 deletions
diff --git a/include/al/lib.h b/include/al/lib.h
index 63a2f48..c94f817 100644
--- a/include/al/lib.h
+++ b/include/al/lib.h
@@ -128,6 +128,12 @@ AL_UNUSED_FUNCTION_POP
#define AL_PASTER(X, Y) AL_PASTER_EVALUATOR(X, Y)
#endif
+#ifndef _MSVC_
+#define __al_thread __thread
+#else
+#define __al_thread
+#endif
+
AL_UNUSED_FUNCTION_PUSH
static inline size_t al_next_power_of_two(size_t n)
diff --git a/include/al/log.h b/include/al/log.h
index 8723635..ae3d2d0 100644
--- a/include/al/log.h
+++ b/include/al/log.h
@@ -6,7 +6,7 @@
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
-void al_set_print(void *userdata, s32 (*print_func)(void *, char *));
+void al_set_print(s32 (*print_func)(void *, char *), void *userdata);
s32 _al_log(const char *level, const char *section, const char *name, const s32 line,
const char *func, const char *fmt, ...);
diff --git a/src/array.c b/src/array.c
index c843ff6..e95b1a9 100644
--- a/src/array.c
+++ b/src/array.c
@@ -2,6 +2,7 @@
#include "../include/al/array_sort.h"
// https://github.com/lifthrasiir/angolmois/blob/master/angolmois.c#L79
+// https://gist.github.com/lifthrasiir/4422136
#define array(type) \
struct { \
diff --git a/src/log.c b/src/log.c
index ca9266d..9a738df 100644
--- a/src/log.c
+++ b/src/log.c
@@ -4,8 +4,7 @@
#define AL_LOG_MESSAGE_SIZE 511
#define AL_LOG_TEMPLATE "%s:%d %s(): %s -> (%s) "
-static void *al_log_userdata = NULL;
-
+#if !AL_LOG_SKIP
static s32 al_print_default(void *userdata, char *s)
{
(void)userdata;
@@ -14,15 +13,15 @@ static s32 al_print_default(void *userdata, char *s)
return ret;
}
-static s32 (*_al_print)(void *, char *) = al_print_default;
+__al_thread s32 (*_al_print)(void *, char *) = al_print_default;
+__al_thread void *_al_log_userdata = NULL;
-void al_set_print(void *userdata, s32 (*print_func)(void *, char *))
+void al_set_print(s32 (*print_func)(void *, char *), void *userdata)
{
- al_log_userdata = userdata;
_al_print = print_func;
+ _al_log_userdata = userdata;
}
-#if !AL_LOG_SKIP
static char *get_buffer(const char *level, const char *section, const char *fmt,
const char *name, const s32 line, const char *func, va_list args)
{
@@ -33,6 +32,8 @@ static char *get_buffer(const char *level, const char *section, const char *fmt,
buffer[strcspn(buffer, "\r\n")] = '\0';
return buffer;
}
+#else
+void al_set_print(s32 (*print_func)(void *, char *), void *userdata) { (void)print_func; (void)userdata; }
#endif
s32 _al_log_nop(const char *section, const char *fmt, ...)
@@ -62,7 +63,7 @@ s32 _al_log(const char *level, const char *section, const char *name, const s32
#if AL_LOG_SKIP
return ret;
#else
- return _al_print(al_log_userdata, buffer);
+ return _al_print(_al_log_userdata, buffer);
#endif
#endif
}
@@ -84,7 +85,7 @@ s32 _al_logv(const char *level, const char *section, const char *name, const s32
#if AL_LOG_SKIP
return ret;
#else
- return _al_print(al_log_userdata, buffer);
+ return _al_print(_al_log_userdata, buffer);
#endif
#endif
}