2014-12-23 00:31:11 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "Utilities/Log.h"
|
|
|
|
|
#include "Emu/Memory/Memory.h"
|
|
|
|
|
#include "Emu/System.h"
|
|
|
|
|
|
2015-07-08 00:33:24 +02:00
|
|
|
#include "Emu/CPU/CPUThread.h"
|
2015-03-02 22:09:20 +01:00
|
|
|
#include "sleep_queue.h"
|
2014-12-23 00:31:11 +01:00
|
|
|
|
2015-07-08 00:33:24 +02:00
|
|
|
sleep_queue_entry_t::sleep_queue_entry_t(CPUThread& cpu, sleep_queue_t& queue)
|
|
|
|
|
: m_queue(queue)
|
|
|
|
|
, m_thread(cpu)
|
2014-12-24 17:09:32 +01:00
|
|
|
{
|
2015-07-17 18:27:12 +02:00
|
|
|
m_queue.emplace_back(cpu.shared_from_this());
|
2015-01-02 00:41:29 +01:00
|
|
|
|
2015-07-08 00:33:24 +02:00
|
|
|
m_thread.Sleep();
|
2014-12-23 00:31:11 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-08 00:33:24 +02:00
|
|
|
sleep_queue_entry_t::~sleep_queue_entry_t() noexcept(false)
|
2014-12-23 00:31:11 +01:00
|
|
|
{
|
2015-07-08 00:33:24 +02:00
|
|
|
m_thread.Awake();
|
2015-01-02 00:41:29 +01:00
|
|
|
|
2015-07-08 00:33:24 +02:00
|
|
|
if (m_queue.front().get() == &m_thread)
|
2014-12-23 00:31:11 +01:00
|
|
|
{
|
2015-07-08 00:33:24 +02:00
|
|
|
m_queue.pop_front();
|
|
|
|
|
return;
|
2014-12-23 00:31:11 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-08 00:33:24 +02:00
|
|
|
if (m_queue.back().get() == &m_thread)
|
2014-12-23 00:31:11 +01:00
|
|
|
{
|
2015-07-08 00:33:24 +02:00
|
|
|
m_queue.pop_back();
|
|
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
}
|
2014-12-23 00:31:11 +01:00
|
|
|
|
2015-07-08 00:33:24 +02:00
|
|
|
if (!std::uncaught_exception())
|
2014-12-23 00:31:11 +01:00
|
|
|
{
|
2015-07-08 00:33:24 +02:00
|
|
|
throw EXCEPTION("Thread not found");
|
2014-12-23 00:31:11 +01:00
|
|
|
}
|
|
|
|
|
}
|