1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Comptime compat

This commit is contained in:
Brian Fiete 2022-03-08 06:23:24 -08:00
parent 1223395a01
commit bbb97d1490

View file

@ -18,12 +18,14 @@ namespace System.Threading
public this() public this()
{ {
mCritSect = Platform.BfpCritSect_Create(); if (!Compiler.IsComptime)
mCritSect = Platform.BfpCritSect_Create();
} }
public ~this() public ~this()
{ {
Platform.BfpCritSect_Release(mCritSect); if (!Compiler.IsComptime)
Platform.BfpCritSect_Release(mCritSect);
} }
/// Acquires the monitor lock. Will block if another thread holds the lock. /// Acquires the monitor lock. Will block if another thread holds the lock.
@ -34,7 +36,8 @@ namespace System.Threading
{ {
MonitorLockInstance monitorLockInstance; MonitorLockInstance monitorLockInstance;
monitorLockInstance.mMonitor = this; monitorLockInstance.mMonitor = this;
Platform.BfpCritSect_Enter(mCritSect); if (!Compiler.IsComptime)
Platform.BfpCritSect_Enter(mCritSect);
return monitorLockInstance; return monitorLockInstance;
} }
@ -44,21 +47,28 @@ namespace System.Threading
/// multiple Enters which have not all be Exited. /// multiple Enters which have not all be Exited.
public void Exit() public void Exit()
{ {
Platform.BfpCritSect_Leave(mCritSect); if (!Compiler.IsComptime)
Platform.BfpCritSect_Leave(mCritSect);
} }
/// Attempt to enter the monitor without waiting. /// Attempt to enter the monitor without waiting.
/// @return true if the monitor was entered /// @return true if the monitor was entered
public bool TryEnter() public bool TryEnter()
{ {
return Platform.BfpCritSect_TryEnter(mCritSect, 0); if (!Compiler.IsComptime)
return Platform.BfpCritSect_TryEnter(mCritSect, 0);
else
return true;
} }
/// Blocks up to a timeout, or if millisecondsTimeout is -1, will wait forever. /// Blocks up to a timeout, or if millisecondsTimeout is -1, will wait forever.
/// @return true if the monitor was entered /// @return true if the monitor was entered
public bool TryEnter(int millisecondsTimeout) public bool TryEnter(int millisecondsTimeout)
{ {
return Platform.BfpCritSect_TryEnter(mCritSect, (int32)millisecondsTimeout); if (!Compiler.IsComptime)
return Platform.BfpCritSect_TryEnter(mCritSect, (int32)millisecondsTimeout);
else
return true;
} }
private static int32 MillisecondsTimeoutFromTimeSpan(TimeSpan timeout) private static int32 MillisecondsTimeoutFromTimeSpan(TimeSpan timeout)