rpcs3/Utilities/SleepQueue.cpp

56 lines
966 B
C++
Raw Normal View History

2014-12-22 23:31:11 +00:00
#include "stdafx.h"
#include "Emu/CPU/CPUThread.h"
#include "SleepQueue.h"
2014-12-22 23:31:11 +00:00
2015-07-19 01:56:33 +00:00
void sleep_queue_entry_t::add_entry()
2014-12-24 16:09:32 +00:00
{
2015-11-26 08:06:29 +00:00
m_queue.emplace_back(std::static_pointer_cast<CPUThread>(m_thread.shared_from_this()));
2014-12-22 23:31:11 +00:00
}
2015-07-19 01:56:33 +00:00
void sleep_queue_entry_t::remove_entry()
2014-12-22 23:31:11 +00: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 01:56:33 +00:00
}
2014-12-22 23:31:11 +00:00
2015-07-19 01:56:33 +00:00
bool sleep_queue_entry_t::find() const
{
for (auto it = m_queue.begin(); it != m_queue.end(); it++)
2014-12-22 23:31:11 +00:00
{
2015-07-19 01:56:33 +00:00
if (it->get() == &m_thread)
{
return true;
}
2014-12-22 23:31:11 +00:00
}
2015-07-19 01:56:33 +00:00
return false;
}
2015-11-26 08:06:29 +00:00
sleep_queue_entry_t::sleep_queue_entry_t(sleep_entry_t& cpu, sleep_queue_t& queue)
2015-07-19 01:56:33 +00:00
: m_thread(cpu)
, m_queue(queue)
{
add_entry();
2015-07-19 11:36:32 +00:00
cpu.sleep();
2015-07-19 01:56:33 +00:00
}
2015-11-26 08:06:29 +00:00
sleep_queue_entry_t::sleep_queue_entry_t(sleep_entry_t& cpu, sleep_queue_t& queue, const defer_sleep_t&)
2015-07-19 01:56:33 +00:00
: m_thread(cpu)
, m_queue(queue)
{
2015-07-19 11:36:32 +00:00
cpu.sleep();
2015-07-19 01:56:33 +00:00
}
sleep_queue_entry_t::~sleep_queue_entry_t()
2015-07-19 01:56:33 +00:00
{
remove_entry();
2015-07-19 11:36:32 +00:00
m_thread.awake();
2014-12-22 23:31:11 +00:00
}