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