[Scummvm-cvs-logs] SF.net SVN: scummvm:[49572] scummvm/trunk/backends/platform/psp

Bluddy at users.sourceforge.net Bluddy at users.sourceforge.net
Thu Jun 10 15:41:30 CEST 2010


Revision: 49572
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49572&view=rev
Author:   Bluddy
Date:     2010-06-10 13:41:29 +0000 (Thu, 10 Jun 2010)

Log Message:
-----------
PSP: switched to psp semaphores rather than SDL's. Removal of SDL is almost complete.

Modified Paths:
--------------
    scummvm/trunk/backends/platform/psp/osys_psp.cpp
    scummvm/trunk/backends/platform/psp/thread.cpp
    scummvm/trunk/backends/platform/psp/thread.h

Modified: scummvm/trunk/backends/platform/psp/osys_psp.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/osys_psp.cpp	2010-06-10 12:40:58 UTC (rev 49571)
+++ scummvm/trunk/backends/platform/psp/osys_psp.cpp	2010-06-10 13:41:29 UTC (rev 49572)
@@ -346,19 +346,19 @@
 }
 
 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) {

Modified: scummvm/trunk/backends/platform/psp/thread.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/thread.cpp	2010-06-10 12:40:58 UTC (rev 49571)
+++ scummvm/trunk/backends/platform/psp/thread.cpp	2010-06-10 13:41:29 UTC (rev 49572)
@@ -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 @@
 	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);

Modified: scummvm/trunk/backends/platform/psp/thread.h
===================================================================
--- scummvm/trunk/backends/platform/psp/thread.h	2010-06-10 12:40:58 UTC (rev 49571)
+++ scummvm/trunk/backends/platform/psp/thread.h	2010-06-10 13:41:29 UTC (rev 49572)
@@ -34,6 +34,33 @@
 	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;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list