* Cleanup worker after thread has been run

This commit is contained in:
Michael Van Canneyt 2025-04-02 16:45:42 +02:00
parent bd0fdc19f2
commit 84679edbf0
2 changed files with 8 additions and 4 deletions

View File

@ -127,13 +127,14 @@ Type
// Cleanup thread info: put this worker into unusued workers
TWorkerCleanupCommand = class external name 'Object' (TWorkerCommand)
exitstatus : integer;
end;
{ TWorkerCleanupCommandHelper }
TWorkerCleanupCommandHelper = class helper for TWorkerCleanupCommand
Class function CommandName : string; static;
Class function Create(aThreadID : Integer): TWorkerCleanupCommand; static; reintroduce;
class function Create(aThreadID, aExitStatus: Integer): TWorkerCleanupCommand; static; reintroduce;
end;
@ -471,9 +472,10 @@ begin
Result:=cmdCleanup
end;
class function TWorkerCleanupCommandHelper.Create(aThreadID: Integer): TWorkerCleanupCommand;
class function TWorkerCleanupCommandHelper.Create(aThreadID, aExitStatus: Integer): TWorkerCleanupCommand;
begin
Result:=TWorkerCleanupCommand(TWorkerCommand.NewWorker(CommandName,aThreadID));
Result.ExitStatus:=aExitStatus;
end;
{ TWorkerConsoleCommandHelper }

View File

@ -56,7 +56,6 @@ Type
Private
Type
TWorkerState = (wsNeutral, wsLoading, wsLoaded, wsRunWaiting, wsRunning);
procedure DoRunThread(aExports: TWASIExports);
Private
FState: TWorkerState;
FCurrentThreadInfo : TThreadinfo;
@ -65,6 +64,7 @@ Type
FWasiHost: TWASIThreadHost;
Protected
// Incoming messages
procedure DoRunThread(aExports: TWASIExports); virtual;
procedure LoadWasmModule(aCommand: TWorkerLoadCommand); virtual;
procedure RunWasmModule(aCommand: TWorkerRunCommand); virtual;
procedure CancelWasmModule(aCommand: TWorkerCancelCommand); virtual;
@ -408,6 +408,7 @@ Procedure TWorkerThreadSupport.DoRunThread(aExports : TWASIExports);
Var
aResult : Integer;
begin
try
FState:=wsRunning;
@ -416,6 +417,7 @@ begin
FState:=wsLoaded;
if aResult>0 then
SendConsoleMessage('Thread run function result= %d ',[aResult]);
SendCommand(TWorkerCleanupCommand.Create(Self.FCurrentThreadInfo.ThreadID,aResult));
except
on E : Exception do
SendException(E);
@ -896,7 +898,7 @@ end;
function TWorkerThreadControllerApplication.CreateThreadSupport(aEnv : TPas2JSWASIEnvironment) : TThreadController;
begin
Result:=TThreadController.Create(aEnv,ThreadRunnerScript,20);
Result:=TThreadController.Create(aEnv,ThreadRunnerScript,ThreadCount);
end;
function TWorkerThreadControllerApplication.CreateHost: TWASIHost;