IO Thread local on callback, build system thread local on perm arena

This commit is contained in:
Krzosa Karol
2024-03-10 19:22:16 +01:00
parent bc12273f2a
commit c944ceac4b
3 changed files with 20 additions and 5 deletions

View File

@@ -12,9 +12,8 @@
#define AND_CL_STRING_TERMINATE_ON_NEW_LINE #define AND_CL_STRING_TERMINATE_ON_NEW_LINE
#include "../standalone_libraries/clexer.c" #include "../standalone_libraries/clexer.c"
MA_Arena PernamentArena; thread_local MA_Arena PernamentArena;
MA_Arena *Perm = &PernamentArena; thread_local MA_Arena *Perm = &PernamentArena;
Table<S8_String> CMDLine;
#include "cache.cpp" #include "cache.cpp"
#include "easy_strings.cpp" #include "easy_strings.cpp"

View File

@@ -31,7 +31,7 @@ IO_StaticFunc int IO_Strlen(char *string) {
return len; return len;
} }
void (*IO_User_OutputMessage)(int kind, const char *file, int line, char *str, int len); IO_THREAD_LOCAL void (*IO_User_OutputMessage)(int kind, const char *file, int line, char *str, int len);
IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) { IO_API bool IO__FatalErrorf(const char *file, int line, const char *msg, ...) {
va_list args1; va_list args1;

View File

@@ -22,6 +22,22 @@ typedef enum IO_ErrorResult {
#define IO_DebugBreak() (__builtin_trap(), 0) #define IO_DebugBreak() (__builtin_trap(), 0)
#endif #endif
#ifndef IO_THREAD_LOCAL
#if defined(__cplusplus) && __cplusplus >= 201103L
#define IO_THREAD_LOCAL thread_local
#elif defined(__GNUC__)
#define IO_THREAD_LOCAL __thread
#elif defined(_MSC_VER)
#define IO_THREAD_LOCAL __declspec(thread)
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
#define IO_THREAD_LOCAL _Thread_local
#elif defined(__TINYC__)
#define IO_THREAD_LOCAL _Thread_local
#else
#error Couldnt figure out thread local, needs to be provided manually
#endif
#endif
#if defined(__has_attribute) #if defined(__has_attribute)
#if __has_attribute(format) #if __has_attribute(format)
#define IO__PrintfFormat(fmt, va) __attribute__((format(printf, fmt, va))) #define IO__PrintfFormat(fmt, va) __attribute__((format(printf, fmt, va)))
@@ -33,7 +49,7 @@ typedef enum IO_ErrorResult {
#endif #endif
typedef void IO_MessageHandler(int kind, const char *file, int line, char *str, int len); typedef void IO_MessageHandler(int kind, const char *file, int line, char *str, int len);
extern void (*IO_User_OutputMessage)(int kind, const char *file, int line, char *str, int len); extern IO_THREAD_LOCAL void (*IO_User_OutputMessage)(int kind, const char *file, int line, char *str, int len);
#define IO__STRINGIFY(x) #x #define IO__STRINGIFY(x) #x
#define IO__TOSTRING(x) IO__STRINGIFY(x) #define IO__TOSTRING(x) IO__STRINGIFY(x)