d3d12: Signal thread termination request + use a producer/consumer pattern closer to other ones in rpcs3.

This commit is contained in:
Vincent Lejeune 2015-08-11 00:37:47 +02:00
parent 7843b23ee1
commit cf1c86bb2f
2 changed files with 31 additions and 4 deletions

View File

@ -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)

View File

@ -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;