mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-04 11:43:47 +01:00
Fix sceKernelReferMutexStatus().
This commit is contained in:
1 parent
a7caa1b63d
commit
ad3152cb94
1 file changed
+18
-15
+18
-15
@@ -54,6 +54,7 @@ struct NativeMutex
|
||||
SceUInt attr;
|
||||
int initialCount;
|
||||
int lockLevel;
|
||||
SceUID lockThread;
|
||||
int numWaitThreads;
|
||||
};
|
||||
|
||||
@@ -69,13 +70,11 @@ struct Mutex : public KernelObject
|
||||
p.Do(nm);
|
||||
SceUID dv = 0;
|
||||
p.Do(waitingThreads, dv);
|
||||
p.Do(lockThread);
|
||||
p.DoMarker("Mutex");
|
||||
}
|
||||
|
||||
NativeMutex nm;
|
||||
std::vector<SceUID> waitingThreads;
|
||||
int lockThread; // The thread holding the lock
|
||||
};
|
||||
|
||||
// Guesswork - not exposed anyway
|
||||
@@ -178,7 +177,7 @@ void __KernelMutexAcquireLock(Mutex *mutex, int count, SceUID thread)
|
||||
mutexHeldLocks.insert(std::make_pair(thread, mutex->GetUID()));
|
||||
|
||||
mutex->nm.lockLevel = count;
|
||||
mutex->lockThread = thread;
|
||||
mutex->nm.lockThread = thread;
|
||||
}
|
||||
|
||||
void __KernelMutexAcquireLock(Mutex *mutex, int count)
|
||||
@@ -188,10 +187,10 @@ void __KernelMutexAcquireLock(Mutex *mutex, int count)
|
||||
|
||||
void __KernelMutexEraseLock(Mutex *mutex)
|
||||
{
|
||||
if (mutex->lockThread != -1)
|
||||
if (mutex->nm.lockThread != -1)
|
||||
{
|
||||
SceUID id = mutex->GetUID();
|
||||
std::pair<MutexMap::iterator, MutexMap::iterator> locked = mutexHeldLocks.equal_range(mutex->lockThread);
|
||||
std::pair<MutexMap::iterator, MutexMap::iterator> locked = mutexHeldLocks.equal_range(mutex->nm.lockThread);
|
||||
for (MutexMap::iterator iter = locked.first; iter != locked.second; ++iter)
|
||||
{
|
||||
if ((*iter).second == id)
|
||||
@@ -201,7 +200,7 @@ void __KernelMutexEraseLock(Mutex *mutex)
|
||||
}
|
||||
}
|
||||
}
|
||||
mutex->lockThread = -1;
|
||||
mutex->nm.lockThread = -1;
|
||||
}
|
||||
|
||||
std::vector<SceUID>::iterator __KernelMutexFindPriority(std::vector<SceUID> &waiting)
|
||||
@@ -245,7 +244,7 @@ int sceKernelCreateMutex(const char *name, u32 attr, int initialCount, u32 optio
|
||||
Mutex *mutex = new Mutex();
|
||||
SceUID id = kernelObjects.Create(mutex);
|
||||
|
||||
mutex->nm.size = sizeof(mutex);
|
||||
mutex->nm.size = sizeof(mutex->nm);
|
||||
strncpy(mutex->nm.name, name, KERNELOBJECT_MAX_NAME_LENGTH);
|
||||
mutex->nm.name[KERNELOBJECT_MAX_NAME_LENGTH] = 0;
|
||||
mutex->nm.attr = attr;
|
||||
@@ -253,7 +252,7 @@ int sceKernelCreateMutex(const char *name, u32 attr, int initialCount, u32 optio
|
||||
if (initialCount == 0)
|
||||
{
|
||||
mutex->nm.lockLevel = 0;
|
||||
mutex->lockThread = -1;
|
||||
mutex->nm.lockThread = -1;
|
||||
}
|
||||
else
|
||||
__KernelMutexAcquireLock(mutex, initialCount);
|
||||
@@ -307,7 +306,7 @@ int sceKernelDeleteMutex(SceUID id)
|
||||
for (iter = mutex->waitingThreads.begin(), end = mutex->waitingThreads.end(); iter != end; ++iter)
|
||||
wokeThreads |= __KernelUnlockMutexForThread(mutex, *iter, error, SCE_KERNEL_ERROR_WAIT_DELETE);
|
||||
|
||||
if (mutex->lockThread != -1)
|
||||
if (mutex->nm.lockThread != -1)
|
||||
__KernelMutexEraseLock(mutex);
|
||||
mutex->waitingThreads.clear();
|
||||
|
||||
@@ -343,7 +342,7 @@ bool __KernelLockMutex(Mutex *mutex, int count, u32 &error)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mutex->lockThread == __KernelGetCurThread())
|
||||
if (mutex->nm.lockThread == __KernelGetCurThread())
|
||||
{
|
||||
// Recursive mutex, let's just increase the lock count and keep going
|
||||
if (mutex->nm.attr & PSP_MUTEX_ATTR_ALLOW_RECURSIVE)
|
||||
@@ -379,7 +378,7 @@ bool __KernelUnlockMutex(Mutex *mutex, u32 &error)
|
||||
}
|
||||
|
||||
if (!wokeThreads)
|
||||
mutex->lockThread = -1;
|
||||
mutex->nm.lockThread = -1;
|
||||
|
||||
return wokeThreads;
|
||||
}
|
||||
@@ -528,7 +527,7 @@ int sceKernelUnlockMutex(SceUID id, int count)
|
||||
return SCE_KERNEL_ERROR_ILLEGAL_COUNT;
|
||||
if ((mutex->nm.attr & PSP_MUTEX_ATTR_ALLOW_RECURSIVE) == 0 && count > 1)
|
||||
return SCE_KERNEL_ERROR_ILLEGAL_COUNT;
|
||||
if (mutex->nm.lockLevel == 0 || mutex->lockThread != __KernelGetCurThread())
|
||||
if (mutex->nm.lockLevel == 0 || mutex->nm.lockThread != __KernelGetCurThread())
|
||||
return PSP_MUTEX_ERROR_NOT_LOCKED;
|
||||
if (mutex->nm.lockLevel < count)
|
||||
return PSP_MUTEX_ERROR_UNLOCK_UNDERFLOW;
|
||||
@@ -605,9 +604,13 @@ int sceKernelReferMutexStatus(SceUID id, u32 infoAddr)
|
||||
if (!Memory::IsValidAddress(infoAddr))
|
||||
return -1;
|
||||
|
||||
// Refresh and write
|
||||
m->nm.numWaitThreads = m->waitingThreads.size();
|
||||
Memory::WriteStruct(infoAddr, &m->nm);
|
||||
// Don't write if the size is 0. Anything else is A-OK, though, apparently.
|
||||
if (Memory::Read_U32(infoAddr) != 0)
|
||||
{
|
||||
// Refresh and write
|
||||
m->nm.numWaitThreads = m->waitingThreads.size();
|
||||
Memory::WriteStruct(infoAddr, &m->nm);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user