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)

View file

@ -27,7 +27,6 @@ internal class MountTable : IDisposable
{
_fileSystemList = new LinkedList<FileSystemAccessor>();
_mutex = new SdkMutexType();
_mutex.Initialize();
_fsClient = fsClient;
}

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;

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()

View file

@ -4,7 +4,7 @@ internal struct InternalConditionVariable
{
private InternalConditionVariableImpl _impl;
public InternalConditionVariable(nint _ = 0)
public InternalConditionVariable()
{
_impl = new InternalConditionVariableImpl();
}

View file

@ -6,6 +6,11 @@ internal struct InternalCriticalSectionImpl
{
private object _obj;
public InternalCriticalSectionImpl()
{
_obj = new object();
}
public void Initialize()
{
_obj = new object();

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();

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();