From 527d81a3b26e70e38331d6dbf8fcf3c294aed8e9 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Tue, 14 Dec 2021 23:03:11 -0700 Subject: [PATCH] Add default constructors to some mutex types --- src/LibHac/Diag/Assert.cs | 11 ++--------- src/LibHac/Fs/Fsa/MountTable.cs | 3 +-- src/LibHac/FsSystem/BucketTree.cs | 3 +-- .../Impl/InternalConditionVariable-os.net.cs | 4 ++-- .../Os/Impl/InternalConditionVariable.cs | 4 ++-- .../Os/Impl/InternalCriticalSection-os.net.cs | 7 ++++++- src/LibHac/Os/Impl/InternalCriticalSection.cs | 7 ++++++- src/LibHac/Os/SdkMutex.cs | 18 +++++++++++++++++- 8 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/LibHac/Diag/Assert.cs b/src/LibHac/Diag/Assert.cs index 4c22a26a..02b4353d 100644 --- a/src/LibHac/Diag/Assert.cs +++ b/src/LibHac/Diag/Assert.cs @@ -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); } -} +} \ No newline at end of file diff --git a/src/LibHac/Fs/Fsa/MountTable.cs b/src/LibHac/Fs/Fsa/MountTable.cs index a08897fa..2c2609ad 100644 --- a/src/LibHac/Fs/Fsa/MountTable.cs +++ b/src/LibHac/Fs/Fsa/MountTable.cs @@ -27,7 +27,6 @@ internal class MountTable : IDisposable { _fileSystemList = new LinkedList(); _mutex = new SdkMutexType(); - _mutex.Initialize(); _fsClient = fsClient; } @@ -162,4 +161,4 @@ internal class MountTable : IDisposable dataIdCount = count; return Result.Success; } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSystem/BucketTree.cs b/src/LibHac/FsSystem/BucketTree.cs index 79ab8d85..44898782 100644 --- a/src/LibHac/FsSystem/BucketTree.cs +++ b/src/LibHac/FsSystem/BucketTree.cs @@ -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); } } -} +} \ No newline at end of file diff --git a/src/LibHac/Os/Impl/InternalConditionVariable-os.net.cs b/src/LibHac/Os/Impl/InternalConditionVariable-os.net.cs index c02144ac..5a5da6d4 100644 --- a/src/LibHac/Os/Impl/InternalConditionVariable-os.net.cs +++ b/src/LibHac/Os/Impl/InternalConditionVariable-os.net.cs @@ -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; } -} +} \ No newline at end of file diff --git a/src/LibHac/Os/Impl/InternalConditionVariable.cs b/src/LibHac/Os/Impl/InternalConditionVariable.cs index 594cc681..143a1db0 100644 --- a/src/LibHac/Os/Impl/InternalConditionVariable.cs +++ b/src/LibHac/Os/Impl/InternalConditionVariable.cs @@ -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); -} +} \ No newline at end of file diff --git a/src/LibHac/Os/Impl/InternalCriticalSection-os.net.cs b/src/LibHac/Os/Impl/InternalCriticalSection-os.net.cs index 9d3590b8..fcb852e3 100644 --- a/src/LibHac/Os/Impl/InternalCriticalSection-os.net.cs +++ b/src/LibHac/Os/Impl/InternalCriticalSection-os.net.cs @@ -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); } -} +} \ No newline at end of file diff --git a/src/LibHac/Os/Impl/InternalCriticalSection.cs b/src/LibHac/Os/Impl/InternalCriticalSection.cs index 9daa0e59..2a937ce1 100644 --- a/src/LibHac/Os/Impl/InternalCriticalSection.cs +++ b/src/LibHac/Os/Impl/InternalCriticalSection.cs @@ -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(); -} +} \ No newline at end of file diff --git a/src/LibHac/Os/SdkMutex.cs b/src/LibHac/Os/SdkMutex.cs index 310543f5..d43d6974 100644 --- a/src/LibHac/Os/SdkMutex.cs +++ b/src/LibHac/Os/SdkMutex.cs @@ -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(); } -} +} \ No newline at end of file