diff options
| author | 2023-11-11 17:20:20 -0500 | |
|---|---|---|
| committer | 2023-11-11 17:20:20 -0500 | |
| commit | 3ab946ffad95405971834f5c50784d8e9dfabd6a (patch) | |
| tree | 70b35bf39399a19565281003c5013d0bf8560d66 | |
| parent | 2e2f5dc93d8ce75bc3a9ab0287b4c9af64d7d4f0 (diff) | |
| download | libalabaster-3ab946ffad95405971834f5c50784d8e9dfabd6a.tar.gz libalabaster-3ab946ffad95405971834f5c50784d8e9dfabd6a.tar.bz2 libalabaster-3ab946ffad95405971834f5c50784d8e9dfabd6a.zip | |
Make log globals thread-local, add array reference
Signed-off-by: Andrew Opalach <andrew@akon.city>
| -rw-r--r-- | include/al/lib.h | 6 | ||||
| -rw-r--r-- | include/al/log.h | 2 | ||||
| -rw-r--r-- | src/array.c | 1 | ||||
| -rw-r--r-- | src/log.c | 17 |
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 { \ @@ -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 } |