Skip to content

Commit

Permalink
wasm multithread
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 21, 2023
1 parent 6215e61 commit 88f0eef
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 23 deletions.
10 changes: 4 additions & 6 deletions demo/OneWare.Demo.Browser/OneWare.Demo.Browser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
<WasmMainJSPath>AppBundle\main.js</WasmMainJSPath>
<OutputType>Exe</OutputType>
<MSBuildEnableWorkloadResolver>true</MSBuildEnableWorkloadResolver>
<!-- Multithreading not working at the moment (November 2023)
<!--Enable Multithread-->
<WasmEnableThreads>true</WasmEnableThreads>
<MonoWasmRuntimeConfiguration>threads-release</MonoWasmRuntimeConfiguration>
-->
<_WasmAppIncludeThreadsWorker>true</_WasmAppIncludeThreadsWorker>
<_WasmPThreadPoolSize>8</_WasmPThreadPoolSize>
<!--
<WasmBuildNative>true</WasmBuildNative>
<EmccFlags>-sVERBOSE -sERROR_ON_UNDEFINED_SYMBOLS=0</EmccFlags>
<EmccInitialHeapSize>32mb</EmccInitialHeapSize>
-->
</PropertyGroup>
Expand All @@ -27,8 +26,6 @@
<TrimMode>full</TrimMode>
<WasmBuildNative>true</WasmBuildNative>
<InvariantGlobalization>true</InvariantGlobalization>
<EmccCompileOptimizationFlag>-O2</EmccCompileOptimizationFlag>
<EmccLinkOptimizationFlag>-O2</EmccLinkOptimizationFlag>
</PropertyGroup>

<ItemGroup>
Expand All @@ -40,6 +37,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.WebAssembly.Threading" Version="8.0.0" />
<PackageReference Include="TextMateSharp.Wasm" Version="1.0.56" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions demo/OneWare.Demo.Browser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ internal partial class Program
{
public static async Task Main(string[] args)
{
#if DEBUG
Trace.Listeners.Add(new ConsoleTraceListener());
#endif

await BuildAvaloniaApp()
#if DEBUG
.LogToTrace()
#endif
.StartBrowserAppAsync("out");
}

Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.Core/ViewModels/DockViews/EditViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private async Task<bool> LoadAsync()
await using var stream = File.OpenRead(CurrentFile.FullPath);
using var reader = new StreamReader(stream);

var doc = await PlatformHelper.RunTask(() =>
var doc = await Task.Run(() =>
{
var d = new TextDocument(reader.ReadToEnd());
d.SetOwnerThread(null);
Expand Down
9 changes: 0 additions & 9 deletions src/OneWare.Shared/Helpers/PlatformHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,6 @@ public static void OpenExplorerPath(string path)
ContainerLocator.Container.Resolve<ILogger>().Error("Can't open " + path + " in explorer. " + e, e, true, true);
}
}

public static Task<TResult> RunTask<TResult>(Func<TResult> function)
{
if (RuntimeInformation.OSArchitecture is Architecture.Wasm)
{
return Task.FromResult(function.Invoke());
}
else return Task.Run(function);
}

#region File Management

Expand Down
9 changes: 3 additions & 6 deletions src/OneWare.Vcd.Parser/VcdParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static async Task ReadSignalsAsync(string path, VcdFile vcdFile, IProgres
//Use thread safe variant
if (threads == 1)
{
async Task ReadSignalsLocal()
await Task.Run(async () =>
{
await using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.ReadWrite);
stream.Seek(vcdFile.DefinitionParseEndPosition+1, SeekOrigin.Begin);
Expand All @@ -42,10 +42,7 @@ await ReadSignals(reader, vcdFile.Definition.SignalRegister, vcdFile.Definition.
cancellationToken);
if(!cancellationToken.IsCancellationRequested) await Task.Delay(1, cancellationToken);
reader.Dispose();
}

if (RuntimeInformation.OSArchitecture is Architecture.Wasm) _ = ReadSignalsLocal();
else await Task.Run(() => _ = ReadSignalsLocal());
});

return;
}
Expand Down Expand Up @@ -210,7 +207,7 @@ private static VcdFile ReadDefinition(TextReader reader)
stream.Seek(-backOffset, SeekOrigin.End);
using var reader = new StreamReader(stream);

var text = RuntimeInformation.OSArchitecture is Architecture.Wasm ? reader.ReadToEnd() : await reader.ReadToEndAsync();
var text = await reader.ReadToEndAsync();

var lines = text.Split('\n');
var lastTime = lines.LastOrDefault(x => x.StartsWith('#'));
Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.Vhdl/LanguageServiceVhdl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static LanguageServiceVhdl()
{
PlatformId.WinX64 => $"{assemblyPath}/native_tools/win-x64/rusthdl/vhdl_ls-x86_64-pc-windows-msvc/bin/vhdl_ls.exe",
PlatformId.LinuxX64 => $"{assemblyPath}/native_tools/linux-x64/rusthdl/vhdl_ls-x86_64-unknown-linux-musl/bin/vhdl_ls",
PlatformId.Wasm => "wss://oneware-cloud-ls-vhdl-qtuhvc77rq-ew.a.run.app",
//PlatformId.Wasm => "wss://oneware-cloud-ls-vhdl-qtuhvc77rq-ew.a.run.app",
_ => null
};
}
Expand Down

0 comments on commit 88f0eef

Please sign in to comment.