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,53 +35,51 @@ 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)
{
std::unique_lock<std::mutex> lock(m_mutex);
while (!m_askForTermination)
if (!lock)
{
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);
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_isThreadAlive = false;
});
m_worker.detach();
}
GarbageCollectionThread::~GarbageCollectionThread()
{
m_askForTermination = true;
while (m_isThreadAlive);
{
std::unique_lock<std::mutex> lock(m_mutex);
m_askForTermination = true;
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();
{
std::unique_lock<std::mutex> lock(m_mutex);
m_queue.push(f);
}
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;