apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r552161 - /apr/apr/trunk/atomic/unix/apr_atomic.c
Date Sat, 30 Jun 2007 15:20:56 GMT
Author: davi
Date: Sat Jun 30 08:20:55 2007
New Revision: 552161

URL: http://svn.apache.org/viewvc?view=rev&rev=552161
Log:
Avoid overwriting the hash_mutex table for applications that incorrectly calls
apr_atomic_init().

Noticied by: Tim Jones
PR: 42760

Modified:
    apr/apr/trunk/atomic/unix/apr_atomic.c

Modified: apr/apr/trunk/atomic/unix/apr_atomic.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/atomic/unix/apr_atomic.c?view=diff&rev=552161&r1=552160&r2=552161
==============================================================================
--- apr/apr/trunk/atomic/unix/apr_atomic.c (original)
+++ apr/apr/trunk/atomic/unix/apr_atomic.c Sat Jun 30 08:20:55 2007
@@ -226,12 +226,28 @@
 static apr_thread_mutex_t **hash_mutex;
 #endif /* APR_HAS_THREADS */
 
+#if APR_HAS_THREADS
+static apr_status_t atomic_cleanup(void *data)
+{
+    if (hash_mutex == data)
+        hash_mutex = NULL;
+
+    return APR_SUCCESS;
+}
+#endif
+
 apr_status_t apr_atomic_init(apr_pool_t *p)
 {
 #if APR_HAS_THREADS
     int i;
     apr_status_t rv;
+
+    if (hash_mutex != NULL)
+        return APR_SUCCESS;
+
     hash_mutex = apr_palloc(p, sizeof(apr_thread_mutex_t*) * NUM_ATOMIC_HASH);
+    apr_pool_cleanup_register(p, hash_mutex, atomic_cleanup,
+                              apr_pool_cleanup_null);
 
     for (i = 0; i < NUM_ATOMIC_HASH; i++) {
         rv = apr_thread_mutex_create(&(hash_mutex[i]),



Mime
View raw message