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

View File

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