| ... | @@ -1018,12 +1018,15 @@ const WasiThreadImpl = struct { | ... | @@ -1018,12 +1018,15 @@ const WasiThreadImpl = struct { |
| 1018 | return .{ .thread = &instance.thread }; | 1018 | return .{ .thread = &instance.thread }; |
| 1019 | } | 1019 | } |
| 1020 | | 1020 | |
| 1021 | /// Bootstrap procedure, called by the host environment after thread creation. | 1021 | comptime { |
| 1022 | export fn wasi_thread_start(tid: i32, arg: *Instance) void { | 1022 | if (!builtin.single_threaded) { |
| 1023 | if (builtin.single_threaded) { | 1023 | @export(wasi_thread_start, .{ .name = "wasi_thread_start" }); |
| 1024 | // ensure function is not analyzed in single-threaded mode | | |
| 1025 | return; | | |
| 1026 | } | 1024 | } |
| | 1025 | } |
| | 1026 | |
| | 1027 | /// Called by the host environment after thread creation. |
| | 1028 | fn wasi_thread_start(tid: i32, arg: *Instance) callconv(.c) void { |
| | 1029 | comptime assert(!builtin.single_threaded); |
| 1027 | __set_stack_pointer(arg.thread.memory.ptr + arg.stack_offset); | 1030 | __set_stack_pointer(arg.thread.memory.ptr + arg.stack_offset); |
| 1028 | __wasm_init_tls(arg.thread.memory.ptr + arg.tls_offset); | 1031 | __wasm_init_tls(arg.thread.memory.ptr + arg.tls_offset); |
| 1029 | @atomicStore(u32, &WasiThreadImpl.tls_thread_id, @intCast(tid), .seq_cst); | 1032 | @atomicStore(u32, &WasiThreadImpl.tls_thread_id, @intCast(tid), .seq_cst); |