Add default constructors to some mutex types

This commit is contained in:
Alex Barney 2021-12-14 23:03:11 -07:00
parent 06806517da
commit 527d81a3b2
8 changed files with 37 additions and 20 deletions

View file

@ -37,16 +37,9 @@ public static class Assert
{
private const string AssertCondition = "ENABLE_ASSERTS";
private static SdkMutexType _mutex = InitMutex();
private static SdkMutexType _mutex = new SdkMutexType();
private static AssertionFailureHandler _assertionFailureHandler = DefaultAssertionFailureHandler;
private static SdkMutexType InitMutex()
{
var mutex = new SdkMutexType();
mutex.Initialize();
return mutex;
}
private static AbortReason ToAbortReason(AssertionType assertionType)
{
switch (assertionType)
@ -1182,4 +1175,4 @@ public static class Assert
AlignedImpl(AssertionType.SdkRequires, value, alignment, valueText, alignmentText, functionName, fileName,
lineNumber);
}
}
}

View file

@ -27,7 +27,6 @@ internal class MountTable : IDisposable
{
_fileSystemList = new LinkedList<FileSystemAccessor>();
_mutex = new SdkMutexType();
_mutex.Initialize();
_fsClient = fsClient;
}
@ -162,4 +161,4 @@ internal class MountTable : IDisposable
dataIdCount = count;
return Result.Success;
}
}
}

View file

@ -291,7 +291,6 @@ public partial class BucketTree : IDisposable
public OffsetCache()
{
Mutex = new SdkMutexType();
Mutex.Initialize();
IsInitialized = false;
Offsets.StartOffset = -1;
Offsets.EndOffset = -1;
@ -1295,4 +1294,4 @@ public partial class BucketTree : IDisposable
return _tree.ScanContinuousReading(out info, in param);
}
}
}
}

View file

@ -7,7 +7,7 @@ internal struct InternalConditionVariableImpl
{
private object _obj;
public InternalConditionVariableImpl(nint _ = 0) => _obj = new object();
public InternalConditionVariableImpl() => _obj = new object();
public void Initialize() => _obj = new object();
public void Signal()
@ -73,4 +73,4 @@ internal struct InternalConditionVariableImpl
return ConditionVariableStatus.Success;
}
}
}

View file

@ -4,7 +4,7 @@ internal struct InternalConditionVariable
{
private InternalConditionVariableImpl _impl;
public InternalConditionVariable(nint _ = 0)
public InternalConditionVariable()
{
_impl = new InternalConditionVariableImpl();
}
@ -16,4 +16,4 @@ internal struct InternalConditionVariable
public void TimedWait(ref InternalCriticalSection cs, in TimeoutHelper timeoutHelper) =>
_impl.TimedWait(ref cs, in timeoutHelper);
}
}

View file

@ -6,6 +6,11 @@ internal struct InternalCriticalSectionImpl
{
private object _obj;
public InternalCriticalSectionImpl()
{
_obj = new object();
}
public void Initialize()
{
_obj = new object();
@ -32,4 +37,4 @@ internal struct InternalCriticalSectionImpl
{
return Monitor.IsEntered(_obj);
}
}
}

View file

@ -4,6 +4,11 @@ public struct InternalCriticalSection : ILockable
{
private InternalCriticalSectionImpl _impl;
public InternalCriticalSection()
{
_impl = new InternalCriticalSectionImpl();
}
public void Initialize() => _impl.Initialize();
public void FinalizeObject() => _impl.FinalizeObject();
@ -16,4 +21,4 @@ public struct InternalCriticalSection : ILockable
public void Unlock() => _impl.Leave();
public bool IsLockedByCurrentThread() => _impl.IsLockedByCurrentThread();
}
}

View file

@ -7,6 +7,11 @@ public class SdkMutex : ILockable
{
private SdkMutexType _mutex;
public SdkMutex()
{
_mutex.Initialize();
}
public void Initialize()
{
_mutex.Initialize();
@ -37,6 +42,11 @@ public struct SdkMutexType : ILockable
{
private InternalCriticalSection _cs;
public SdkMutexType()
{
_cs = new InternalCriticalSection();
}
public void Initialize()
{
_cs.Initialize();
@ -96,6 +106,12 @@ public struct SdkRecursiveMutexType : ILockable
private InternalCriticalSection _cs;
private int _recursiveCount;
public SdkRecursiveMutexType()
{
_cs = new InternalCriticalSection();
_recursiveCount = 0;
}
public void Initialize()
{
_cs.Initialize();
@ -144,4 +160,4 @@ public struct SdkRecursiveMutexType : ILockable
{
return _cs.IsLockedByCurrentThread();
}
}
}