diff options
author | Yotam Barnoy | 2010-06-10 13:41:29 +0000 |
---|---|---|
committer | Yotam Barnoy | 2010-06-10 13:41:29 +0000 |
commit | c8ee854600710f36f09d8375fbe51e1924d97320 (patch) | |
tree | 15cc8efe5e1f093765a09837464097c27396a3e6 /backends/platform | |
parent | 711f679b7ffa9b51c2d6a07dab0a1dd7799f155d (diff) | |
download | scummvm-rg350-c8ee854600710f36f09d8375fbe51e1924d97320.tar.gz scummvm-rg350-c8ee854600710f36f09d8375fbe51e1924d97320.tar.bz2 scummvm-rg350-c8ee854600710f36f09d8375fbe51e1924d97320.zip |
PSP: switched to psp semaphores rather than SDL's. Removal of SDL is almost complete.
svn-id: r49572
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/psp/osys_psp.cpp | 8 | ||||
-rw-r--r-- | backends/platform/psp/thread.cpp | 84 | ||||
-rw-r--r-- | backends/platform/psp/thread.h | 27 |
3 files changed, 115 insertions, 4 deletions
diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index 48e9044535..b0fb971230 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -346,19 +346,19 @@ void OSystem_PSP::setTimerCallback(TimerProc callback, int interval) { } OSystem::MutexRef OSystem_PSP::createMutex(void) { - return (MutexRef)SDL_CreateMutex(); + return (MutexRef) new PspMutex(true); // start with a full mutex } void OSystem_PSP::lockMutex(MutexRef mutex) { - SDL_mutexP((SDL_mutex *)mutex); + ((PspMutex *)mutex)->lock(); } void OSystem_PSP::unlockMutex(MutexRef mutex) { - SDL_mutexV((SDL_mutex *)mutex); + ((PspMutex *)mutex)->unlock(); } void OSystem_PSP::deleteMutex(MutexRef mutex) { - SDL_DestroyMutex((SDL_mutex *)mutex); + delete (PspMutex *)mutex; } void OSystem_PSP::mixCallback(void *sys, byte *samples, int len) { diff --git a/backends/platform/psp/thread.cpp b/backends/platform/psp/thread.cpp index 4e7d5eada9..684a985fed 100644 --- a/backends/platform/psp/thread.cpp +++ b/backends/platform/psp/thread.cpp @@ -31,6 +31,8 @@ #include "backends/platform/psp/thread.h" #include "backends/platform/psp/trace.h" +// Class PspThread -------------------------------------------------- + void PspThread::delayMillis(uint32 ms) { sceKernelDelayThread(ms * 1000); } @@ -39,6 +41,88 @@ void PspThread::delayMicros(uint32 us) { sceKernelDelayThread(us); } +// Class PspSemaphore ------------------------------------------------ +//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */ +//#define __PSP_DEBUG_PRINT__ /* For debug printouts */ + +#include "backends/platform/psp/trace.h" + +PspSemaphore::PspSemaphore(int initialValue, int maxValue) { + DEBUG_ENTER_FUNC(); + _handle = 0; + _handle = sceKernelCreateSema("ScummVM Sema", 0 /* attr */, + initialValue, maxValue, + 0 /*option*/); + if (!_handle) + PSP_ERROR("failed to create semaphore.\n"); +} + +PspSemaphore::~PspSemaphore() { + DEBUG_ENTER_FUNC(); + if (_handle) + if (sceKernelDeleteSema(_handle) < 0) + PSP_ERROR("failed to delete semaphore.\n"); +} + +int PspSemaphore::numOfWaitingThreads() { + DEBUG_ENTER_FUNC(); + SceKernelSemaInfo info; + info.numWaitThreads = 0; + + if (sceKernelReferSemaStatus(_handle, &info) < 0) + PSP_ERROR("failed to retrieve semaphore info for handle %d\n", _handle); + + return info.numWaitThreads; +} + +int PspSemaphore::getValue() { + DEBUG_ENTER_FUNC(); + SceKernelSemaInfo info; + info.currentCount = 0; + + if (sceKernelReferSemaStatus(_handle, &info) < 0) + PSP_ERROR("failed to retrieve semaphore info for handle %d\n", _handle); + + return info.currentCount; +} + +bool PspSemaphore::pollForValue(int value) { + DEBUG_ENTER_FUNC(); + if (sceKernelPollSema(_handle, value) < 0) + return false; + + return true; +} + +// false: timeout or error +bool PspSemaphore::takeWithTimeOut(int num, uint32 timeOut) { + DEBUG_ENTER_FUNC(); + + uint32 *pTimeOut = 0; + if (timeOut) + pTimeOut = &timeOut; + + if (sceKernelWaitSema(_handle, num, pTimeOut) < 0) + return false; + return true; +} + +bool PspSemaphore::give(int num) { + DEBUG_ENTER_FUNC(); + + if (sceKernelSignalSema(_handle, num) < 0) + return false; + return true; +} + +//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */ +//#define __PSP_DEBUG_PRINT__ /* For debug printouts */ + +#include "backends/platform/psp/trace.h" + + +// Class PspRtc --------------------------------------------------------------- + void PspRtc::init() { // init our starting ticks uint32 ticks[2]; sceRtcGetCurrentTick((u64 *)ticks); diff --git a/backends/platform/psp/thread.h b/backends/platform/psp/thread.h index 380159fa2d..23db8594dc 100644 --- a/backends/platform/psp/thread.h +++ b/backends/platform/psp/thread.h @@ -34,6 +34,33 @@ public: static void delayMicros(uint32 us); }; +class PspSemaphore { +private: + SceUID _handle; +public: + PspSemaphore(int initialValue, int maxValue); + ~PspSemaphore(); + bool take(int num) { return takeWithTimeOut(num, 0); } + bool takeWithTimeOut(int num, uint32 timeOut); + bool give(int num); + bool pollForValue(int value); // check for a certain value + int numOfWaitingThreads(); + int getValue(); +}; + +class PspMutex { +private: + PspSemaphore _semaphore; +public: + PspMutex(bool initialValue) : _semaphore(initialValue ? 1 : 0, 255) {} // initial, max value + bool lock() { return _semaphore.take(1); } + bool unlock() { return _semaphore.give(1); } + bool poll() { return _semaphore.pollForValue(1); } + int getNumWaitingThreads() { return _semaphore.numOfWaitingThreads(); } + bool getValue() { return (bool)_semaphore.getValue(); } +}; + + class PspRtc { private: uint32 _startMillis; |