}
}
-// @Robustness
-// Currently, because the only compilation target is WebAssembly, which is only
-// single threaded for the moment, it is safe to store the context in a global
-// variable. If other compilations targets are added, or if WebAssembly standardizes
-// a multi-threading proposal, this context will need to be changed. Either it will
-// need to be a thread-local variable, or it needs to be implicitly passed as the
-// first parameter to ALL procedures in a compilation unit.
-context : OnyxContext;
+#thread_local context : OnyxContext;
assert :: (cond: bool, msg: str, site := #callsite) {
if !cond do context.assert_handler(msg, site);
__exit(1);
}
-// Use this procedure to initialize everything needed in the
-// standard library when you are dropped directly into a function.
__runtime_initialize :: () {
alloc.init();
+ __thread_initialize();
+
+ #if Multi_Threading_Enabled do thread.__initialize();
+}
+
+// Use this procedure to initialize everything needed in the
+// standard library when you are dropped directly into a function.
+__thread_initialize :: () {
+ __tls_base = raw_alloc(alloc.heap_allocator, __tls_size);
__initialize(^context);
context.allocator = alloc.heap_allocator;
context.temp_allocator = alloc.temp_allocator;
context.assert_handler = __assert_handler;
- #if Multi_Threading_Enabled {
- thread.__initialize();
- }
+ __stdio_init();
}
#export "_start" () {
__runtime_initialize();
- __tls_base = raw_alloc(context.allocator, __tls_size);
- __stdio_init();
-
args: [] cstr = .{ null, 0 };
(package main).main(args);
#export "_thread_start" (func: (data: rawptr) -> void, data: rawptr) {
__stack_top = raw_alloc(context.allocator, 1 << 20);
-
- __tls_base = raw_alloc(context.allocator, __tls_size);
- __stdio_init();
+ __thread_initialize();
func(data);
// Sets up everything needed for execution.
#export "_start" () {
__runtime_initialize();
-
- __tls_base = raw_alloc(context.allocator, __tls_size);
- __stdio_init();
args : [] cstr;
argv_buf_size : Size;
// Private and internal things
//
-#threadlocal stdio : struct {
+#thread_local stdio : struct {
print_stream : io.DynamicStringStream;
print_writer : io.Writer;
}
}
if (parse_possible_directive(parser, "persist")) {
- b32 thread_local = parse_possible_directive(parser, "threadlocal");
+ b32 thread_local = parse_possible_directive(parser, "thread_local");
OnyxToken* symbol = expect_token(parser, Token_Type_Symbol);
AstMemRes* memres = parse_memory_reservation(parser, symbol, thread_local);
ENTITY_SUBMIT(tag);
return;
}
- else if (parse_possible_directive(parser, "threadlocal")) {
+ else if (parse_possible_directive(parser, "thread_local")) {
OnyxToken* symbol = expect_token(parser, Token_Type_Symbol);
AstMemRes* memres = parse_memory_reservation(parser, symbol, 1);