2014-12-22 23:31:11 +00:00
|
|
|
#include "stdafx.h"
|
2015-07-07 22:33:24 +00:00
|
|
|
#include "Emu/CPU/CPUThread.h"
|
2015-08-07 21:37:32 +00:00
|
|
|
|
|
|
|
#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
|
|
|
{
|
2015-07-07 22:33:24 +00:00
|
|
|
for (auto it = m_queue.begin(); it != m_queue.end(); it++)
|
2015-01-01 23:41:29 +00:00
|
|
|
{
|
2015-07-07 22:33:24 +00:00
|
|
|
if (it->get() == &m_thread)
|
2015-01-01 23:41:29 +00:00
|
|
|
{
|
2015-07-07 22:33:24 +00:00
|
|
|
m_queue.erase(it);
|
|
|
|
return;
|
2015-01-01 23:41:29 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2015-08-19 11:04:58 +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
|
|
|
}
|