[Haiku-commits] r28354 - haiku/trunk/src/system/libroot/posix/pthread

bonefish at BerliOS bonefish at mail.berlios.de
Tue Oct 28 13:04:52 CET 2008


Author: bonefish
Date: 2008-10-28 13:04:51 +0100 (Tue, 28 Oct 2008)
New Revision: 28354
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=28354&view=rev

Modified:
   haiku/trunk/src/system/libroot/posix/pthread/pthread_mutex.c
Log:
Fixed some incorrect behavior pointed out in #2990:
* The pthread_mutex_*lock() family should return EDEADLK when re-locking
  an error-checked mutex.
* pthread_mutex_trylock() is supposed to return EBUSY, not
  B_WOULD_BLOCK.
* pthread_mutex_unlock() should return EPERM when the caller is not the
  owner. It used to print a message and try to unlock anyway.


Modified: haiku/trunk/src/system/libroot/posix/pthread/pthread_mutex.c
===================================================================
--- haiku/trunk/src/system/libroot/posix/pthread/pthread_mutex.c	2008-10-28 02:44:39 UTC (rev 28353)
+++ haiku/trunk/src/system/libroot/posix/pthread/pthread_mutex.c	2008-10-28 12:04:51 UTC (rev 28354)
@@ -85,7 +85,7 @@
 	if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_ERRORCHECK
 		&& mutex->owner == thisThread) {
 		// we detect this kind of deadlock and return an error
-		return B_BUSY;
+		return EDEADLK;
 	}
 
 	if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_RECURSIVE
@@ -123,11 +123,12 @@
 int
 pthread_mutex_trylock(pthread_mutex_t *mutex)
 {
-	return mutex_lock(mutex, 0);
+	status_t status = mutex_lock(mutex, 0);
+	return status == B_WOULD_BLOCK ? EBUSY : status;
 }
 
 
-int 
+int
 pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *tv)
 {
 	bool invalidTime = false;
@@ -156,11 +157,8 @@
 	if (mutex == NULL)
 		return B_BAD_VALUE;
 
-	if (mutex->owner != find_thread(NULL)) {
-		// this is a bug in the calling application!
-		// ToDo: should we handle it in another way?
-		fprintf(stderr, "mutex unlocked from foreign thread!\n");
-	}
+	if (mutex->owner != find_thread(NULL))
+		return EPERM;
 
 	if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_RECURSIVE) {
 		if (mutex->owner_count-- > 1)
@@ -176,7 +174,7 @@
 }
 
 
-int 
+int
 pthread_mutex_getprioceiling(pthread_mutex_t *mutex, int *_prioCeiling)
 {
 	if (mutex == NULL || _prioCeiling == NULL)
@@ -189,7 +187,7 @@
 }
 
 
-int 
+int
 pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioCeiling,
 	int *_oldCeiling)
 {




More information about the Haiku-commits mailing list