Timers. Probably.

This commit is contained in:
Ben Vanik
2014-01-07 21:55:32 -08:00
parent 1357a798ef
commit cfe7b2127d
6 changed files with 212 additions and 6 deletions

View File

@@ -15,5 +15,7 @@
'xsemaphore.h',
'xthread.cc',
'xthread.h',
'xtimer.cc',
'xtimer.h',
],
}

View File

@@ -0,0 +1,60 @@
/**
******************************************************************************
* 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>
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);
}
X_STATUS XTimer::SetTimer(int64_t due_time, uint32_t period_ms) {
LARGE_INTEGER due_time_li;
due_time_li.QuadPart = due_time;
if (SetWaitableTimer(handle_, &due_time_li, period_ms, NULL, NULL, TRUE)) {
return X_STATUS_SUCCESS;
} else {
return X_STATUS_UNSUCCESSFUL;
}
}
X_STATUS XTimer::Cancel() {
return CancelWaitableTimer(handle_) == 0 ?
X_STATUS_SUCCESS : X_STATUS_UNSUCCESSFUL;
}

View File

@@ -0,0 +1,44 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#ifndef XENIA_KERNEL_XBOXKRNL_XTIMER_H_
#define XENIA_KERNEL_XBOXKRNL_XTIMER_H_
#include <xenia/kernel/xobject.h>
#include <xenia/xbox.h>
namespace xe {
namespace kernel {
class XTimer : public XObject {
public:
XTimer(KernelState* kernel_state);
virtual ~XTimer();
void Initialize(uint32_t timer_type);
// completion routine, arg to completion routine
X_STATUS SetTimer(int64_t due_time, uint32_t period_ms);
X_STATUS Cancel();
virtual void* GetWaitHandle() { return handle_; }
private:
HANDLE handle_;
};
} // namespace kernel
} // namespace xe
#endif // XENIA_KERNEL_XBOXKRNL_TIMER_H_