rpcs3/Utilities/SleepQueue.h

47 lines
968 B
C
Raw Normal View History

2014-12-23 02:31:11 +03:00
#pragma once
class CPUThread;
using sleep_queue_t = std::deque<std::shared_ptr<CPUThread>>;
static struct defer_sleep_t {} const defer_sleep{};
2015-07-19 04:56:33 +03:00
// automatic object handling a thread entry in the sleep queue
class sleep_queue_entry_t final
2014-12-23 02:31:11 +03:00
{
CPUThread& m_thread;
sleep_queue_t& m_queue;
2014-12-24 19:09:32 +03:00
2015-07-19 04:56:33 +03:00
void add_entry();
void remove_entry();
bool find() const;
2014-12-24 19:09:32 +03:00
public:
2015-07-19 04:56:33 +03:00
// add specified thread to the sleep queue
sleep_queue_entry_t(CPUThread& cpu, sleep_queue_t& queue);
2014-12-28 16:15:22 +03:00
2015-07-19 04:56:33 +03:00
// don't add specified thread to the sleep queue
sleep_queue_entry_t(CPUThread& cpu, sleep_queue_t& queue, const defer_sleep_t&);
// removes specified thread from the sleep queue if added
~sleep_queue_entry_t();
2015-07-19 04:56:33 +03:00
// add thread to the sleep queue
inline void enter()
{
add_entry();
}
// remove thread from the sleep queue
inline void leave()
{
remove_entry();
}
// check whether the thread exists in the sleep queue
inline explicit operator bool() const
{
return find();
}
2014-12-23 02:31:11 +03:00
};