|
@@ -58,24 +58,15 @@ Type
|
|
procedure DoRunThread(aExports: TWASIExports);
|
|
procedure DoRunThread(aExports: TWASIExports);
|
|
Private
|
|
Private
|
|
FState: TWorkerState;
|
|
FState: TWorkerState;
|
|
- FStartThreadID : Integer;
|
|
|
|
- FNextThreadID : Integer;
|
|
|
|
FCurrentThreadInfo : TThreadinfo;
|
|
FCurrentThreadInfo : TThreadinfo;
|
|
FModule : TJSWebAssemblyModule;
|
|
FModule : TJSWebAssemblyModule;
|
|
FMemory : TJSWebAssemblyMemory;
|
|
FMemory : TJSWebAssemblyMemory;
|
|
FWasiHost: TWASIThreadHost;
|
|
FWasiHost: TWASIThreadHost;
|
|
Protected
|
|
Protected
|
|
- // Set new thread range
|
|
|
|
- procedure InitThreadRange(aRange: Integer);
|
|
|
|
- // allocate new thread ID.
|
|
|
|
- Function AllocateNewThreadID : NativeInt;
|
|
|
|
// Incoming messages
|
|
// Incoming messages
|
|
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;
|
|
- procedure SetThreadRange(aCommand: TWorkerThreadIDRangeCommand); virtual;
|
|
|
|
- // outgoing messages
|
|
|
|
- procedure RequestNewThreadBlock; virtual;
|
|
|
|
procedure SendLoaded; virtual;
|
|
procedure SendLoaded; virtual;
|
|
Procedure SendConsoleMessage(aMessage : String); overload;
|
|
Procedure SendConsoleMessage(aMessage : String); overload;
|
|
Procedure SendConsoleMessage(aFmt : String; const aArgs : array of const); overload;
|
|
Procedure SendConsoleMessage(aFmt : String; const aArgs : array of const); overload;
|
|
@@ -322,12 +313,11 @@ function TWorkerThreadSupport.thread_spawn(start_arg: longint): longint;
|
|
|
|
|
|
Var
|
|
Var
|
|
P : TWorkerSpawnThreadCommand;
|
|
P : TWorkerSpawnThreadCommand;
|
|
- lThreadID : Integer;
|
|
|
|
|
|
+
|
|
begin
|
|
begin
|
|
- lThreadID:=AllocateNewThreadID;
|
|
|
|
- P:=TWorkerSpawnThreadCommand.Create(lThreadID,start_arg);
|
|
|
|
|
|
+ P:=TWorkerSpawnThreadCommand.Create(start_arg,start_arg);
|
|
SendCommand(P);
|
|
SendCommand(P);
|
|
- Result:=lThreadID;
|
|
|
|
|
|
+ Result:=start_arg;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TWorkerThreadSupport.thread_detach(thread_id: Integer): Integer;
|
|
function TWorkerThreadSupport.thread_detach(thread_id: Integer): Integer;
|
|
@@ -347,17 +337,6 @@ begin
|
|
Result:=0;
|
|
Result:=0;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TWorkerThreadSupport.AllocateNewThreadID: NativeInt;
|
|
|
|
-
|
|
|
|
-begin
|
|
|
|
- if (FNextThreadID-FStartThreadID)>=ThreadIDInterval then
|
|
|
|
- FNextThreadID:=FStartThreadID;
|
|
|
|
- Inc(FNextThreadID);
|
|
|
|
- if (FNextThreadID-FStartThreadID)=ThreadIDInterval-ThreadIDMargin then
|
|
|
|
- RequestNewThreadBlock;
|
|
|
|
- Result:=FNextThreadID;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
procedure TWorkerThreadSupport.SendLoaded;
|
|
procedure TWorkerThreadSupport.SendLoaded;
|
|
|
|
|
|
Var
|
|
Var
|
|
@@ -520,7 +499,6 @@ begin
|
|
FState:=wsLoading;
|
|
FState:=wsLoading;
|
|
FMemory:=aCommand.Memory;
|
|
FMemory:=aCommand.Memory;
|
|
FModule:=aCommand.Module;
|
|
FModule:=aCommand.Module;
|
|
- InitThreadRange(aCommand.ThreadRangeStart);
|
|
|
|
try
|
|
try
|
|
aTable:=TJSWebAssemblyTable.New(Host.TableDescriptor);
|
|
aTable:=TJSWebAssemblyTable.New(Host.TableDescriptor);
|
|
WASD:=Host.InitStartDescriptor(FMemory,aTable,Nil);
|
|
WASD:=Host.InitStartDescriptor(FMemory,aTable,Nil);
|
|
@@ -533,26 +511,6 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWorkerThreadSupport.InitThreadRange(aRange: Integer);
|
|
|
|
-
|
|
|
|
-begin
|
|
|
|
- FStartThreadID:=aRange;
|
|
|
|
- FNextThreadID:=FStartThreadID;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-procedure TWorkerThreadSupport.RequestNewThreadBlock;
|
|
|
|
-
|
|
|
|
-begin
|
|
|
|
- SendCommand(TWorkerNeedIdBlockCommand.Create(FNextThreadID));
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-procedure TWorkerThreadSupport.SetThreadRange(
|
|
|
|
- aCommand: TWorkerThreadIDRangeCommand);
|
|
|
|
-
|
|
|
|
-begin
|
|
|
|
- InitThreadRange(aCommand.RangeStart);
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
procedure TWorkerThreadSupport.HandleCommand(aCommand: TWorkerCommand);
|
|
procedure TWorkerThreadSupport.HandleCommand(aCommand: TWorkerCommand);
|
|
|
|
|
|
begin
|
|
begin
|
|
@@ -560,7 +518,6 @@ begin
|
|
cmdload : LoadWasmModule(TWorkerLoadCommand(aCommand));
|
|
cmdload : LoadWasmModule(TWorkerLoadCommand(aCommand));
|
|
cmdRun : RunWasmModule(TWorkerRunCommand(aCommand));
|
|
cmdRun : RunWasmModule(TWorkerRunCommand(aCommand));
|
|
cmdCancel : CancelWasmModule(TWorkerCancelCommand(aCommand));
|
|
cmdCancel : CancelWasmModule(TWorkerCancelCommand(aCommand));
|
|
- cmdThreadIdRange : SetThreadRange(TWorkerThreadIDRangeCommand(aCommand));
|
|
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|