mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-02 23:49:40 +00:00
PSP: switched to psp semaphores rather than SDL's. Removal of SDL is almost complete.
svn-id: r49572
This commit is contained in:
parent
711f679b7f
commit
c8ee854600
@ -346,19 +346,19 @@ void OSystem_PSP::setTimerCallback(TimerProc callback, int interval) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OSystem::MutexRef OSystem_PSP::createMutex(void) {
|
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) {
|
void OSystem_PSP::lockMutex(MutexRef mutex) {
|
||||||
SDL_mutexP((SDL_mutex *)mutex);
|
((PspMutex *)mutex)->lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSystem_PSP::unlockMutex(MutexRef mutex) {
|
void OSystem_PSP::unlockMutex(MutexRef mutex) {
|
||||||
SDL_mutexV((SDL_mutex *)mutex);
|
((PspMutex *)mutex)->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSystem_PSP::deleteMutex(MutexRef mutex) {
|
void OSystem_PSP::deleteMutex(MutexRef mutex) {
|
||||||
SDL_DestroyMutex((SDL_mutex *)mutex);
|
delete (PspMutex *)mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSystem_PSP::mixCallback(void *sys, byte *samples, int len) {
|
void OSystem_PSP::mixCallback(void *sys, byte *samples, int len) {
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#include "backends/platform/psp/thread.h"
|
#include "backends/platform/psp/thread.h"
|
||||||
#include "backends/platform/psp/trace.h"
|
#include "backends/platform/psp/trace.h"
|
||||||
|
|
||||||
|
// Class PspThread --------------------------------------------------
|
||||||
|
|
||||||
void PspThread::delayMillis(uint32 ms) {
|
void PspThread::delayMillis(uint32 ms) {
|
||||||
sceKernelDelayThread(ms * 1000);
|
sceKernelDelayThread(ms * 1000);
|
||||||
}
|
}
|
||||||
@ -39,6 +41,88 @@ void PspThread::delayMicros(uint32 us) {
|
|||||||
sceKernelDelayThread(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
|
void PspRtc::init() { // init our starting ticks
|
||||||
uint32 ticks[2];
|
uint32 ticks[2];
|
||||||
sceRtcGetCurrentTick((u64 *)ticks);
|
sceRtcGetCurrentTick((u64 *)ticks);
|
||||||
|
@ -34,6 +34,33 @@ public:
|
|||||||
static void delayMicros(uint32 us);
|
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 {
|
class PspRtc {
|
||||||
private:
|
private:
|
||||||
uint32 _startMillis;
|
uint32 _startMillis;
|
||||||
|
Loading…
Reference in New Issue
Block a user