Skip to content

Commit

Permalink
Don't use SyncTextWriter on WASI either (#104798)
Browse files Browse the repository at this point in the history
Follow-up to #101221 so we match behavior between single-threaded Browser and WASI.
  • Loading branch information
akoeplinger committed Jul 15, 2024
1 parent 5130683 commit 9bc738d
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/libraries/System.Console/tests/ReadAndWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ public static async Task OutWriteAndWriteLineOverloads()
Console.SetOut(sw);
TextWriter writer = Console.Out;
Assert.NotNull(writer);
// Browser bypasses SyncTextWriter for faster startup
if (!OperatingSystem.IsBrowser())
// single-threaded WASM bypasses SyncTextWriter for faster startup
if (PlatformDetection.IsThreadingSupported)
Assert.NotEqual(writer, sw); // the writer we provide gets wrapped
else
Assert.Equal(writer, sw); // the writer we provide does not get wrapped

// We just want to ensure none of these throw exceptions, we don't actually validate
// what was written.
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Console/tests/SyncTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class SyncTextWriter
{
// Browser bypasses SyncTextWriter for faster startup
// single-threaded WASM bypasses SyncTextWriter for faster startup
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public void SyncTextWriterLockedOnThis()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
<IsBigEndian Condition="'$(Platform)' == 's390x'">true</IsBigEndian>
<Is64Bit Condition="'$(Platform)' == 'arm64' or '$(Platform)' == 'x64' or '$(Platform)' == 's390x' or '$(Platform)' == 'loongarch64' or '$(Platform)' == 'ppc64le' or '$(Platform)' == 'riscv64'">true</Is64Bit>
<UseMinimalGlobalizationData Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">true</UseMinimalGlobalizationData>
<FeatureWasmManagedThreads Condition="'$(WasmEnableThreads)' == 'true'">true</FeatureWasmManagedThreads>
<DefineConstants Condition="'$(FeatureWasmManagedThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(IsBigEndian)' == 'true'">$(DefineConstants);BIGENDIAN</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ public static TextWriter Synchronized(TextWriter writer)
{
ArgumentNullException.ThrowIfNull(writer);

#if !TARGET_BROWSER || FEATURE_WASM_MANAGED_THREADS
#if (!TARGET_BROWSER && !TARGET_WASI) || FEATURE_WASM_MANAGED_THREADS
return writer is SyncTextWriter ? writer : new SyncTextWriter(writer);
#else
return writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void ObjectClosedReadLineBaseStream()
Assert.Throws<ObjectDisposedException>(() => sr.ReadLine());
}

// Browser bypasses SyncTextWriter for faster startup
// single-threaded WASM bypasses SyncTextWriter for faster startup
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public void Synchronized_NewObject()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.IO.Tests
{
public partial class WriteTests
{
// Browser bypasses SyncTextWriter for faster startup
// single-threaded WASM bypasses SyncTextWriter for faster startup
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public void Synchronized_NewObject()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ public void DisposeAsync_ExceptionReturnedInTask()
Assert.Same(e, vt.AsTask().Exception.InnerException);
}

// Browser bypasses SyncTextWriter for faster startup
// single-threaded WASM bypasses SyncTextWriter for faster startup
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
public async Task FlushAsync_Precanceled()
{
Expand Down
2 changes: 0 additions & 2 deletions src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<Platforms>x64;x86;arm;armv6;arm64;riscv64;s390x;wasm;ppc64le</Platforms>

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<FeatureWasmManagedThreads Condition="'$(WasmEnableThreads)' == 'true'">true</FeatureWasmManagedThreads>
<DefineConstants Condition="'$(FeatureWasmManagedThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
</PropertyGroup>

<!-- Note that various places in SPCL depend on this resource name i.e. TplEventSource -->
Expand Down

0 comments on commit 9bc738d

Please sign in to comment.