Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 58658 invoked by uid 500); 11 Jan 2002 04:28:03 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 58647 invoked from network); 11 Jan 2002 04:28:03 -0000 Message-ID: <3C3E69DC.9000307@cnet.com> Date: Thu, 10 Jan 2002 20:28:12 -0800 From: Brian Pane User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.5) Gecko/20011011 X-Accept-Language: en-us MIME-Version: 1.0 To: dev@apr.apache.org Subject: [PATCH] speedup for thread mutexes Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N This is a repost of a patch from December that reduces the number of branches in the apr_thread_mutex_lock/unlock functions. It reduces the cost of these calls by about 10%. --Brian Index: srclib/apr/locks/unix/thread_mutex.c =================================================================== RCS file: /home/cvspublic/apr/locks/unix/thread_mutex.c,v retrieving revision 1.5 diff -u -r1.5 thread_mutex.c --- srclib/apr/locks/unix/thread_mutex.c 22 Oct 2001 08:30:08 -0000 1.5 +++ srclib/apr/locks/unix/thread_mutex.c 1 Jan 2002 02:40:46 -0000 @@ -128,26 +128,35 @@ apr_status_t rv; #if APR_HAS_THREADS - if (mutex->nested && apr_os_thread_equal(mutex->owner, - apr_os_thread_current())) { - mutex->owner_ref++; - return APR_SUCCESS; - } -#endif + if (mutex->nested) { + if (apr_os_thread_equal(mutex->owner, apr_os_thread_current())) { + mutex->owner_ref++; + return APR_SUCCESS; + } - rv = pthread_mutex_lock(&mutex->mutex); - if (rv) { + rv = pthread_mutex_lock(&mutex->mutex); + if (rv) { #ifdef PTHREAD_SETS_ERRNO - rv = errno; + rv = errno; #endif - return rv; - } + return rv; + } -#if APR_HAS_THREADS - if (mutex->nested) { mutex->owner = apr_os_thread_current(); mutex->owner_ref = 1; } + else { +#endif + rv = pthread_mutex_lock(&mutex->mutex); + if (rv) { +#ifdef PTHREAD_SETS_ERRNO + rv = errno; +#endif + return rv; + } + +#if APR_HAS_THREADS + } #endif return rv; @@ -194,24 +203,29 @@ if (mutex->owner_ref > 0) return APR_SUCCESS; } - } -#endif - - status = pthread_mutex_unlock(&mutex->mutex); - if (status) { + status = pthread_mutex_unlock(&mutex->mutex); + if (status) { #ifdef PTHREAD_SETS_ERRNO - status = errno; + status = errno; #endif - return status; - } + return status; + } -#if APR_HAS_THREADS - if (mutex->nested) { memset(&mutex->owner, 0, sizeof mutex->owner); mutex->owner_ref = 0; } + else { +#endif + status = pthread_mutex_unlock(&mutex->mutex); + if (status) { +#ifdef PTHREAD_SETS_ERRNO + status = errno; +#endif + return status; + } +#if APR_HAS_THREADS + } #endif - return status; }