Skip to content

Commit

Permalink
fix non-browser+threads builds
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdageek committed Mar 31, 2023
1 parent 552f9a5 commit 812524f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private LowLevelLifoSemaphore(int initialSignalCount, int maximumSignalCount, in
#pragma warning disable IDE0060
private void CreateAsyncWait(int maximumSignalCount)
{
_kind = LifoSemaphoreKind.AsyncWait;
lifo_semaphore = InitInternal((int)_kind);
Kind = LifoSemaphoreKind.AsyncWait;
lifo_semaphore = InitInternal((int)Kind);
}
#pragma warning restore IDE0060

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,46 @@ namespace System.Threading
internal sealed unsafe partial class LowLevelLifoSemaphore : IDisposable
{
private IntPtr lifo_semaphore;
#if FEATURE_WASM_THREADS
#if TARGET_BROWSER && FEATURE_WASM_THREADS
private LifoSemaphoreKind _kind;
#endif

#pragma warning disable CA1822
private LifoSemaphoreKind Kind
#pragma warning restore CA1822
{
get
{
#if TARGET_BROWSER && FEATURE_WASM_THREADS
return _kind;
#else
return LifoSemaphoreKind.Normal;
#endif
}
set
{
#if TARGET_BROWSER && FEATURE_WASM_THREADS
_kind = value;
#endif
}
}

// Keep in sync with lifo-semaphore.h
private enum LifoSemaphoreKind : int {
Normal = 1,
#if TARGET_BROWSER && FEATURE_WASM_THREADS
AsyncWait = 2,
}
#endif
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern IntPtr InitInternal(int kind);

#pragma warning disable IDE0060
private void Create(int maximumSignalCount)
{
_kind = LifoSemaphoreKind.Normal;
lifo_semaphore = InitInternal((int)_kind);
Kind = LifoSemaphoreKind.Normal;
lifo_semaphore = InitInternal((int)Kind);
}
#pragma warning restore IDE0060

Expand All @@ -36,7 +58,7 @@ public void Dispose()
{
DeleteInternal(lifo_semaphore);
lifo_semaphore = IntPtr.Zero;
_kind = (LifoSemaphoreKind)0;
Kind = (LifoSemaphoreKind)0;
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
Expand All @@ -48,10 +70,14 @@ private bool WaitCore(int timeoutMs)
return TimedWaitInternal(lifo_semaphore, timeoutMs) != 0;
}

#pragma warning disable CA1822
private void ThrowIfInvalidSemaphoreKind(LifoSemaphoreKind expected)
#pragma warning restore CA1822
{
#if TARGET_BROWSER && FEATURE_WASM_THREADS
if (_kind != expected)
throw new InvalidOperationException ($"Unexpected LowLevelLifoSemaphore kind {_kind} expected {expected}");
#endif
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
Expand Down

0 comments on commit 812524f

Please sign in to comment.