apr-bugs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 42760] New: - Atomic hash_mutex overwritten on multiple calls to apr_atomic_init
Date Thu, 28 Jun 2007 07:03:56 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42760>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42760

           Summary: Atomic hash_mutex overwritten on multiple calls to
                    apr_atomic_init
           Product: APR
           Version: HEAD
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: APR
        AssignedTo: bugs@apr.apache.org
        ReportedBy: tim@mr-dog.net


The global hash_mutex table is initialised every time apr_atomic_init is called.
I know this, ideally, should be called once per application, but I'm using both
APR and Log4cxx. Log4cxx also uses APR, and initialises the APR.

Log4cxx calls apr_initialize and then apr_atomic_init within it's singleton
initialiser class. Not knowing this, and as this is Log4cxx internals, I myself
call both apt_initialize and then apr_atomic_init thus overwriting the global
hash_mutex. This causes things to go bang.

I'm using this patch to overcome this and thought it maybe a useful addition to
the APRs initialisation.

Cheers,

Tim

Index: apr_atomic.c
===================================================================
--- apr_atomic.c        (revision 5)
+++ apr_atomic.c        (working copy)
@@ -168,7 +168,7 @@
 #define NUM_ATOMIC_HASH 7
 /* shift by 2 to get rid of alignment issues */
 #define ATOMIC_HASH(x) (unsigned int)(((unsigned long)(x)>>2)%(unsigned
int)NUM_ATOMIC_HASH)
-static apr_thread_mutex_t **hash_mutex;
+static apr_thread_mutex_t **hash_mutex = 0;
 #endif /* APR_HAS_THREADS */
 
 apr_status_t apr_atomic_init(apr_pool_t *p)
@@ -176,13 +176,16 @@
 #if APR_HAS_THREADS
     int i;
     apr_status_t rv;
-    hash_mutex = apr_palloc(p, sizeof(apr_thread_mutex_t*) * NUM_ATOMIC_HASH);
 
-    for (i = 0; i < NUM_ATOMIC_HASH; i++) {
-        rv = apr_thread_mutex_create(&(hash_mutex[i]),
-                                     APR_THREAD_MUTEX_DEFAULT, p);
-        if (rv != APR_SUCCESS) {
-           return rv;
+    if (hash_mutex == 0) {
+        hash_mutex = apr_palloc(p, sizeof(apr_thread_mutex_t*) * NUM_ATOMIC_HASH);
+
+        for (i = 0; i < NUM_ATOMIC_HASH; i++) {
+            rv = apr_thread_mutex_create(&(hash_mutex[i]),
+                                         APR_THREAD_MUTEX_DEFAULT, p);
+            if (rv != APR_SUCCESS) {
+                return rv;
+            }
         }
     }
 #endif /* APR_HAS_THREADS */

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


Mime
View raw message