mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-20 22:05:12 +00:00
This commit is contained in:
commit
7a1d44b552
42 changed files with 2804 additions and 314 deletions
|
|
@ -6,9 +6,9 @@ __forceinline void SM_Sleep()
|
|||
Sleep(1);
|
||||
}
|
||||
|
||||
__forceinline std::thread::id SM_GetCurrentThreadId()
|
||||
__forceinline size_t SM_GetCurrentThreadId()
|
||||
{
|
||||
return std::this_thread::get_id();
|
||||
return std::this_thread::get_id().hash();
|
||||
}
|
||||
|
||||
__forceinline u32 SM_GetCurrentCPUThreadId()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
extern void SM_Sleep();
|
||||
extern std::thread::id SM_GetCurrentThreadId();
|
||||
extern size_t SM_GetCurrentThreadId();
|
||||
extern u32 SM_GetCurrentCPUThreadId();
|
||||
extern be_t<u32> SM_GetCurrentCPUThreadIdBE();
|
||||
|
||||
|
|
@ -20,13 +20,13 @@ enum SMutexResult
|
|||
template
|
||||
<
|
||||
typename T,
|
||||
u32 free_value = 0,
|
||||
u32 dead_value = ~0,
|
||||
u64 free_value = 0,
|
||||
u64 dead_value = ~0,
|
||||
void (*wait)() = SM_Sleep
|
||||
>
|
||||
class SMutexBase
|
||||
{
|
||||
static_assert(sizeof(T) == 4, "Invalid SMutexBase typename");
|
||||
static_assert(sizeof(T) == sizeof(std::atomic<T>), "Invalid SMutexBase type");
|
||||
std::atomic<T> owner;
|
||||
|
||||
public:
|
||||
|
|
@ -157,14 +157,14 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
typedef SMutexBase<DWORD>
|
||||
typedef SMutexBase<size_t>
|
||||
SMutexGeneral;
|
||||
typedef SMutexBase<u32>
|
||||
SMutex;
|
||||
typedef SMutexBase<be_t<u32>>
|
||||
SMutexBE;
|
||||
|
||||
typedef SMutexLockerBase<std::thread::id, SM_GetCurrentThreadId>
|
||||
typedef SMutexLockerBase<size_t, SM_GetCurrentThreadId>
|
||||
SMutexGeneralLocker;
|
||||
typedef SMutexLockerBase<u32, SM_GetCurrentCPUThreadId>
|
||||
SMutexLocker;
|
||||
|
|
|
|||
99
Utilities/SQueue.h
Normal file
99
Utilities/SQueue.h
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#pragma once
|
||||
|
||||
template<typename T, u32 SQSize = 666>
|
||||
class SQueue
|
||||
{
|
||||
SMutex m_mutex;
|
||||
u32 m_pos;
|
||||
u32 m_count;
|
||||
T m_data[SQSize];
|
||||
|
||||
public:
|
||||
SQueue()
|
||||
: m_pos(0)
|
||||
, m_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool Push(T& data)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (Emu.IsStopped())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_mutex.GetOwner() == m_mutex.GetDeadValue())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_count >= SQSize)
|
||||
{
|
||||
Sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
SMutexLocker lock(m_mutex);
|
||||
|
||||
if (m_count >= SQSize) continue;
|
||||
|
||||
m_data[(m_pos + m_count++) % SQSize] = data;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Pop(T& data)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (Emu.IsStopped())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_mutex.GetOwner() == m_mutex.GetDeadValue())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_count)
|
||||
{
|
||||
Sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
SMutexLocker lock(m_mutex);
|
||||
|
||||
if (!m_count) continue;
|
||||
|
||||
data = m_data[m_pos];
|
||||
m_pos = (m_pos + 1) % SQSize;
|
||||
m_count--;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
volatile u32 GetCount()
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
volatile bool IsEmpty()
|
||||
{
|
||||
return !m_count;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
SMutexLocker lock(m_mutex);
|
||||
m_count = 0;
|
||||
}
|
||||
};
|
||||
|
|
@ -117,10 +117,12 @@ thread::thread()
|
|||
}
|
||||
|
||||
void thread::start(std::function<void()> func)
|
||||
{ // got a crash related with strings
|
||||
m_thr = std::thread([this, func]()
|
||||
{
|
||||
std::string name = m_name;
|
||||
|
||||
m_thr = std::thread([func, name]()
|
||||
{
|
||||
NamedThreadBase info(m_name);
|
||||
NamedThreadBase info(name);
|
||||
g_tls_this_thread = &info;
|
||||
|
||||
try
|
||||
|
|
@ -130,7 +132,7 @@ void thread::start(std::function<void()> func)
|
|||
catch(...)
|
||||
{
|
||||
ConLog.Error("Crash :(");
|
||||
std::terminate();
|
||||
//std::terminate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue