Skip to content

Commit 19034d2

Browse files
committed
more
1 parent df00d23 commit 19034d2

File tree

8 files changed

+52
-20
lines changed

8 files changed

+52
-20
lines changed

src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public LowLevelLifoSemaphore(int initialSignalCount, int maximumSignalCount, int
4040
public bool Wait(int timeoutMs, bool spinWait)
4141
{
4242
Debug.Assert(timeoutMs >= -1);
43+
#if FEATURE_WASM_MANAGED_THREADS
44+
Thread.AssureBlockingPossible();
45+
#endif
4346

4447
int spinCount = spinWait ? _spinCount : 0;
4548

src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelMonitor.Unix.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ private void ReleaseCore()
4141

4242
private void WaitCore()
4343
{
44+
#if FEATURE_WASM_MANAGED_THREADS
45+
Thread.AssureBlockingPossible();
46+
#endif
4447
Interop.Sys.LowLevelMonitor_Wait(_nativeMonitor);
4548
}
4649

src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
485485

486486
ArgumentOutOfRangeException.ThrowIfLessThan(millisecondsTimeout, -1);
487487

488+
#if FEATURE_WASM_MANAGED_THREADS
489+
Thread.AssureBlockingPossible();
490+
#endif
491+
488492
if (!IsSet)
489493
{
490494
if (millisecondsTimeout == 0)

src/libraries/System.Private.CoreLib/src/System/Threading/WaitHandle.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ internal bool WaitOneNoCheck(
112112
{
113113
Debug.Assert(millisecondsTimeout >= -1);
114114

115+
#if FEATURE_WASM_MANAGED_THREADS
116+
Thread.AssureBlockingPossible();
117+
#endif
118+
115119
// The field value is modifiable via the public <see cref="WaitHandle.SafeWaitHandle"/> property, save it locally
116120
// to ensure that one instance is used in all places in this method
117121
SafeWaitHandle? waitHandle = _waitHandle;

src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.ThreadWaitInfo.Unix.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ private int ProcessSignaledWaitState()
278278

279279
public int Wait(int timeoutMilliseconds, bool interruptible, bool isSleep, ref LockHolder lockHolder)
280280
{
281+
#if FEATURE_WASM_MANAGED_THREADS
282+
Thread.AssureBlockingPossible();
283+
#endif
281284
if (isSleep)
282285
{
283286
s_lock.VerifyIsNotLocked();

src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.Unix.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ public static int Wait(
347347
Debug.Assert(waitHandles.Length > 0);
348348
Debug.Assert(waitHandles.Length <= WaitHandle.MaxWaitHandles);
349349
Debug.Assert(timeoutMilliseconds >= -1);
350+
#if FEATURE_WASM_MANAGED_THREADS
351+
Thread.AssureBlockingPossible();
352+
#endif
350353

351354
ThreadWaitInfo waitInfo = Thread.CurrentThread.WaitInfo;
352355
WaitableObject?[] waitableObjects = waitInfo.GetWaitedObjectArray(waitHandles.Length);

src/libraries/System.Private.CoreLib/src/System/Threading/WaitSubsystem.WaitableObject.Unix.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ public int Wait(ThreadWaitInfo waitInfo, int timeoutMilliseconds, bool interrupt
307307
Debug.Assert(waitInfo.Thread == Thread.CurrentThread);
308308

309309
Debug.Assert(timeoutMilliseconds >= -1);
310+
#if FEATURE_WASM_MANAGED_THREADS
311+
Thread.AssureBlockingPossible();
312+
#endif
310313

311314
var lockHolder = new LockHolder(s_lock);
312315
try

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/WebWorkerTestBase.cs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,35 +168,44 @@ static void LocalCtsIgnoringCall(Action<CancellationToken> action)
168168

169169
public static IEnumerable<NamedCall> BlockingCalls = new List<NamedCall>
170170
{
171+
// things that should NOT throw PNSE
171172
new NamedCall { IsBlocking = false, Name = "Console.WriteLine", Call = delegate (CancellationToken ct) { Console.WriteLine("Blocking"); }},
172173
new NamedCall { IsBlocking = false, Name = "Directory.GetCurrentDirectory", Call = delegate (CancellationToken ct) { Directory.GetCurrentDirectory(); }},
173-
new NamedCall { IsBlocking = true, Name = "Task.Wait", Call = delegate (CancellationToken ct) { Task.Delay(10, ct).Wait(ct); }},
174-
new NamedCall { IsBlocking = true, Name = "Task.WaitAll", Call = delegate (CancellationToken ct) { Task.WaitAll(Task.Delay(10, ct)); }},
175-
new NamedCall { IsBlocking = true, Name = "Task.WaitAny", Call = delegate (CancellationToken ct) { Task.WaitAny(Task.Delay(10, ct)); }},
174+
new NamedCall { IsBlocking = false, Name = "CancellationTokenSource.ctor", Call = delegate (CancellationToken ct) {
175+
using var cts = new CancellationTokenSource(8);
176+
}},
177+
new NamedCall { IsBlocking = false, Name = "Task.Delay", Call = delegate (CancellationToken ct) {
178+
Task.Delay(30, ct);
179+
}},
180+
new NamedCall { IsBlocking = false, Name = "new Timer", Call = delegate (CancellationToken ct) {
181+
new Timer((_) => { }, null, 1, -1);
182+
}},
183+
184+
// things which should throw PNSE on sync JSExport and JSWebWorker
185+
new NamedCall { IsBlocking = true, Name = "Task.Wait", Call = delegate (CancellationToken ct) { Task.Delay(30, ct).Wait(ct); }},
186+
new NamedCall { IsBlocking = true, Name = "Task.WaitAll", Call = delegate (CancellationToken ct) { Task.WaitAll(Task.Delay(30, ct)); }},
187+
new NamedCall { IsBlocking = true, Name = "Task.WaitAny", Call = delegate (CancellationToken ct) { Task.WaitAny(Task.Delay(30, ct)); }},
176188
new NamedCall { IsBlocking = true, Name = "ManualResetEventSlim.Wait", Call = delegate (CancellationToken ct) {
177-
using var mr = new ManualResetEventSlim(false);
189+
using var mr = new ManualResetEventSlim(false);
178190
LocalCtsIgnoringCall(mr.Wait);
179-
}},
191+
}},
180192
new NamedCall { IsBlocking = true, Name = "SemaphoreSlim.Wait", Call = delegate (CancellationToken ct) {
181-
using var sem = new SemaphoreSlim(2);
193+
using var sem = new SemaphoreSlim(2);
182194
LocalCtsIgnoringCall(sem.Wait);
183195
}},
184-
/*new NamedCall { IsBlocking = true, Name = "CancellationTokenSource.ctor", Call = delegate (CancellationToken ct) {
185-
using var cts = new CancellationTokenSource(8);
186-
}},
187196
new NamedCall { IsBlocking = true, Name = "Mutex.WaitOne", Call = delegate (CancellationToken ct) {
188-
using var mr = new ManualResetEventSlim(false);
189-
var mutex = new Mutex();
190-
var thread = new Thread(() => {
191-
mutex.WaitOne();
192-
mr.Set();
193-
Thread.Sleep(50);
194-
mutex.ReleaseMutex();
195-
});
196-
thread.Start();
197-
Thread.ForceBlockingWait(static (b) => ((ManualResetEventSlim)b).Wait(), mr);
197+
using var mr = new ManualResetEventSlim(false);
198+
var mutex = new Mutex();
199+
var thread = new Thread(() => {
198200
mutex.WaitOne();
199-
}},*/
201+
mr.Set();
202+
Thread.Sleep(50);
203+
mutex.ReleaseMutex();
204+
});
205+
thread.Start();
206+
Thread.ForceBlockingWait(static (b) => ((ManualResetEventSlim)b).Wait(), mr);
207+
mutex.WaitOne();
208+
}},
200209
};
201210

202211
public static IEnumerable<object[]> GetTargetThreadsAndBlockingCalls()

0 commit comments

Comments
 (0)