From b2adae02ca8356ecddb7aae66521c726ecf86b51 Mon Sep 17 00:00:00 2001 From: Michael Van Canneyt Date: Fri, 7 Feb 2025 16:44:23 +0100 Subject: [PATCH] * Correct main/self thread functions --- packages/wasi/src/rtl.threadcontroller.pas | 7 ----- packages/wasi/src/rtl.webthreads.pas | 32 +++++++++++++++++++++- packages/wasi/src/wasiworkerthreadhost.pas | 5 ---- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/packages/wasi/src/rtl.threadcontroller.pas b/packages/wasi/src/rtl.threadcontroller.pas index 503ede5..63163f9 100644 --- a/packages/wasi/src/rtl.threadcontroller.pas +++ b/packages/wasi/src/rtl.threadcontroller.pas @@ -74,7 +74,6 @@ Type function thread_spawn(start_arg : longint) : longint; override; Function thread_detach(thread_id : longint) : Integer; override; Function thread_cancel(thread_id : longint) : Integer; override; - Function thread_self() : Integer; override; Protected FIdleWorkers : Array of TWasmThread; FBusyWorkers : Array of TWasmThread; @@ -354,12 +353,6 @@ begin Result:=-1; end; -function TThreadController.thread_self: Integer; -begin - Result:=-1; -end; - - procedure TThreadController.SendLoadCommands; Var diff --git a/packages/wasi/src/rtl.webthreads.pas b/packages/wasi/src/rtl.webthreads.pas index e44077c..bd6cb4b 100644 --- a/packages/wasi/src/rtl.webthreads.pas +++ b/packages/wasi/src/rtl.webthreads.pas @@ -292,9 +292,11 @@ Type // Proposed WASI standard, modeled after POSIX pthreads. function thread_spawn(start_arg : longint) : longint; virtual; abstract; + // These are extensions Function thread_detach(thread_id : longint) : Integer; virtual; abstract; Function thread_cancel(thread_id : longint) : Integer; virtual; abstract; - Function thread_self() : Integer; virtual; abstract; + Function thread_self() : Integer; virtual; + Function thread_main() : Integer; virtual; Public Function ImportName : String; override; procedure FillImportObject(aObject: TJSObject); override; @@ -498,6 +500,34 @@ end; { TWasmThreadSupport } +function TWasmThreadSupport.thread_self(): Integer; + +Type + TGetThreadIDFunction = Function : Longint; +var + F : TGetThreadIDFunction; +begin + F:=TGetThreadIDFunction(InstanceExports['GetSelfThread']); + if Assigned(F) then + Result:=F() + else + Result:=0; +end; + +function TWasmThreadSupport.thread_main: Integer; + +Type + TGetThreadIDFunction = Function : Longint; +var + F : TGetThreadIDFunction; +begin + F:=TGetThreadIDFunction(InstanceExports['GetMainThread']); + if Assigned(F) then + Result:=F() + else + Result:=0; +end; + function TWasmThreadSupport.ImportName: String; begin Result:='wasi'; diff --git a/packages/wasi/src/wasiworkerthreadhost.pas b/packages/wasi/src/wasiworkerthreadhost.pas index 57babb5..0c7d952 100644 --- a/packages/wasi/src/wasiworkerthreadhost.pas +++ b/packages/wasi/src/wasiworkerthreadhost.pas @@ -77,7 +77,6 @@ Type function thread_spawn(start_arg : longint) : longint; override; Function thread_detach(thread_id : Integer) : Integer; override; Function thread_cancel(thread_id : Integer) : Integer; override; - Function thread_self() : Integer; override; Public // Handle incoming command Procedure HandleCommand(aCommand : TWorkerCommand); override; @@ -332,10 +331,6 @@ begin if thread_id=0 then ; end; -function TWorkerThreadSupport.thread_self: Integer; -begin - Result:=0; -end; procedure TWorkerThreadSupport.SendLoaded;