mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-18 02:51:59 +00:00
[pthread] pthread improvements and fixes
This commit is contained in:
@@ -11,7 +11,6 @@ namespace SharpEmu.Libs.Kernel;
|
|||||||
|
|
||||||
public static class KernelPthreadCompatExports
|
public static class KernelPthreadCompatExports
|
||||||
{
|
{
|
||||||
private const int MutexTypeDefault = 0;
|
|
||||||
private const int MutexTypeErrorCheck = 1;
|
private const int MutexTypeErrorCheck = 1;
|
||||||
private const int MutexTypeRecursive = 2;
|
private const int MutexTypeRecursive = 2;
|
||||||
private const int MutexTypeNormal = 3;
|
private const int MutexTypeNormal = 3;
|
||||||
@@ -44,7 +43,7 @@ public static class KernelPthreadCompatExports
|
|||||||
public SemaphoreSlim Semaphore { get; } = new(1, 1);
|
public SemaphoreSlim Semaphore { get; } = new(1, 1);
|
||||||
public ulong OwnerThreadId { get; set; }
|
public ulong OwnerThreadId { get; set; }
|
||||||
public int RecursionCount { get; set; }
|
public int RecursionCount { get; set; }
|
||||||
public int Type { get; set; } = MutexTypeDefault;
|
public int Type { get; set; } = MutexTypeErrorCheck;
|
||||||
public int Protocol { get; set; }
|
public int Protocol { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,7 +540,7 @@ public static class KernelPthreadCompatExports
|
|||||||
return (int)OrbisGen2Result.ORBIS_GEN2_OK;
|
return (int)OrbisGen2Result.ORBIS_GEN2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.Type is MutexTypeDefault or MutexTypeNormal or MutexTypeAdaptiveNp)
|
if (state.Type is MutexTypeNormal or MutexTypeAdaptiveNp)
|
||||||
{
|
{
|
||||||
if (tryOnly)
|
if (tryOnly)
|
||||||
{
|
{
|
||||||
@@ -676,7 +675,7 @@ public static class KernelPthreadCompatExports
|
|||||||
return (int)OrbisGen2Result.ORBIS_GEN2_ERROR_MEMORY_FAULT;
|
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))
|
if (!WriteMutexAttrObject(ctx, handle, initialState))
|
||||||
{
|
{
|
||||||
return (int)OrbisGen2Result.ORBIS_GEN2_ERROR_MEMORY_FAULT;
|
return (int)OrbisGen2Result.ORBIS_GEN2_ERROR_MEMORY_FAULT;
|
||||||
@@ -735,7 +734,7 @@ public static class KernelPthreadCompatExports
|
|||||||
{
|
{
|
||||||
if (!_mutexAttrStates.TryGetValue(resolvedAddress, out var state))
|
if (!_mutexAttrStates.TryGetValue(resolvedAddress, out var state))
|
||||||
{
|
{
|
||||||
state = new PthreadMutexAttrState(MutexTypeDefault, 0);
|
state = new PthreadMutexAttrState(MutexTypeErrorCheck, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedState = state with { Type = NormalizeMutexType(type) };
|
updatedState = state with { Type = NormalizeMutexType(type) };
|
||||||
@@ -764,7 +763,7 @@ public static class KernelPthreadCompatExports
|
|||||||
{
|
{
|
||||||
if (!_mutexAttrStates.TryGetValue(resolvedAddress, out var state))
|
if (!_mutexAttrStates.TryGetValue(resolvedAddress, out var state))
|
||||||
{
|
{
|
||||||
state = new PthreadMutexAttrState(MutexTypeDefault, 0);
|
state = new PthreadMutexAttrState(MutexTypeErrorCheck, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedState = state with { Protocol = protocol };
|
updatedState = state with { Protocol = protocol };
|
||||||
@@ -847,7 +846,7 @@ public static class KernelPthreadCompatExports
|
|||||||
return false;
|
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)
|
private static ulong ResolveMutexAttrHandle(CpuContext ctx, ulong attrAddress)
|
||||||
@@ -891,7 +890,7 @@ public static class KernelPthreadCompatExports
|
|||||||
{
|
{
|
||||||
return _mutexAttrStates.TryGetValue(resolvedAddress, out var state)
|
return _mutexAttrStates.TryGetValue(resolvedAddress, out var state)
|
||||||
? state
|
? state
|
||||||
: new PthreadMutexAttrState(MutexTypeDefault, 0);
|
: new PthreadMutexAttrState(MutexTypeErrorCheck, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1293,12 +1292,12 @@ public static class KernelPthreadCompatExports
|
|||||||
{
|
{
|
||||||
return type switch
|
return type switch
|
||||||
{
|
{
|
||||||
0 => MutexTypeDefault,
|
0 => MutexTypeErrorCheck,
|
||||||
1 => MutexTypeErrorCheck,
|
1 => MutexTypeErrorCheck,
|
||||||
2 => MutexTypeRecursive,
|
2 => MutexTypeRecursive,
|
||||||
3 => MutexTypeNormal,
|
3 => MutexTypeNormal,
|
||||||
4 => MutexTypeAdaptiveNp,
|
4 => MutexTypeAdaptiveNp,
|
||||||
_ => MutexTypeDefault,
|
_ => MutexTypeErrorCheck,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user