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

Bluddy at users.sourceforge.net Bluddy at users.sourceforge.net
Tue Jun 15 08:30:50 CEST 2010


Revision: 49682
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49682&view=rev
Author:   Bluddy
Date:     2010-06-15 06:30:49 +0000 (Tue, 15 Jun 2010)

Log Message:
-----------
PSP: fixed SCI freeze issue by using recursive mutexes

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

Modified: scummvm/trunk/backends/platform/psp/thread.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/thread.cpp	2010-06-15 05:53:15 UTC (rev 49681)
+++ scummvm/trunk/backends/platform/psp/thread.cpp	2010-06-15 06:30:49 UTC (rev 49682)
@@ -95,14 +95,14 @@
 }
 
 // false: timeout or error
-bool PspSemaphore::takeWithTimeOut(int num, uint32 timeOut) {
+bool PspSemaphore::takeWithTimeOut(uint32 timeOut) {
 	DEBUG_ENTER_FUNC();
 	
 	uint32 *pTimeOut = 0;
 	if (timeOut) 
 		pTimeOut = &timeOut;
 	
-	if (sceKernelWaitSema(_handle, num, pTimeOut) < 0)
+	if (sceKernelWaitSema(_handle, 1, pTimeOut) < 0)	// we always wait for 1
 		return false;
 	return true;
 }
@@ -115,6 +115,43 @@
 	return true;
 }
 
+// Class PspMutex ------------------------------------------------------------
+
+bool PspMutex::lock() {
+	DEBUG_ENTER_FUNC();
+	int threadId = sceKernelGetThreadId();
+	bool ret = true;
+	
+	if (_ownerId == threadId) {
+		_recursiveCount++;
+	} else {
+		ret = _semaphore.take();
+		_ownerId = threadId;
+		_recursiveCount = 0;
+	}
+	return ret;
+}
+
+bool PspMutex::unlock() {
+	DEBUG_ENTER_FUNC();
+	int threadId = sceKernelGetThreadId();
+	bool ret = true;
+	
+	if (_ownerId != threadId) {
+		PSP_ERROR("attempt to unlock mutex by thread[%x] as opposed to owner[%x]\n",
+			threadId, _ownerId);
+		return false;
+	}
+	
+	if (_recursiveCount) {
+		_recursiveCount--;
+	} else {
+		_ownerId = 0;
+		ret = _semaphore.give(1);
+	}	
+	return ret;
+}
+
 //#define __PSP_DEBUG_FUNCS__	/* For debugging function calls */
 //#define __PSP_DEBUG_PRINT__	/* For debug printouts */
 

Modified: scummvm/trunk/backends/platform/psp/thread.h
===================================================================
--- scummvm/trunk/backends/platform/psp/thread.h	2010-06-15 05:53:15 UTC (rev 49681)
+++ scummvm/trunk/backends/platform/psp/thread.h	2010-06-15 06:30:49 UTC (rev 49682)
@@ -40,8 +40,8 @@
 public:
 	PspSemaphore(int initialValue, int maxValue);
 	~PspSemaphore();
-	bool take(int num) { return takeWithTimeOut(num, 0); }
-	bool takeWithTimeOut(int num, uint32 timeOut);
+	bool take() { return takeWithTimeOut(0); }
+	bool takeWithTimeOut(uint32 timeOut);
 	bool give(int num);
 	bool pollForValue(int value);	// check for a certain value
 	int numOfWaitingThreads();
@@ -51,12 +51,14 @@
 class PspMutex {
 private:
 	PspSemaphore _semaphore;
+	int _recursiveCount;
+	int _ownerId;
 public:
-	PspMutex(bool initialValue) : _semaphore(initialValue ? 1 : 0, 255) {}	// initial, max value
-	bool lock() { return _semaphore.take(1); }
-	bool unlock() { return _semaphore.give(1); }
+	PspMutex(bool initialValue) : _semaphore(initialValue ? 1 : 0, 255), _recursiveCount(0), _ownerId(0) {}	// initial, max value
+	bool lock();
+	bool unlock();
 	bool poll() { return _semaphore.pollForValue(1); }
-	int getNumWaitingThreads() { return _semaphore.numOfWaitingThreads(); }
+	int numOfWaitingThreads() { return _semaphore.numOfWaitingThreads(); }
 	bool getValue() { return (bool)_semaphore.getValue(); }
 };
 


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