Return-Path: X-Original-To: apmail-apr-commits-archive@www.apache.org Delivered-To: apmail-apr-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B8AE319154 for ; Tue, 12 Apr 2016 15:55:20 +0000 (UTC) Received: (qmail 44432 invoked by uid 500); 12 Apr 2016 15:55:20 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 44367 invoked by uid 500); 12 Apr 2016 15:55:20 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 44358 invoked by uid 99); 12 Apr 2016 15:55:20 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Apr 2016 15:55:20 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 0C52E1A06FF for ; Tue, 12 Apr 2016 15:55:20 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.799 X-Spam-Level: * X-Spam-Status: No, score=1.799 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id PpFjEk19sNdM for ; Tue, 12 Apr 2016 15:55:18 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id B07855F232 for ; Tue, 12 Apr 2016 15:55:17 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 94BF9E019D for ; Tue, 12 Apr 2016 15:55:16 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 8E90A3A0186 for ; Tue, 12 Apr 2016 15:55:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1738819 - in /apr/apr/branches/1.5.x: include/arch/unix/apr_arch_proc_mutex.h locks/unix/proc_mutex.c Date: Tue, 12 Apr 2016 15:55:16 -0000 To: commits@apr.apache.org From: ylavic@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160412155516.8E90A3A0186@svn01-us-west.apache.org> Author: ylavic Date: Tue Apr 12 15:55:16 2016 New Revision: 1738819 URL: http://svn.apache.org/viewvc?rev=1738819&view=rev Log: apr_proc_mutex-unix: backport r1733775 from trunk (partially). Includes some fixes to unix proc_mutexes contained in the above commit (including follow up to r1738800), but without non-backportable (API) changes. Modified: apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h apr/apr/branches/1.5.x/locks/unix/proc_mutex.c Modified: apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h?rev=1738819&r1=1738818&r2=1738819&view=diff ============================================================================== --- apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h (original) +++ apr/apr/branches/1.5.x/include/arch/unix/apr_arch_proc_mutex.h Tue Apr 12 15:55:16 2016 @@ -104,6 +104,10 @@ struct apr_proc_mutex_t { #endif #if APR_HAS_PROC_PTHREAD_SERIALIZE pthread_mutex_t *pthread_interproc; + int pthread_refcounting; /* Whether the native mutex is refcounted or + * apr_os_proc_mutex_put()ed, which makes + * refcounting impossible/undesirable. + */ #endif }; Modified: apr/apr/branches/1.5.x/locks/unix/proc_mutex.c URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/locks/unix/proc_mutex.c?rev=1738819&r1=1738818&r2=1738819&view=diff ============================================================================== --- apr/apr/branches/1.5.x/locks/unix/proc_mutex.c (original) +++ apr/apr/branches/1.5.x/locks/unix/proc_mutex.c Tue Apr 12 15:55:16 2016 @@ -343,6 +343,23 @@ typedef struct { #define proc_pthread_mutex_refcount(m) \ (((proc_pthread_mutex_t *)(m)->pthread_interproc)->refcount) +static APR_INLINE int proc_pthread_mutex_inc(apr_proc_mutex_t *mutex) +{ + if (mutex->pthread_refcounting) { + apr_atomic_inc32(&proc_pthread_mutex_refcount(mutex)); + return 1; + } + return 0; +} + +static APR_INLINE int proc_pthread_mutex_dec(apr_proc_mutex_t *mutex) +{ + if (mutex->pthread_refcounting) { + return apr_atomic_dec32(&proc_pthread_mutex_refcount(mutex)); + } + return 0; +} + static apr_status_t proc_pthread_mutex_unref(void *mutex_) { apr_proc_mutex_t *mutex=mutex_; @@ -356,7 +373,7 @@ static apr_status_t proc_pthread_mutex_u return rv; } } - if (!apr_atomic_dec32(&proc_pthread_mutex_refcount(mutex))) { + if (!proc_pthread_mutex_dec(mutex)) { if ((rv = pthread_mutex_destroy(mutex->pthread_interproc))) { #ifdef HAVE_ZOS_PTHREADS rv = errno; @@ -378,8 +395,7 @@ static apr_status_t proc_mutex_proc_pthr return rv; } } - if (munmap((caddr_t)mutex->pthread_interproc, - sizeof(proc_pthread_mutex_t))) { + if (munmap(mutex->pthread_interproc, sizeof(proc_pthread_mutex_t))) { return errno; } return APR_SUCCESS; @@ -397,17 +413,17 @@ static apr_status_t proc_mutex_proc_pthr return errno; } - new_mutex->pthread_interproc = (pthread_mutex_t *)mmap( - (caddr_t) 0, - sizeof(proc_pthread_mutex_t), - PROT_READ | PROT_WRITE, MAP_SHARED, - fd, 0); - if (new_mutex->pthread_interproc == (pthread_mutex_t *) (caddr_t) -1) { + new_mutex->pthread_interproc = mmap(NULL, sizeof(proc_pthread_mutex_t), + PROT_READ | PROT_WRITE, MAP_SHARED, + fd, 0); + if (new_mutex->pthread_interproc == MAP_FAILED) { + rv = errno; close(fd); - return errno; + return rv; } close(fd); + new_mutex->pthread_refcounting = 1; new_mutex->curr_locked = -1; /* until the mutex has been created */ if ((rv = pthread_mutexattr_init(&mattr))) { @@ -478,9 +494,10 @@ static apr_status_t proc_mutex_proc_pthr const char *fname) { (*mutex)->curr_locked = 0; - apr_atomic_inc32(&proc_pthread_mutex_refcount(*mutex)); - apr_pool_cleanup_register(pool, *mutex, proc_pthread_mutex_unref, - apr_pool_cleanup_null); + if (proc_pthread_mutex_inc(*mutex)) { + apr_pool_cleanup_register(pool, *mutex, proc_pthread_mutex_unref, + apr_pool_cleanup_null); + } return APR_SUCCESS; } @@ -495,7 +512,7 @@ static apr_status_t proc_mutex_proc_pthr #ifdef HAVE_PTHREAD_MUTEX_ROBUST /* Okay, our owner died. Let's try to make it consistent again. */ if (rv == EOWNERDEAD) { - apr_atomic_dec32(&proc_pthread_mutex_refcount(mutex)); + proc_pthread_mutex_dec(mutex); pthread_mutex_consistent_np(mutex->pthread_interproc); } else @@ -520,6 +537,7 @@ static apr_status_t proc_mutex_proc_pthr #ifdef HAVE_PTHREAD_MUTEX_ROBUST /* Okay, our owner died. Let's try to make it consistent again. */ if (rv == EOWNERDEAD) { + proc_pthread_mutex_dec(mutex); pthread_mutex_consistent_np(mutex->pthread_interproc); } else @@ -527,7 +545,7 @@ static apr_status_t proc_mutex_proc_pthr return rv; } mutex->curr_locked = 1; - return rv; + return APR_SUCCESS; } static apr_status_t proc_mutex_proc_pthread_release(apr_proc_mutex_t *mutex) @@ -734,8 +752,9 @@ static apr_status_t proc_mutex_flock_cre if (rv != APR_SUCCESS) { proc_mutex_flock_cleanup(new_mutex); - return errno; + return rv; } + new_mutex->curr_locked = 0; apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex, apr_proc_mutex_cleanup, @@ -795,13 +814,13 @@ static apr_status_t proc_mutex_flock_chi apr_proc_mutex_t *new_mutex; int rv; - new_mutex = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t)); - - memcpy(new_mutex, *mutex, sizeof *new_mutex); - new_mutex->pool = pool; if (!fname) { fname = (*mutex)->fname; } + + new_mutex = (apr_proc_mutex_t *)apr_pmemdup(pool, *mutex, + sizeof(apr_proc_mutex_t)); + new_mutex->pool = pool; new_mutex->fname = apr_pstrdup(pool, fname); rv = apr_file_open(&new_mutex->interproc, new_mutex->fname, APR_FOPEN_WRITE, 0, new_mutex->pool);