aboutsummaryrefslogtreecommitdiff
path: root/backends/timer
diff options
context:
space:
mode:
authorCameron Cawley2019-11-27 22:29:38 +0000
committerFilippos Karapetis2019-12-10 08:35:13 +0200
commit099ef8db300fc776539694c766dcb58a4a948952 (patch)
treee48def42571181f7488bb539da3dfd5e312e2b12 /backends/timer
parent9dcfe2c09ece2248986af4547e878a07d8ba950f (diff)
downloadscummvm-rg350-099ef8db300fc776539694c766dcb58a4a948952.tar.gz
scummvm-rg350-099ef8db300fc776539694c766dcb58a4a948952.tar.bz2
scummvm-rg350-099ef8db300fc776539694c766dcb58a4a948952.zip
PSP: Make the PspTimer class a subclass of DefaultTimerManager
Diffstat (limited to 'backends/timer')
-rw-r--r--backends/timer/psp/timer.cpp21
-rw-r--r--backends/timer/psp/timer.h15
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;