Author: stefan2
Date: Mon Jun 22 17:00:29 2015
New Revision: 1686899

URL: http://svn.apache.org/r1686899
Log:
On the fsx-1.10 branch:
Fix the last of 3 multi-threading issues with the batch fsync code.

We must destroy the thread pool before its containing pool gets cleaned
up to ensure that the sub-pools containing the threads have not been
destroyed, yet.  This is effectively an APR bug.

* subversion/libsvn_fs_x/batch_fsync.c
  (thread_pool_pre_cleanup): New cleanup function.
  (svn_fs_x__batch_fsync_init): Make sure the above gets called early
                                enough.

Modified:
    subversion/branches/fsx-1.10/subversion/libsvn_fs_x/batch_fsync.c

Modified: subversion/branches/fsx-1.10/subversion/libsvn_fs_x/batch_fsync.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/fsx-1.10/subversion/libsvn_fs_x/batch_fsync.c?rev=1686899&r1=1686898&r2=1686899&view=diff
==============================================================================
--- subversion/branches/fsx-1.10/subversion/libsvn_fs_x/batch_fsync.c (original)
+++ subversion/branches/fsx-1.10/subversion/libsvn_fs_x/batch_fsync.c Mon Jun 
22 17:00:29 2015
@@ -230,6 +230,19 @@ static apr_thread_pool_t *thread_pool =
 /* We open non-directory files with these flags. */
 #define FILE_FLAGS (APR_READ | APR_WRITE | APR_BUFFERED | APR_CREATE)
 
+/* Destructor function that implicitly cleans up any running threads
+   in the thread_pool given as DATA and releases their memory pools
+   before they get destroyed themselves.
+
+   Must be run as a pre-cleanup hook.
+ */
+static apr_status_t
+thread_pool_pre_cleanup(void *data)
+{
+  apr_thread_pool_t *tp = data;
+  return apr_thread_pool_destroy(tp);
+}
+
 svn_error_t *
 svn_fs_x__batch_fsync_init()
 {
@@ -243,6 +256,11 @@ svn_fs_x__batch_fsync_init()
   WRAP_APR_ERR(apr_thread_pool_create(&thread_pool, 0, MAX_THREADS, pool),
                _("Can't create fsync thread pool in FSX"));
 
+  /* Work around an APR bug:  The cleanup must happen in the pre-cleanup
+     hook instead of the normal cleanup hook.  Otherwise, the sub-pools
+     containing the thread objects would already be invalid. */
+  apr_pool_pre_cleanup_register(pool, thread_pool, thread_pool_pre_cleanup);
+
   /* let idle threads linger for a while in case more requests are
      coming in */
   apr_thread_pool_idle_wait_set(thread_pool, THREADPOOL_THREAD_IDLE_LIMIT);


Reply via email to