Subject: CVS commit: src/lib/libpthread
To: None <source-changes@netbsd.org>
From: Nathan J Williams <nathanw@netbsd.org>
List: source-changes
Date: 01/31/2003 04:55:02
Module Name:	src
Committed By:	nathanw
Date:		Fri Jan 31 02:55:01 UTC 2003

Modified Files:
	src/lib/libpthread: pthread_mutex.c

Log Message:
Mutex tuneup.

 * Use a double-checked locking technique to avoid taking
   the interlock in pthread_mutex_unlock().

 * In pthread_mutex_lock() and pthread_mutex_trylock(), only store the
   stack pointer, not the thread ID, in ptm_owner. Do the translation
   to a thread ID in the slow-lock, errorcheck, and recursive mutex
   cases rather than in the common path.

 * Juggle where pthread__self() is called, to move it out of the fast path.

Overall, this means that neither pthread_self() nor
pthread_spin[un]lock() are used in the course of locking and unlocking
an uncontested mutex. Speeds up the fast path by 40-50%, and
eliminates about 98% of spinlocks used by a couple of large threaded
applications.

(Still a GET_MUTEX_PRIVATE() in the fast path... perhaps the type
should be in the main body of the mutex).


To generate a diff of this commit:
cvs rdiff -r1.7 -r1.8 src/lib/libpthread/pthread_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.