Added adaptive mutex initializer handling (#1353)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions

This commit is contained in:
Vladislav Mikhalin 2024-10-13 12:22:14 +03:00 committed by GitHub
parent 1cc4ab7e88
commit 8776eba8c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 7 deletions

View file

@ -36,6 +36,10 @@ void init_pthreads() {
ScePthreadMutexattr default_mutexattr = nullptr; ScePthreadMutexattr default_mutexattr = nullptr;
scePthreadMutexattrInit(&default_mutexattr); scePthreadMutexattrInit(&default_mutexattr);
g_pthread_cxt->setDefaultMutexattr(default_mutexattr); g_pthread_cxt->setDefaultMutexattr(default_mutexattr);
ScePthreadMutexattr adaptive_mutexattr = nullptr;
scePthreadMutexattrInit(&adaptive_mutexattr);
scePthreadMutexattrSettype(&adaptive_mutexattr, ORBIS_PTHREAD_MUTEX_ADAPTIVE);
g_pthread_cxt->setAdaptiveMutexattr(adaptive_mutexattr);
// default cond init // default cond init
ScePthreadCondattr default_condattr = nullptr; ScePthreadCondattr default_condattr = nullptr;
scePthreadCondattrInit(&default_condattr); scePthreadCondattrInit(&default_condattr);
@ -412,7 +416,8 @@ int PS4_SYSV_ABI scePthreadGetaffinity(ScePthread thread, /*SceKernelCpumask*/ u
} }
ScePthreadMutex* createMutex(ScePthreadMutex* addr) { ScePthreadMutex* createMutex(ScePthreadMutex* addr) {
if (addr == nullptr || *addr != nullptr) { if (addr == nullptr ||
(*addr != nullptr && *addr != ORBIS_PTHREAD_MUTEX_ADAPTIVE_INITIALIZER)) {
return addr; return addr;
} }
@ -429,14 +434,14 @@ int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMut
if (mutex == nullptr) { if (mutex == nullptr) {
return SCE_KERNEL_ERROR_EINVAL; return SCE_KERNEL_ERROR_EINVAL;
} }
if (mutex_attr == nullptr) { if (mutex_attr == nullptr || *mutex_attr == nullptr) {
attr = g_pthread_cxt->getDefaultMutexattr(); if (*mutex == ORBIS_PTHREAD_MUTEX_ADAPTIVE_INITIALIZER) {
} else { attr = g_pthread_cxt->getAdaptiveMutexattr();
if (*mutex_attr == nullptr) {
attr = g_pthread_cxt->getDefaultMutexattr();
} else { } else {
attr = mutex_attr; attr = g_pthread_cxt->getDefaultMutexattr();
} }
} else {
attr = mutex_attr;
} }
*mutex = new PthreadMutexInternal{}; *mutex = new PthreadMutexInternal{};

View file

@ -13,6 +13,8 @@
#include "common/types.h" #include "common/types.h"
#define ORBIS_PTHREAD_MUTEX_ADAPTIVE_INITIALIZER (reinterpret_cast<ScePthreadMutex>(1))
namespace Core::Loader { namespace Core::Loader {
class SymbolsResolver; class SymbolsResolver;
} }
@ -134,6 +136,12 @@ public:
void setDefaultMutexattr(ScePthreadMutexattr attr) { void setDefaultMutexattr(ScePthreadMutexattr attr) {
m_default_mutexattr = attr; m_default_mutexattr = attr;
} }
ScePthreadMutexattr* getAdaptiveMutexattr() {
return &m_adaptive_mutexattr;
}
void setAdaptiveMutexattr(ScePthreadMutexattr attr) {
m_adaptive_mutexattr = attr;
}
ScePthreadCondattr* getDefaultCondattr() { ScePthreadCondattr* getDefaultCondattr() {
return &m_default_condattr; return &m_default_condattr;
} }
@ -161,6 +169,7 @@ public:
private: private:
ScePthreadMutexattr m_default_mutexattr = nullptr; ScePthreadMutexattr m_default_mutexattr = nullptr;
ScePthreadMutexattr m_adaptive_mutexattr = nullptr;
ScePthreadCondattr m_default_condattr = nullptr; ScePthreadCondattr m_default_condattr = nullptr;
ScePthreadAttr m_default_attr = nullptr; ScePthreadAttr m_default_attr = nullptr;
PThreadPool* m_pthread_pool = nullptr; PThreadPool* m_pthread_pool = nullptr;