time: Remove delay execution

* Causes high cpu usage in Tohou Luna Nights
This commit is contained in:
IndecisiveTurtle 2024-11-17 22:58:24 +02:00
parent 2378ff44e0
commit b83ba7f945
4 changed files with 10 additions and 31 deletions

View file

@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstring>
#include <unordered_map>
#include "common/assert.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/kernel/kernel.h"

View file

@ -191,13 +191,6 @@ int PthreadMutex::Lock(const OrbisKernelTimespec* abstime, u64 usec) {
return SelfLock(abstime, usec);
}
int ret = 0;
SCOPE_EXIT {
if (ret == 0) {
curthread->Enqueue(this);
}
};
/*
* For adaptive mutexes, spin for a bit in the expectation
* that if the application requests this mutex type then
@ -208,6 +201,7 @@ int PthreadMutex::Lock(const OrbisKernelTimespec* abstime, u64 usec) {
int count = m_spinloops;
while (count--) {
if (m_lock.try_lock()) {
m_owner = curthread;
return 0;
}
CPU_SPINWAIT;
@ -217,11 +211,13 @@ int PthreadMutex::Lock(const OrbisKernelTimespec* abstime, u64 usec) {
while (count--) {
std::this_thread::yield();
if (m_lock.try_lock()) {
m_owner = curthread;
return 0;
}
}
}
int ret = 0;
if (abstime == nullptr) {
m_lock.lock();
} else if (abstime != THR_RELTIME && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
@ -234,6 +230,9 @@ int PthreadMutex::Lock(const OrbisKernelTimespec* abstime, u64 usec) {
ret = m_lock.try_lock_until(abstime->TimePoint()) ? 0 : POSIX_ETIMEDOUT;
}
}
if (ret == 0) {
m_owner = curthread;
}
return ret;
}
@ -244,7 +243,7 @@ int PthreadMutex::TryLock() {
}
const int ret = m_lock.try_lock() ? 0 : POSIX_EBUSY;
if (ret == 0) {
curthread->Enqueue(this);
m_owner = curthread;
}
return ret;
}
@ -286,7 +285,7 @@ int PthreadMutex::Unlock() {
int defered = True(m_flags & PthreadMutexFlags::Defered);
m_flags &= ~PthreadMutexFlags::Defered;
curthread->Dequeue(this);
m_owner = nullptr;
m_lock.unlock();
if (curthread->will_sleep == 0 && defered) {

View file

@ -274,8 +274,6 @@ struct Pthread {
Pthread* joiner;
ThreadFlags flags;
ThreadListFlags tlflags;
std::list<PthreadMutex> mutexq;
std::list<PthreadMutex> pp_mutexq;
void* ret;
PthreadSpecificElem* specific;
int specific_data_count;
@ -330,16 +328,6 @@ struct Pthread {
return true;
}
}
void Enqueue(PthreadMutex* mutex) {
mutex->m_owner = this;
// mutexq.push_back(*mutex);
}
void Dequeue(PthreadMutex* mutex) {
mutex->m_owner = nullptr;
// mutexq.erase(decltype(mutexq)::s_iterator_to(*mutex));
}
};
using PthreadT = Pthread*;

View file

@ -52,14 +52,7 @@ u64 PS4_SYSV_ABI sceKernelReadTsc() {
int PS4_SYSV_ABI sceKernelUsleep(u32 microseconds) {
#ifdef _WIN64
if (microseconds < 1000u) {
LARGE_INTEGER interval{
.QuadPart = -1 * (microseconds * 10u),
};
NtDelayExecution(FALSE, &interval);
} else {
std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
}
std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
return 0;
#else
timespec start;