2014-12-22 23:31:11 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-06-19 15:49:38 +00:00
|
|
|
namespace vm { using namespace ps3; }
|
|
|
|
|
2014-12-22 23:31:11 +00:00
|
|
|
// attr_protocol (waiting scheduling policy)
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// First In, First Out
|
|
|
|
SYS_SYNC_FIFO = 1,
|
|
|
|
// Priority Order
|
|
|
|
SYS_SYNC_PRIORITY = 2,
|
|
|
|
// Basic Priority Inheritance Protocol (probably not implemented)
|
|
|
|
SYS_SYNC_PRIORITY_INHERIT = 3,
|
|
|
|
// Not selected while unlocking
|
|
|
|
SYS_SYNC_RETRY = 4,
|
|
|
|
//
|
|
|
|
SYS_SYNC_ATTR_PROTOCOL_MASK = 0xF,
|
|
|
|
};
|
|
|
|
|
|
|
|
// attr_recursive (recursive locks policy)
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// Recursive locks are allowed
|
|
|
|
SYS_SYNC_RECURSIVE = 0x10,
|
|
|
|
// Recursive locks are NOT allowed
|
|
|
|
SYS_SYNC_NOT_RECURSIVE = 0x20,
|
|
|
|
//
|
|
|
|
SYS_SYNC_ATTR_RECURSIVE_MASK = 0xF0, //???
|
|
|
|
};
|
|
|
|
|
2015-02-21 20:54:53 +00:00
|
|
|
// attr_pshared
|
|
|
|
enum
|
|
|
|
{
|
2015-06-24 16:25:37 +00:00
|
|
|
SYS_SYNC_NOT_PROCESS_SHARED = 0x200,
|
|
|
|
};
|
|
|
|
|
|
|
|
// attr_adaptive
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SYS_SYNC_ADAPTIVE = 0x1000,
|
|
|
|
SYS_SYNC_NOT_ADAPTIVE = 0x2000,
|
2015-02-21 20:54:53 +00:00
|
|
|
};
|
|
|
|
|
2015-07-07 22:33:24 +00:00
|
|
|
using sleep_queue_t = std::deque<std::shared_ptr<CPUThread>>;
|
|
|
|
|
2015-07-19 12:58:11 +00:00
|
|
|
static struct defer_sleep_t{} const defer_sleep{};
|
2015-07-19 01:56:33 +00:00
|
|
|
|
|
|
|
// automatic object handling a thread entry in the sleep queue
|
2015-07-07 22:33:24 +00:00
|
|
|
class sleep_queue_entry_t final
|
2014-12-22 23:31:11 +00:00
|
|
|
{
|
2015-07-07 22:33:24 +00:00
|
|
|
CPUThread& m_thread;
|
|
|
|
sleep_queue_t& m_queue;
|
2014-12-24 16:09:32 +00:00
|
|
|
|
2015-07-19 01:56:33 +00:00
|
|
|
void add_entry();
|
|
|
|
void remove_entry();
|
|
|
|
bool find() const;
|
|
|
|
|
2014-12-24 16:09:32 +00:00
|
|
|
public:
|
2015-07-19 01:56:33 +00:00
|
|
|
// add specified thread to the sleep queue
|
2015-07-07 22:33:24 +00:00
|
|
|
sleep_queue_entry_t(CPUThread& cpu, sleep_queue_t& queue);
|
2014-12-28 13:15:22 +00:00
|
|
|
|
2015-07-19 01:56:33 +00: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
|
2015-07-07 22:33:24 +00:00
|
|
|
~sleep_queue_entry_t() noexcept(false);
|
2015-07-19 01:56:33 +00: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-22 23:31:11 +00:00
|
|
|
};
|