SMutex partially replaced with std::mutex
SPURecompiler.h: SETcc bug fixed
This commit is contained in:
@@ -8,7 +8,14 @@
|
||||
|
||||
__forceinline void SM_Sleep()
|
||||
{
|
||||
Sleep(1);
|
||||
if (NamedThreadBase* t = GetCurrentNamedThread())
|
||||
{
|
||||
t->WaitForAnySignal();
|
||||
}
|
||||
else
|
||||
{
|
||||
Sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
thread_local size_t g_this_thread_id = 0;
|
||||
|
||||
+8
-8
@@ -123,7 +123,7 @@ public:
|
||||
default: return res;
|
||||
}
|
||||
|
||||
wait();
|
||||
if (wait) wait();
|
||||
|
||||
if (timeout && counter++ > timeout)
|
||||
{
|
||||
@@ -133,14 +133,14 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, T (get_tid)()>
|
||||
template<typename T, typename Tid, Tid (get_tid)()>
|
||||
class SMutexLockerBase
|
||||
{
|
||||
SMutexBase<T>& sm;
|
||||
T& sm;
|
||||
public:
|
||||
const T tid;
|
||||
const Tid tid;
|
||||
|
||||
__forceinline SMutexLockerBase(SMutexBase<T>& _sm)
|
||||
__forceinline SMutexLockerBase(T& _sm)
|
||||
: sm(_sm)
|
||||
, tid(get_tid())
|
||||
{
|
||||
@@ -169,9 +169,9 @@ typedef SMutexBase<u32>
|
||||
typedef SMutexBase<be_t<u32>>
|
||||
SMutexBE;
|
||||
|
||||
typedef SMutexLockerBase<size_t, SM_GetCurrentThreadId>
|
||||
typedef SMutexLockerBase<SMutexGeneral, size_t, SM_GetCurrentThreadId>
|
||||
SMutexGeneralLocker;
|
||||
typedef SMutexLockerBase<u32, SM_GetCurrentCPUThreadId>
|
||||
typedef SMutexLockerBase<SMutex, u32, SM_GetCurrentCPUThreadId>
|
||||
SMutexLocker;
|
||||
typedef SMutexLockerBase<be_t<u32>, SM_GetCurrentCPUThreadIdBE>
|
||||
typedef SMutexLockerBase<SMutexBE, be_t<u32>, SM_GetCurrentCPUThreadIdBE>
|
||||
SMutexBELocker;
|
||||
|
||||
+5
-20
@@ -3,7 +3,7 @@
|
||||
template<typename T, u32 SQSize = 666>
|
||||
class SQueue
|
||||
{
|
||||
SMutexGeneral m_mutex;
|
||||
std::mutex m_mutex;
|
||||
u32 m_pos;
|
||||
u32 m_count;
|
||||
T m_data[SQSize];
|
||||
@@ -24,11 +24,6 @@ public:
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (m_mutex.GetOwner() == m_mutex.GetDeadValue())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_count >= SQSize)
|
||||
{
|
||||
if (Emu.IsStopped())
|
||||
@@ -40,7 +35,7 @@ public:
|
||||
}
|
||||
|
||||
{
|
||||
SMutexGeneralLocker lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
if (m_count >= SQSize) continue;
|
||||
|
||||
@@ -55,11 +50,6 @@ public:
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (m_mutex.GetOwner() == m_mutex.GetDeadValue())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_count)
|
||||
{
|
||||
if (Emu.IsStopped())
|
||||
@@ -71,7 +61,7 @@ public:
|
||||
}
|
||||
|
||||
{
|
||||
SMutexGeneralLocker lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
if (!m_count) continue;
|
||||
|
||||
@@ -96,7 +86,7 @@ public:
|
||||
|
||||
void Clear()
|
||||
{
|
||||
SMutexGeneralLocker lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
@@ -104,11 +94,6 @@ public:
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (m_mutex.GetOwner() == m_mutex.GetDeadValue())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!m_count)
|
||||
{
|
||||
if (Emu.IsStopped())
|
||||
@@ -120,7 +105,7 @@ public:
|
||||
}
|
||||
|
||||
{
|
||||
SMutexGeneralLocker lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_count) break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "Thread.h"
|
||||
|
||||
thread_local NamedThreadBase* g_tls_this_thread = nullptr;
|
||||
std::atomic<u32> g_thread_count = 0;
|
||||
std::atomic<u32> g_thread_count(0);
|
||||
|
||||
NamedThreadBase* GetCurrentNamedThread()
|
||||
{
|
||||
|
||||
@@ -13,6 +13,9 @@ class NamedThreadBase
|
||||
{
|
||||
std::string m_name;
|
||||
|
||||
std::condition_variable m_signal_cv;
|
||||
std::mutex m_signal_mtx;
|
||||
|
||||
public:
|
||||
NamedThreadBase(const std::string& name) : m_name(name)
|
||||
{
|
||||
@@ -24,6 +27,17 @@ public:
|
||||
|
||||
virtual std::string GetThreadName() const;
|
||||
virtual void SetThreadName(const std::string& name);
|
||||
|
||||
void WaitForAnySignal() // wait 1 ms for something
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_signal_mtx);
|
||||
m_signal_cv.wait_for(lock, std::chrono::milliseconds(1));
|
||||
}
|
||||
|
||||
void Notify() // wake up waiting thread or nothing
|
||||
{
|
||||
m_signal_cv.notify_one();
|
||||
}
|
||||
};
|
||||
|
||||
NamedThreadBase* GetCurrentNamedThread();
|
||||
|
||||
Reference in New Issue
Block a user