xenia-canary/src/xenia/kernel/objects/xtimer.cc

85 lines
2.2 KiB
C++
Raw Normal View History

2014-01-08 05:55:32 +00:00
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/kernel/objects/xtimer.h>
2014-01-08 06:47:35 +00:00
#include <xenia/cpu/processor.h>
2014-01-08 05:55:32 +00:00
using namespace xe;
using namespace xe::kernel;
XTimer::XTimer(KernelState* kernel_state) :
XObject(kernel_state, kTypeTimer),
handle_(NULL) {
}
XTimer::~XTimer() {
if (handle_) {
CloseHandle(handle_);
}
}
void XTimer::Initialize(uint32_t timer_type) {
XEASSERTNULL(handle_);
bool manual_reset = false;
switch (timer_type) {
case 0: // NotificationTimer
manual_reset = true;
break;
case 1: // SynchronizationTimer
manual_reset = false;
break;
default:
XEASSERTALWAYS();
break;
}
handle_ = CreateWaitableTimer(NULL, manual_reset, NULL);
}
2014-01-08 06:47:35 +00:00
X_STATUS XTimer::SetTimer(
int64_t due_time, uint32_t period_ms,
uint32_t routine, uint32_t routine_arg, bool resume) {
// Stash routine for callback.
current_routine_ = routine;
current_routine_arg_ = routine_arg;
2014-01-08 05:55:32 +00:00
LARGE_INTEGER due_time_li;
due_time_li.QuadPart = due_time;
2014-01-08 06:47:35 +00:00
BOOL result = SetWaitableTimer(
handle_, &due_time_li, period_ms,
routine ? (PTIMERAPCROUTINE)CompletionRoutine : NULL, this,
resume ? TRUE : FALSE);
// Caller is checking for STATUS_TIMER_RESUME_IGNORED.
// This occurs if result == TRUE but error is set.
if (!result && GetLastError() == ERROR_NOT_SUPPORTED) {
return X_STATUS_TIMER_RESUME_IGNORED;
2014-01-08 05:55:32 +00:00
}
2014-01-08 06:47:35 +00:00
return result ? X_STATUS_SUCCESS : X_STATUS_UNSUCCESSFUL;
}
void XTimer::CompletionRoutine(
XTimer* timer, DWORD timer_low, DWORD timer_high) {
XEASSERT(timer->current_routine_);
// Queue APC to call back routine with (arg, low, high).
// TODO(benvanik): APC dispatch.
XELOGE("Timer needs APC!");
2014-01-08 05:55:32 +00:00
}
X_STATUS XTimer::Cancel() {
return CancelWaitableTimer(handle_) == 0 ?
X_STATUS_SUCCESS : X_STATUS_UNSUCCESSFUL;
}