diff options
Diffstat (limited to 'backends/timer')
-rw-r--r-- | backends/timer/psp/timer.cpp | 21 | ||||
-rw-r--r-- | backends/timer/psp/timer.h | 15 |
2 files changed, 14 insertions, 22 deletions
diff --git a/backends/timer/psp/timer.cpp b/backends/timer/psp/timer.cpp index 278f50581c..b1479baecf 100644 --- a/backends/timer/psp/timer.cpp +++ b/backends/timer/psp/timer.cpp @@ -49,47 +49,42 @@ #include "backends/platform/psp/trace.h" -bool PspTimer::start() { +PspTimerManager::PspTimerManager(uint32 interval) : _interval(interval * 1000), _threadId(-1), _init(false) { DEBUG_ENTER_FUNC(); - if (!_interval || !_callback) - return false; - _threadId = sceKernelCreateThread("timerThread", thread, PRIORITY_TIMER_THREAD, STACK_TIMER_THREAD, THREAD_ATTR_USER, 0); if (_threadId < 0) { // error PSP_ERROR("failed to create timer thread. Error code %d\n", _threadId); - return false; + return; } - PspTimer *_this = this; // trick to get into context when the thread starts + PspTimerManager *_this = this; // trick to get into context when the thread starts _init = true; if (sceKernelStartThread(_threadId, sizeof(uint32 *), &_this) < 0) { PSP_ERROR("failed to start thread %d\n", _threadId); - return false; + return; } PSP_DEBUG_PRINT("created timer thread[%x]\n", _threadId); - - return true; } -int PspTimer::thread(SceSize, void *__this) { +int PspTimerManager::thread(SceSize, void *__this) { DEBUG_ENTER_FUNC(); - PspTimer *_this = *(PspTimer **)__this; // get our this for the context + PspTimerManager *_this = *(PspTimerManager **)__this; // get our this for the context _this->timerThread(); return 0; }; -void PspTimer::timerThread() { +void PspTimerManager::timerThread() { DEBUG_ENTER_FUNC(); while (_init) { sceKernelDelayThread(_interval); PSP_DEBUG_PRINT("calling callback!\n"); - _callback(); + handler(); } }; diff --git a/backends/timer/psp/timer.h b/backends/timer/psp/timer.h index 45b32e0e14..a7871009c4 100644 --- a/backends/timer/psp/timer.h +++ b/backends/timer/psp/timer.h @@ -23,19 +23,16 @@ #ifndef PSP_TIMER_H #define PSP_TIMER_H -class PspTimer { +#include "backends/timer/default/default-timer.h" + +class PspTimerManager : public DefaultTimerManager { public: - typedef void (* CallbackFunc)(void); - PspTimer() : _callback(0), _interval(0), _threadId(-1), _init(false) {} - void stop() { _init = false; } - bool start(); - ~PspTimer() { stop(); } - void setCallback(CallbackFunc cb) { _callback = cb; } - void setIntervalMs(uint32 interval) { _interval = interval * 1000; } + PspTimerManager(uint32 interval = 10); + ~PspTimerManager() { _init = false; } + static int thread(SceSize, void *__this); // static thread to use as bridge void timerThread(); private: - CallbackFunc _callback; // pointer to timer callback uint32 _interval; int _threadId; bool _init; |