+ WebAssembly threads: introduced TWasmThread.ThreadHasFinished boolean

This commit is contained in:
Nikolay Nikolov 2024-08-23 12:07:21 +03:00
parent 6dfd2de188
commit 492e38069c

View File

@ -50,6 +50,7 @@ Type
TWasmThread = Record
InitialStackPointer : Pointer;
InitTLSBase : Pointer;
ThreadHasFinished : Boolean;
ID : LongInt; // Allocated by host
ThreadFunction : TThreadFunc;
ThreadFunctionArg : Pointer;
@ -446,6 +447,16 @@ asm
local.get 0 ;; tid
local.get 1 ;; start_arg
call $FPCWasmThreadStartPascal
;; Set start_arg^.ThreadHasFinished to true.
;; This is done from within inline asm, after the pascal code has finished
;; executing, because it indicates that the thread no longer needs its TLS
;; block and linear stack block, so this means it's safe to free them.
local.get 1 ;; start_arg
i32.const 8 ;; offset to ThreadHasFinished
i32.add
i32.const 1 ;; true
i32.atomic.store8
end;
exports wasi_thread_start;