rpcsx/rpcs3/Emu/CPU/CPUThread.h

61 lines
1.4 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"
// cpu_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
suspend, // Thread paused
ret, // Callback return requested
signal, // Thread received a signal (HLE)
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
};
// cpu_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
{
2015-11-26 09:06:29 +01:00
void on_task() override;
2015-07-01 00:25:52 +02:00
public:
virtual void on_stop() override;
virtual ~cpu_thread() override;
const id_value<> id{};
2016-06-25 15:54:08 +02:00
cpu_thread();
2016-04-14 00:59:00 +02:00
// Public thread state
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
// Object associated with sleep state, possibly synchronization primitive (mutex, semaphore, etc.)
atomic_t<void*> owner{};
// Process thread state, return true if the checker must return
bool check_state();
// Run thread
void run();
virtual std::string dump() const = 0; // Print CPU state
virtual void cpu_init() {} // Obsolete, must be removed
2016-04-14 00:59:00 +02:00
virtual void cpu_task() = 0;
};
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;
}