mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-20 03:24:49 +00:00
NIMATA!
This commit is contained in:
parent
1395fd4939
commit
ad686972ff
3 changed files with 20 additions and 16 deletions
|
@ -8,6 +8,7 @@
|
|||
#include "Kernel/Objects/physical_memory.h"
|
||||
#include "Kernel/cpu_management.h"
|
||||
#include "Kernel/event_queues.h"
|
||||
#include <windows.h>
|
||||
|
||||
namespace HLE::Libs::LibKernel {
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Threads.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <chrono>
|
||||
|
||||
static std::thread::id g_main_thread;
|
||||
static int g_main_thread_int;
|
||||
|
@ -55,25 +56,28 @@ Lib::Mutex::Mutex() { m_mutex = new MutexStructInternal(); }
|
|||
|
||||
Lib::Mutex::~Mutex() { delete m_mutex; }
|
||||
|
||||
void Lib::Mutex::LockMutex() { EnterCriticalSection(&m_mutex->m_cs); }
|
||||
void Lib::Mutex::LockMutex() { m_mutex->m_cs.lock(); }
|
||||
|
||||
void Lib::Mutex::UnlockMutex() { LeaveCriticalSection(&m_mutex->m_cs); }
|
||||
void Lib::Mutex::UnlockMutex() { m_mutex->m_cs.unlock(); }
|
||||
|
||||
bool Lib::Mutex::TryLockMutex() { return (TryEnterCriticalSection(&m_mutex->m_cs) != 0); }
|
||||
bool Lib::Mutex::TryLockMutex() { return m_mutex->m_cs.try_lock(); }
|
||||
|
||||
Lib::ConditionVariable::ConditionVariable() { m_cond_var = new ConditionVariableStructInternal(); }
|
||||
|
||||
Lib::ConditionVariable::~ConditionVariable() { delete m_cond_var; }
|
||||
|
||||
void Lib::ConditionVariable::WaitCondVar(Mutex* mutex) { SleepConditionVariableCS(&m_cond_var->m_cv, &mutex->m_mutex->m_cs, INFINITE); }
|
||||
void Lib::ConditionVariable::WaitCondVar(Mutex* mutex) {
|
||||
std::unique_lock<std::mutex> lock(mutex->m_mutex->m_cs);
|
||||
m_cond_var->m_cv.wait(lock);
|
||||
}
|
||||
|
||||
bool Lib::ConditionVariable::WaitCondVarFor(Mutex* mutex, u32 micros) {
|
||||
bool ok = false;
|
||||
ok = !(SleepConditionVariableCS(&m_cond_var->m_cv, &mutex->m_mutex->m_cs, (micros < 1000 ? 1 : micros / 1000)) == 0 &&
|
||||
GetLastError() == ERROR_TIMEOUT);
|
||||
std::unique_lock<std::mutex> lock(mutex->m_mutex->m_cs);
|
||||
ok = m_cond_var->m_cv.wait_for(lock, std::chrono::microseconds(micros)) == std::cv_status::no_timeout;
|
||||
return ok;
|
||||
}
|
||||
|
||||
void Lib::ConditionVariable::SignalCondVar() { WakeConditionVariable(&m_cond_var->m_cv); }
|
||||
void Lib::ConditionVariable::SignalCondVar() { m_cond_var->m_cv.notify_one(); }
|
||||
|
||||
void Lib::ConditionVariable::SignalCondVarAll() { WakeAllConditionVariable(&m_cond_var->m_cv); }
|
||||
void Lib::ConditionVariable::SignalCondVarAll() { m_cond_var->m_cv.notify_all(); }
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "windows.h"
|
||||
#include <synchapi.h>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
|
@ -52,7 +51,7 @@ class Thread {
|
|||
};
|
||||
|
||||
struct ThreadStructInternal {
|
||||
ThreadStructInternal(thread_func_t f, void* a) : func(f), arg(a), m_thread(&Run, this) {}
|
||||
ThreadStructInternal(thread_func_t f, void* a) : func(f), arg(a), m_thread(&ThreadStructInternal::Run, this) {}
|
||||
|
||||
static void Run(ThreadStructInternal* t) {
|
||||
t->unique_id = Lib::Thread::GetThreadIdUnique();
|
||||
|
@ -89,9 +88,9 @@ class Mutex {
|
|||
};
|
||||
|
||||
struct MutexStructInternal {
|
||||
MutexStructInternal() { InitializeCriticalSectionAndSpinCount(&m_cs, 4000); }
|
||||
~MutexStructInternal() { DeleteCriticalSection(&m_cs); }
|
||||
CRITICAL_SECTION m_cs{};
|
||||
MutexStructInternal() = default;
|
||||
~MutexStructInternal() = default;
|
||||
std::mutex m_cs{};
|
||||
};
|
||||
class ConditionVariable {
|
||||
public:
|
||||
|
@ -108,9 +107,9 @@ class ConditionVariable {
|
|||
};
|
||||
|
||||
struct ConditionVariableStructInternal {
|
||||
ConditionVariableStructInternal() { InitializeConditionVariable(&m_cv); }
|
||||
ConditionVariableStructInternal() = default;
|
||||
~ConditionVariableStructInternal() = default;
|
||||
CONDITION_VARIABLE m_cv{};
|
||||
std::condition_variable m_cv{};
|
||||
};
|
||||
|
||||
class LockMutexGuard {
|
||||
|
|
Loading…
Add table
Reference in a new issue