diff Python/thread_pthread.h @ 28674:9eb6964b4b6c 2.2

Patch #711835: Remove unnecessary lock operations.
author Martin v. Löwis <martin@v.loewis.de>
date Fri, 18 Apr 2003 11:21:22 +0000
parents 61822d2b5e88
children d0ae620afbd4
line wrap: on
line diff
--- a/Python/thread_pthread.h	Thu Apr 17 22:37:50 2003 +0000
+++ b/Python/thread_pthread.h	Fri Apr 18 11:21:22 2003 +0000
@@ -359,27 +359,23 @@
 	status = pthread_mutex_lock( &thelock->mut );
 	CHECK_STATUS("pthread_mutex_lock[1]");
 	success = thelock->locked == 0;
-	if (success) thelock->locked = 1;
-	status = pthread_mutex_unlock( &thelock->mut );
-	CHECK_STATUS("pthread_mutex_unlock[1]");
 
 	if ( !success && waitflag ) {
 		/* continue trying until we get the lock */
 
 		/* mut must be locked by me -- part of the condition
 		 * protocol */
-		status = pthread_mutex_lock( &thelock->mut );
-		CHECK_STATUS("pthread_mutex_lock[2]");
 		while ( thelock->locked ) {
 			status = pthread_cond_wait(&thelock->lock_released,
 						   &thelock->mut);
 			CHECK_STATUS("pthread_cond_wait");
 		}
-		thelock->locked = 1;
-		status = pthread_mutex_unlock( &thelock->mut );
-		CHECK_STATUS("pthread_mutex_unlock[2]");
 		success = 1;
 	}
+	if (success) thelock->locked = 1;
+	status = pthread_mutex_unlock( &thelock->mut );
+	CHECK_STATUS("pthread_mutex_unlock[1]");
+
 	if (error) success = 0;
 	dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
 	return success;