1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-23 03:02:53 +01:00

d3d12: Do not detach garbage collection thread

Thanks Neko for the tips.
This commit is contained in:
Vincent Lejeune 2015-08-11 22:04:15 +02:00
parent cf1c86bb2f
commit 9cb7339067
2 changed files with 31 additions and 34 deletions

View File

@ -35,16 +35,11 @@ void SetGetD3DGSFrameCallback(GetGSFrameCb2 value)
GarbageCollectionThread::GarbageCollectionThread()
{
m_isThreadAlive = true;
m_askForTermination = false;
m_worker = std::thread([this]() {
while (m_isThreadAlive)
{
std::unique_lock<std::mutex> lock(m_mutex);
while (!m_askForTermination)
{
CHECK_EMU_STATUS;
if (!lock)
{
lock.lock();
@ -65,23 +60,26 @@ GarbageCollectionThread::GarbageCollectionThread()
}
cv.wait(lock);
}
}
m_isThreadAlive = false;
});
m_worker.detach();
}
GarbageCollectionThread::~GarbageCollectionThread()
{
{
std::unique_lock<std::mutex> lock(m_mutex);
m_askForTermination = true;
while (m_isThreadAlive);
cv.notify_one();
}
m_worker.join();
}
void GarbageCollectionThread::pushWork(std::function<void()>&& f)
{
{
std::unique_lock<std::mutex> lock(m_mutex);
m_queue.push(f);
cv.notify_all();
}
cv.notify_one();
}
void GarbageCollectionThread::waitForCompletion()

View File

@ -215,8 +215,7 @@ struct DataHeap
*/
struct GarbageCollectionThread
{
bool m_isThreadAlive;
bool m_askForTermination;
std::atomic<bool> m_askForTermination;
std::mutex m_mutex;
std::condition_variable cv;
std::queue<std::function<void()> > m_queue;