1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-26 12:42:41 +01:00
rpcs3/Utilities/SleepQueue.cpp

56 lines
921 B
C++
Raw Normal View History

2014-12-23 00:31:11 +01:00
#include "stdafx.h"
#include "Emu/CPU/CPUThread.h"
#include "SleepQueue.h"
2014-12-23 00:31:11 +01:00
2015-07-19 03:56:33 +02:00
void sleep_queue_entry_t::add_entry()
2014-12-24 17:09:32 +01:00
{
2015-07-19 03:56:33 +02:00
m_queue.emplace_back(m_thread.shared_from_this());
2014-12-23 00:31:11 +01:00
}
2015-07-19 03:56:33 +02:00
void sleep_queue_entry_t::remove_entry()
2014-12-23 00:31:11 +01:00
{
for (auto it = m_queue.begin(); it != m_queue.end(); it++)
{
if (it->get() == &m_thread)
{
m_queue.erase(it);
return;
}
}
2015-07-19 03:56:33 +02:00
}
2014-12-23 00:31:11 +01:00
2015-07-19 03:56:33 +02:00
bool sleep_queue_entry_t::find() const
{
for (auto it = m_queue.begin(); it != m_queue.end(); it++)
2014-12-23 00:31:11 +01:00
{
2015-07-19 03:56:33 +02:00
if (it->get() == &m_thread)
{
return true;
}
2014-12-23 00:31:11 +01:00
}
2015-07-19 03:56:33 +02:00
return false;
}
sleep_queue_entry_t::sleep_queue_entry_t(CPUThread& cpu, sleep_queue_t& queue)
: m_thread(cpu)
, m_queue(queue)
{
add_entry();
2015-07-19 13:36:32 +02:00
cpu.sleep();
2015-07-19 03:56:33 +02:00
}
sleep_queue_entry_t::sleep_queue_entry_t(CPUThread& cpu, sleep_queue_t& queue, const defer_sleep_t&)
: m_thread(cpu)
, m_queue(queue)
{
2015-07-19 13:36:32 +02:00
cpu.sleep();
2015-07-19 03:56:33 +02:00
}
sleep_queue_entry_t::~sleep_queue_entry_t()
2015-07-19 03:56:33 +02:00
{
remove_entry();
2015-07-19 13:36:32 +02:00
m_thread.awake();
2014-12-23 00:31:11 +01:00
}