rpcsx/rpcs3/Emu/CPU/CPUThread.h

76 lines
1.6 KiB
C
Raw Normal View History

#pragma once
2015-07-01 00:25:52 +02:00
2016-06-07 22:24:20 +02:00
#include "../Utilities/Thread.h"
2016-08-07 21:01:27 +02:00
#include "../Utilities/bit_set.h"
2016-08-13 16:58:19 +02:00
// Thread state flags
enum class cpu_flag : u32
2015-03-16 22:38:21 +01:00
{
2016-04-14 00:59:00 +02:00
stop, // Thread not running (HLE, initial state)
exit, // Irreversible exit
2017-02-06 19:36:46 +01:00
suspend, // Thread suspended
2016-04-14 00:59:00 +02:00
ret, // Callback return requested
signal, // Thread received a signal (HLE)
2017-03-11 00:14:48 +01:00
memory, // Thread must unlock memory mutex
2016-04-14 00:59:00 +02:00
dbg_global_pause, // Emulation paused
dbg_global_stop, // Emulation stopped
dbg_pause, // Thread paused
dbg_step, // Thread forced to pause after one step (one instruction, etc)
2016-08-07 21:01:27 +02:00
__bitset_enum_max
2015-03-16 22:38:21 +01:00
};
2016-08-13 16:58:19 +02:00
// Flag set for pause state
constexpr bs_t<cpu_flag> cpu_state_pause = cpu_flag::suspend + cpu_flag::dbg_global_pause + cpu_flag::dbg_pause;
2015-07-01 00:25:52 +02:00
2016-04-14 00:59:00 +02:00
class cpu_thread : public named_thread
{
2016-08-13 16:58:19 +02:00
void on_task() override final;
2015-07-01 00:25:52 +02:00
public:
virtual void on_stop() override;
virtual ~cpu_thread() override;
2017-01-25 18:50:30 +01:00
const u32 id;
2016-06-25 15:54:08 +02:00
2017-01-25 18:50:30 +01:00
cpu_thread(u32 id);
2016-04-14 00:59:00 +02:00
// Public thread state
2017-03-11 00:14:48 +01:00
atomic_t<bs_t<cpu_flag>> state{+cpu_flag::stop};
2016-04-14 00:59:00 +02:00
2016-05-13 16:01:48 +02:00
// Process thread state, return true if the checker must return
bool check_state();
// Process thread state
void test_state();
// Run thread
void run();
2017-01-25 18:50:30 +01:00
// Check thread type
u32 id_type()
{
return id >> 24;
}
// Thread stats for external observation
static atomic_t<u64> g_threads_created, g_threads_deleted;
2016-08-13 16:58:19 +02:00
// Print CPU state
virtual std::string dump() const;
// Thread entry point function
2016-04-14 00:59:00 +02:00
virtual void cpu_task() = 0;
2017-02-06 19:36:46 +01:00
// Callback for cpu_flag::suspend
virtual void cpu_sleep() {}
};
2016-04-14 00:59:00 +02:00
inline cpu_thread* get_current_cpu_thread() noexcept
{
2016-04-14 00:59:00 +02:00
extern thread_local cpu_thread* g_tls_current_cpu_thread;
return g_tls_current_cpu_thread;
}