[Base] Use chrono APIs for Timers
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "xenia/kernel/xtimer.h"
|
||||
|
||||
#include "xenia/base/clock.h"
|
||||
#include "xenia/base/chrono.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/cpu/processor.h"
|
||||
#include "xenia/kernel/xthread.h"
|
||||
@@ -40,13 +40,24 @@ void XTimer::Initialize(uint32_t timer_type) {
|
||||
|
||||
X_STATUS XTimer::SetTimer(int64_t due_time, uint32_t period_ms,
|
||||
uint32_t routine, uint32_t routine_arg, bool resume) {
|
||||
using xe::chrono::WinSystemClock;
|
||||
using xe::chrono::XSystemClock;
|
||||
// Caller is checking for STATUS_TIMER_RESUME_IGNORED.
|
||||
if (resume) {
|
||||
return X_STATUS_TIMER_RESUME_IGNORED;
|
||||
}
|
||||
|
||||
due_time = Clock::ScaleGuestDurationFileTime(due_time);
|
||||
period_ms = Clock::ScaleGuestDurationMillis(period_ms);
|
||||
WinSystemClock::time_point due_tp;
|
||||
if (due_time < 0) {
|
||||
// Any timer implementation uses absolute times eventually, convert as early
|
||||
// as possible for increased accuracy
|
||||
auto after = xe::chrono::hundrednanoseconds(-due_time);
|
||||
due_tp = date::clock_cast<WinSystemClock>(XSystemClock::now() + after);
|
||||
} else {
|
||||
due_tp = date::clock_cast<WinSystemClock>(
|
||||
XSystemClock::from_file_time(due_time));
|
||||
}
|
||||
|
||||
// Stash routine for callback.
|
||||
callback_thread_ = XThread::GetCurrentThread();
|
||||
@@ -72,12 +83,10 @@ X_STATUS XTimer::SetTimer(int64_t due_time, uint32_t period_ms,
|
||||
|
||||
bool result;
|
||||
if (!period_ms) {
|
||||
result = timer_->SetOnce(std::chrono::nanoseconds(due_time * 100),
|
||||
std::move(callback));
|
||||
result = timer_->SetOnceAt(due_tp, std::move(callback));
|
||||
} else {
|
||||
result = timer_->SetRepeating(std::chrono::nanoseconds(due_time * 100),
|
||||
std::chrono::milliseconds(period_ms),
|
||||
std::move(callback));
|
||||
result = timer_->SetRepeatingAt(
|
||||
due_tp, std::chrono::milliseconds(period_ms), std::move(callback));
|
||||
}
|
||||
|
||||
return result ? X_STATUS_SUCCESS : X_STATUS_UNSUCCESSFUL;
|
||||
|
||||
Reference in New Issue
Block a user