From dd5e5248795e70fa793c032fdf3d30199ccabf93 Mon Sep 17 00:00:00 2001 From: ParantezTech Date: Wed, 1 Jul 2026 13:50:24 +0300 Subject: [PATCH] [pthread] pthread improvements and fixes --- .../Kernel/KernelPthreadCompatExports.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/SharpEmu.Libs/Kernel/KernelPthreadCompatExports.cs b/src/SharpEmu.Libs/Kernel/KernelPthreadCompatExports.cs index d6a5349..79c98a9 100644 --- a/src/SharpEmu.Libs/Kernel/KernelPthreadCompatExports.cs +++ b/src/SharpEmu.Libs/Kernel/KernelPthreadCompatExports.cs @@ -11,7 +11,6 @@ namespace SharpEmu.Libs.Kernel; public static class KernelPthreadCompatExports { - private const int MutexTypeDefault = 0; private const int MutexTypeErrorCheck = 1; private const int MutexTypeRecursive = 2; private const int MutexTypeNormal = 3; @@ -44,7 +43,7 @@ public static class KernelPthreadCompatExports public SemaphoreSlim Semaphore { get; } = new(1, 1); public ulong OwnerThreadId { get; set; } public int RecursionCount { get; set; } - public int Type { get; set; } = MutexTypeDefault; + public int Type { get; set; } = MutexTypeErrorCheck; public int Protocol { get; set; } } @@ -541,7 +540,7 @@ public static class KernelPthreadCompatExports return (int)OrbisGen2Result.ORBIS_GEN2_OK; } - if (state.Type is MutexTypeDefault or MutexTypeNormal or MutexTypeAdaptiveNp) + if (state.Type is MutexTypeNormal or MutexTypeAdaptiveNp) { if (tryOnly) { @@ -676,7 +675,7 @@ public static class KernelPthreadCompatExports return (int)OrbisGen2Result.ORBIS_GEN2_ERROR_MEMORY_FAULT; } - var initialState = new PthreadMutexAttrState(MutexTypeDefault, 0); + var initialState = new PthreadMutexAttrState(MutexTypeErrorCheck, 0); if (!WriteMutexAttrObject(ctx, handle, initialState)) { return (int)OrbisGen2Result.ORBIS_GEN2_ERROR_MEMORY_FAULT; @@ -735,7 +734,7 @@ public static class KernelPthreadCompatExports { if (!_mutexAttrStates.TryGetValue(resolvedAddress, out var state)) { - state = new PthreadMutexAttrState(MutexTypeDefault, 0); + state = new PthreadMutexAttrState(MutexTypeErrorCheck, 0); } updatedState = state with { Type = NormalizeMutexType(type) }; @@ -764,7 +763,7 @@ public static class KernelPthreadCompatExports { if (!_mutexAttrStates.TryGetValue(resolvedAddress, out var state)) { - state = new PthreadMutexAttrState(MutexTypeDefault, 0); + state = new PthreadMutexAttrState(MutexTypeErrorCheck, 0); } updatedState = state with { Protocol = protocol }; @@ -847,7 +846,7 @@ public static class KernelPthreadCompatExports return false; } - return CreateImplicitMutexState(ctx, mutexAddress, MutexTypeDefault, out resolvedAddress, out state); + return CreateImplicitMutexState(ctx, mutexAddress, MutexTypeErrorCheck, out resolvedAddress, out state); } private static ulong ResolveMutexAttrHandle(CpuContext ctx, ulong attrAddress) @@ -891,7 +890,7 @@ public static class KernelPthreadCompatExports { return _mutexAttrStates.TryGetValue(resolvedAddress, out var state) ? state - : new PthreadMutexAttrState(MutexTypeDefault, 0); + : new PthreadMutexAttrState(MutexTypeErrorCheck, 0); } } @@ -1293,12 +1292,12 @@ public static class KernelPthreadCompatExports { return type switch { - 0 => MutexTypeDefault, + 0 => MutexTypeErrorCheck, 1 => MutexTypeErrorCheck, 2 => MutexTypeRecursive, 3 => MutexTypeNormal, 4 => MutexTypeAdaptiveNp, - _ => MutexTypeDefault, + _ => MutexTypeErrorCheck, }; }