mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-01 16:13:23 +00: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
@ -35,21 +35,46 @@ void SetGetD3DGSFrameCallback(GetGSFrameCb2 value)
|
||||
|
||||
GarbageCollectionThread::GarbageCollectionThread()
|
||||
{
|
||||
m_isThreadAlive = true;
|
||||
m_askForTermination = false;
|
||||
m_worker = std::thread([this]() {
|
||||
while (true)
|
||||
while (m_isThreadAlive)
|
||||
{
|
||||
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);
|
||||
m_queue.front()();
|
||||
m_queue.pop();
|
||||
}
|
||||
}
|
||||
m_isThreadAlive = false;
|
||||
});
|
||||
m_worker.detach();
|
||||
}
|
||||
|
||||
GarbageCollectionThread::~GarbageCollectionThread()
|
||||
{
|
||||
m_askForTermination = true;
|
||||
while (m_isThreadAlive);
|
||||
}
|
||||
|
||||
void GarbageCollectionThread::pushWork(std::function<void()>&& f)
|
||||
|
@ -215,6 +215,8 @@ struct DataHeap
|
||||
*/
|
||||
struct GarbageCollectionThread
|
||||
{
|
||||
bool m_isThreadAlive;
|
||||
bool m_askForTermination;
|
||||
std::mutex m_mutex;
|
||||
std::condition_variable cv;
|
||||
std::queue<std::function<void()> > m_queue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user