mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 13:31:27 +12:00
Some cleanup
This commit is contained in:
parent
f6ba1eaebd
commit
a74e07dc40
15 changed files with 74 additions and 196 deletions
|
@ -1,11 +1,9 @@
|
|||
#pragma once
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
//#include <Utilities/SSemaphore.h>
|
||||
|
||||
static std::thread::id main_thread;
|
||||
|
||||
|
@ -35,16 +33,9 @@ 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 WaitForAnySignal();
|
||||
|
||||
void Notify() // wake up waiting thread or nothing
|
||||
{
|
||||
m_signal_cv.notify_one();
|
||||
}
|
||||
void Notify();
|
||||
};
|
||||
|
||||
NamedThreadBase* GetCurrentNamedThread();
|
||||
|
@ -89,132 +80,4 @@ public:
|
|||
void detach();
|
||||
void join();
|
||||
bool joinable() const;
|
||||
};
|
||||
|
||||
template<typename T> class MTPacketBuffer
|
||||
{
|
||||
protected:
|
||||
volatile bool m_busy;
|
||||
volatile u32 m_put, m_get;
|
||||
std::vector<u8> m_buffer;
|
||||
u32 m_max_buffer_size;
|
||||
mutable std::recursive_mutex m_cs_main;
|
||||
|
||||
void CheckBusy()
|
||||
{
|
||||
m_busy = m_put >= m_max_buffer_size;
|
||||
}
|
||||
|
||||
public:
|
||||
MTPacketBuffer(u32 max_buffer_size)
|
||||
: m_max_buffer_size(max_buffer_size)
|
||||
{
|
||||
Flush();
|
||||
}
|
||||
|
||||
~MTPacketBuffer()
|
||||
{
|
||||
Flush();
|
||||
}
|
||||
|
||||
void Flush()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_cs_main);
|
||||
m_put = m_get = 0;
|
||||
m_buffer.clear();
|
||||
m_busy = false;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void _push(const T& v) = 0;
|
||||
virtual T _pop() = 0;
|
||||
|
||||
public:
|
||||
void Push(const T& v)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_cs_main);
|
||||
_push(v);
|
||||
}
|
||||
|
||||
T Pop()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_cs_main);
|
||||
return _pop();
|
||||
}
|
||||
|
||||
bool HasNewPacket() const { std::lock_guard<std::recursive_mutex> lock(m_cs_main); return m_put != m_get; }
|
||||
bool IsBusy() const { return m_busy; }
|
||||
};
|
||||
|
||||
/*
|
||||
class StepThread : public ThreadBase
|
||||
{
|
||||
wxSemaphore m_main_sem;
|
||||
wxSemaphore m_destroy_sem;
|
||||
volatile bool m_exit;
|
||||
|
||||
protected:
|
||||
StepThread(const std::string& name = "Unknown StepThread")
|
||||
: ThreadBase(true, name)
|
||||
, m_exit(false)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~StepThread() throw()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void Task()
|
||||
{
|
||||
m_exit = false;
|
||||
|
||||
while(!TestDestroy())
|
||||
{
|
||||
m_main_sem.Wait();
|
||||
|
||||
if(TestDestroy() || m_exit) break;
|
||||
|
||||
Step();
|
||||
}
|
||||
|
||||
while(!TestDestroy()) std::this_thread::sleep_for(std::chrono::milliseconds(0));
|
||||
if(m_destroy_sem.TryWait() != wxSEMA_NO_ERROR) m_destroy_sem.Post();
|
||||
}
|
||||
|
||||
virtual void Step()=0;
|
||||
|
||||
public:
|
||||
void DoStep()
|
||||
{
|
||||
if(IsRunning()) m_main_sem.Post();
|
||||
}
|
||||
|
||||
void WaitForExit()
|
||||
{
|
||||
if(TestDestroy()) m_destroy_sem.Wait();
|
||||
}
|
||||
|
||||
void WaitForNextStep()
|
||||
{
|
||||
if(!IsRunning()) return;
|
||||
|
||||
while(m_main_sem.TryWait() != wxSEMA_NO_ERROR) std::this_thread::sleep_for(std::chrono::milliseconds(0));
|
||||
}
|
||||
|
||||
void Exit(bool wait = false)
|
||||
{
|
||||
if(!IsAlive()) return;
|
||||
|
||||
if(m_main_sem.TryWait() != wxSEMA_NO_ERROR)
|
||||
{
|
||||
m_exit = true;
|
||||
m_main_sem.Post();
|
||||
}
|
||||
|
||||
Delete();
|
||||
|
||||
if(wait) WaitForExit();
|
||||
}
|
||||
};
|
||||
*/
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue