Kernel: pass ref to timer

This commit is contained in:
Weiyi Wang 2018-10-12 16:26:23 -04:00
parent 247249d5d3
commit c141657d83
4 changed files with 17 additions and 14 deletions

View file

@ -18,6 +18,7 @@ class CodeSet;
class Process;
class Thread;
class Semaphore;
class Timer;
enum class ResetType {
OneShot,
@ -84,6 +85,14 @@ public:
*/
ResultVal<SharedPtr<Semaphore>> CreateSemaphore(s32 initial_count, s32 max_count,
std::string name = "Unknown");
/**
* Creates a timer
* @param reset_type ResetType describing how to create the timer
* @param name Optional name of timer
* @return The created Timer
*/
SharedPtr<Timer> CreateTimer(ResetType reset_type, std::string name = "Unknown");
};
} // namespace Kernel

View file

@ -986,8 +986,8 @@ static ResultCode ClearEvent(Handle handle) {
/// Creates a timer
static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) {
SharedPtr<Timer> timer = Timer::Create(static_cast<ResetType>(reset_type),
fmt ::format("timer-{:08x}", Core::CPU().GetReg(14)));
SharedPtr<Timer> timer = Core::System::GetInstance().Kernel().CreateTimer(
static_cast<ResetType>(reset_type), fmt ::format("timer-{:08x}", Core::CPU().GetReg(14)));
CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(timer)));
LOG_TRACE(Kernel_SVC, "called reset_type=0x{:08X} : created handle=0x{:08X}", reset_type,

View file

@ -19,11 +19,11 @@ static CoreTiming::EventType* timer_callback_event_type = nullptr;
// us to simply use a pool index or similar.
static Kernel::HandleTable timer_callback_handle_table;
Timer::Timer() {}
Timer::Timer(KernelSystem& kernel) {}
Timer::~Timer() {}
SharedPtr<Timer> Timer::Create(ResetType reset_type, std::string name) {
SharedPtr<Timer> timer(new Timer);
SharedPtr<Timer> KernelSystem::CreateTimer(ResetType reset_type, std::string name) {
SharedPtr<Timer> timer(new Timer(*this));
timer->reset_type = reset_type;
timer->signaled = false;

View file

@ -12,14 +12,6 @@ namespace Kernel {
class Timer final : public WaitObject {
public:
/**
* Creates a timer
* @param reset_type ResetType describing how to create the timer
* @param name Optional name of timer
* @return The created Timer
*/
static SharedPtr<Timer> Create(ResetType reset_type, std::string name = "Unknown");
std::string GetTypeName() const override {
return "Timer";
}
@ -68,7 +60,7 @@ public:
void Signal(s64 cycles_late);
private:
Timer();
explicit Timer(KernelSystem& kernel);
~Timer() override;
ResetType reset_type; ///< The ResetType of this timer
@ -81,6 +73,8 @@ private:
/// Handle used as userdata to reference this object when inserting into the CoreTiming queue.
Handle callback_handle;
friend class KernelSystem;
};
/// Initializes the required variables for timers