mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-06 06:51:26 +12:00
d3d12: Signal thread termination request + use a producer/consumer pattern closer to other ones in rpcs3.
This commit is contained in:
parent
7843b23ee1
commit
cf1c86bb2f
2 changed files with 31 additions and 4 deletions
|
@ -35,21 +35,46 @@ void SetGetD3DGSFrameCallback(GetGSFrameCb2 value)
|
||||||
|
|
||||||
GarbageCollectionThread::GarbageCollectionThread()
|
GarbageCollectionThread::GarbageCollectionThread()
|
||||||
{
|
{
|
||||||
|
m_isThreadAlive = true;
|
||||||
|
m_askForTermination = false;
|
||||||
m_worker = std::thread([this]() {
|
m_worker = std::thread([this]() {
|
||||||
while (true)
|
while (m_isThreadAlive)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
while (m_queue.empty())
|
while (!m_askForTermination)
|
||||||
|
{
|
||||||
|
CHECK_EMU_STATUS;
|
||||||
|
|
||||||
|
if (!lock)
|
||||||
|
{
|
||||||
|
lock.lock();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_queue.empty())
|
||||||
|
{
|
||||||
|
auto func = std::move(m_queue.front());
|
||||||
|
|
||||||
|
m_queue.pop();
|
||||||
|
|
||||||
|
if (lock) lock.unlock();
|
||||||
|
|
||||||
|
func();
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
cv.wait(lock);
|
cv.wait(lock);
|
||||||
m_queue.front()();
|
}
|
||||||
m_queue.pop();
|
|
||||||
}
|
}
|
||||||
|
m_isThreadAlive = false;
|
||||||
});
|
});
|
||||||
m_worker.detach();
|
m_worker.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
GarbageCollectionThread::~GarbageCollectionThread()
|
GarbageCollectionThread::~GarbageCollectionThread()
|
||||||
{
|
{
|
||||||
|
m_askForTermination = true;
|
||||||
|
while (m_isThreadAlive);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GarbageCollectionThread::pushWork(std::function<void()>&& f)
|
void GarbageCollectionThread::pushWork(std::function<void()>&& f)
|
||||||
|
|
|
@ -215,6 +215,8 @@ struct DataHeap
|
||||||
*/
|
*/
|
||||||
struct GarbageCollectionThread
|
struct GarbageCollectionThread
|
||||||
{
|
{
|
||||||
|
bool m_isThreadAlive;
|
||||||
|
bool m_askForTermination;
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
std::queue<std::function<void()> > m_queue;
|
std::queue<std::function<void()> > m_queue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue