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

56 lines
966 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-11-26 09:06:29 +01:00
m_queue.emplace_back(std::static_pointer_cast<CPUThread>(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;
}
2015-11-26 09:06:29 +01:00
sleep_queue_entry_t::sleep_queue_entry_t(sleep_entry_t& cpu, sleep_queue_t& queue)
2015-07-19 03:56:33 +02:00
: 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
}
2015-11-26 09:06:29 +01:00
sleep_queue_entry_t::sleep_queue_entry_t(sleep_entry_t& cpu, sleep_queue_t& queue, const defer_sleep_t&)
2015-07-19 03:56:33 +02:00
: 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
}