Author: stefan2
Date: Sat Jul  2 10:20:56 2011
New Revision: 1142191

URL: http://svn.apache.org/viewvc?rev=1142191&view=rev
Log:
Bring svn_mutex__* API more in line with its APR counterpart.

* subversion/include/private/svn_mutex.h
  (svn_mutex__t): make it an actual typedef instead of a wrapper struct
  (svn_mutex__init, svn_mutex__lock, svn_mutex__unlock): switch to pointer 
style API
* subversion/libsvn_subr/svn_mutex.c
  (uninit, svn_mutex__lock, svn_mutex__unlock): adapt implementation to API 
change
  (svn_mutex__init): dito; use SVN error code instead of APR_ENOIMPL

* subversion/libsvn_subr/dso.c
  (dso_mutex): svn_mutex__t is now to be used via a pointer
* subversion/libsvn_subr/cache-membuffer.c
  (svn_membuffer_t): dito
* subversion/libsvn_subr/cache-inprocess.c
  (inprocess_cache_t): dito
* subversion/libsvn_fs_fs/fs_fs.c
  (with_some_lock): dito
* subversion/libsvn_fs_fs/fs.h
  (fs_fs_shared_data_t): dito
* subversion/libsvn_fs/fs-loader.c
  (common_pool_lock): dito

Modified:
    subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h
    subversion/branches/svn_mutex/subversion/libsvn_fs/fs-loader.c
    subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs.h
    subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs_fs.c
    subversion/branches/svn_mutex/subversion/libsvn_subr/cache-inprocess.c
    subversion/branches/svn_mutex/subversion/libsvn_subr/cache-membuffer.c
    subversion/branches/svn_mutex/subversion/libsvn_subr/dso.c
    subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c

Modified: subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h?rev=1142191&r1=1142190&r2=1142191&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h 
(original)
+++ subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h Sat 
Jul  2 10:20:56 2011
@@ -28,6 +28,7 @@
 #define SVN_MUTEX_H
 
 #include <apr_thread_mutex.h>
+
 #include "svn_error.h"
 
 #ifdef __cplusplus
@@ -37,35 +38,34 @@ extern "C" {
 /**
  * This is a simple wrapper around @c apr_thread_mutex_t and will be a
  * valid identifier even if APR does not support threading.
- * 
- * @note In contrast to other structures, this one shall be treated as 
- * a pointer type, i.e. be instantiated and be passed by value instead by
- * reference. There is simply no point in introducing yet another level
- * of indirection and pointers to check for validity.
  */
-typedef struct svn_mutex__t
-{
 #if APR_HAS_THREADS
 
-  /** A mutex for synchronization between threads. It may be NULL, in
-   * which case no synchronization will take place. The latter is useful,
-   * if implement some functionality where synchronization is optional.
-   */
-  apr_thread_mutex_t *mutex;
-  
+/** A mutex for synchronization between threads. It may be NULL, in
+ * which case no synchronization will take place. The latter is useful,
+ * if implement some functionality where synchronization is optional.
+ */
+typedef apr_thread_mutex_t svn_mutex__t;
+
+#else
+
+/** Dummy definition. The content will never be actually accessed.
+ */
+typedef int svn_mutex__t;
+
 #endif
-} svn_mutex__t;
 
 /** Initialize the @a *mutex. If @a enable_mutex is TRUE, the mutex will
  * actually be created with a lifetime defined by @a pool. Otherwise, the
- * wrapped pointer will be set to @c NULL and @ref svn_mutex__lock as well
- * as @ref svn_mutex__unlock will be no-ops.
+ * pointer will be set to @c NULL and @ref svn_mutex__lock as well as
+ * @ref svn_mutex__unlock will be no-ops. The same happens at the end 
+ * of the pool lifetime as part of the pool cleanup.
  * 
  * If @a enable_mutex is set but threading is not supported by APR, this 
  * function returns an @c APR_ENOTIMPL error.
  */
 svn_error_t *
-svn_mutex__init(svn_mutex__t *mutex,
+svn_mutex__init(svn_mutex__t **mutex,
                 svn_boolean_t enable_mutex,
                 apr_pool_t *pool);
 
@@ -74,7 +74,7 @@ svn_mutex__init(svn_mutex__t *mutex,
  * thread to release the mutex again. Recursive locking are not supported.
  */
 svn_error_t *
-svn_mutex__lock(svn_mutex__t mutex);
+svn_mutex__lock(svn_mutex__t *mutex);
 
 /** Release the @a mutex, previously acquired using @ref svn_mutex__lock
  * that has been enabled in @ref svn_mutex__init.
@@ -87,7 +87,7 @@ svn_mutex__lock(svn_mutex__t mutex);
  * reported in the return value.
  */
 svn_error_t *
-svn_mutex__unlock(svn_mutex__t mutex,
+svn_mutex__unlock(svn_mutex__t *mutex,
                   svn_error_t *err);
 
 #ifdef __cplusplus

Modified: subversion/branches/svn_mutex/subversion/libsvn_fs/fs-loader.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/libsvn_fs/fs-loader.c?rev=1142191&r1=1142190&r2=1142191&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/libsvn_fs/fs-loader.c (original)
+++ subversion/branches/svn_mutex/subversion/libsvn_fs/fs-loader.c Sat Jul  2 
10:20:56 2011
@@ -58,7 +58,7 @@
 /* A pool common to all FS objects.  See the documentation on the
    open/create functions in fs-loader.h and for svn_fs_initialize(). */
 static apr_pool_t *common_pool;
-svn_mutex__t common_pool_lock;
+svn_mutex__t *common_pool_lock;
 
 
 /* --- Utility functions for the loader --- */

Modified: subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs.h
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs.h?rev=1142191&r1=1142190&r2=1142191&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs.h (original)
+++ subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs.h Sat Jul  2 
10:20:56 2011
@@ -25,7 +25,6 @@
 
 #include <apr_pools.h>
 #include <apr_hash.h>
-#include <apr_thread_mutex.h>
 #include <apr_network_io.h>
 
 #include "svn_fs.h"
@@ -184,15 +183,15 @@ typedef struct fs_fs_shared_data_t
   fs_fs_shared_txn_data_t *free_txn;
 
   /* A lock for intra-process synchronization when accessing the TXNS list. */
-  svn_mutex__t txn_list_lock;
+  svn_mutex__t *txn_list_lock;
 #if SVN_FS_FS__USE_LOCK_MUTEX
   /* A lock for intra-process synchronization when grabbing the
      repository write lock. */
-  svn_mutex__t fs_write_lock;
+  svn_mutex__t *fs_write_lock;
 
   /* A lock for intra-process synchronization when locking the
      txn-current file. */
-  svn_mutex__t txn_current_lock;
+  svn_mutex__t *txn_current_lock;
 #endif
 
   /* The common pool, under which this object is allocated, subpools

Modified: subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs_fs.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs_fs.c?rev=1142191&r1=1142190&r2=1142191&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs_fs.c (original)
+++ subversion/branches/svn_mutex/subversion/libsvn_fs_fs/fs_fs.c Sat Jul  2 
10:20:56 2011
@@ -554,7 +554,7 @@ with_some_lock(svn_fs_t *fs,
                void *baton,
                const char *lock_filename,
 #if SVN_FS_FS__USE_LOCK_MUTEX
-               svn_mutex__t lock_mutex,
+               svn_mutex__t *lock_mutex,
 #endif
                apr_pool_t *pool)
 {

Modified: subversion/branches/svn_mutex/subversion/libsvn_subr/cache-inprocess.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/libsvn_subr/cache-inprocess.c?rev=1142191&r1=1142190&r2=1142191&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/libsvn_subr/cache-inprocess.c 
(original)
+++ subversion/branches/svn_mutex/subversion/libsvn_subr/cache-inprocess.c Sat 
Jul  2 10:20:56 2011
@@ -84,7 +84,7 @@ typedef struct inprocess_cache_t {
   /* A lock for intra-process synchronization to the cache, or NULL if
    * the cache's creator doesn't feel the cache needs to be
    * thread-safe. */
-  svn_mutex__t mutex;
+  svn_mutex__t *mutex;
 } inprocess_cache_t;
 
 /* A cache page; all items on the page are allocated from the same

Modified: subversion/branches/svn_mutex/subversion/libsvn_subr/cache-membuffer.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/libsvn_subr/cache-membuffer.c?rev=1142191&r1=1142190&r2=1142191&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/libsvn_subr/cache-membuffer.c 
(original)
+++ subversion/branches/svn_mutex/subversion/libsvn_subr/cache-membuffer.c Sat 
Jul  2 10:20:56 2011
@@ -428,7 +428,7 @@ struct svn_membuffer_t
    * the cache's creator doesn't feel the cache needs to be
    * thread-safe.
    */
-  svn_mutex__t mutex;
+  svn_mutex__t *mutex;
 };
 
 /* Align integer VALUE to the next ITEM_ALIGNMENT boundary.

Modified: subversion/branches/svn_mutex/subversion/libsvn_subr/dso.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/libsvn_subr/dso.c?rev=1142191&r1=1142190&r2=1142191&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/libsvn_subr/dso.c (original)
+++ subversion/branches/svn_mutex/subversion/libsvn_subr/dso.c Sat Jul  2 
10:20:56 2011
@@ -29,7 +29,7 @@
 #include "private/svn_mutex.h"
 
 /* A mutex to protect our global pool and cache. */
-static svn_mutex__t dso_mutex;
+static svn_mutex__t *dso_mutex = NULL;
 
 /* Global pool to allocate DSOs in. */
 static apr_pool_t *dso_pool;

Modified: subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c?rev=1142191&r1=1142190&r2=1142191&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c (original)
+++ subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c Sat Jul  2 
10:20:56 2011
@@ -27,19 +27,19 @@
 /* Destructor to be called as part of the pool cleanup procedure. */
 static apr_status_t uninit(void *data)
 {
-  svn_mutex__t *mutex = data;
-  mutex->mutex = NULL;
+  svn_mutex__t **mutex = data;
+  *mutex = NULL;
 
   return APR_SUCCESS;
 }
 
 svn_error_t *
-svn_mutex__init(svn_mutex__t *mutex, 
+svn_mutex__init(svn_mutex__t **mutex, 
                 svn_boolean_t enable_mutex, 
                 apr_pool_t *pool)
 {
 #if APR_HAS_THREADS
-  mutex->mutex = NULL;
+  *mutex = NULL;
   if (enable_mutex)
     {
       apr_thread_mutex_t *apr_mutex;
@@ -50,24 +50,25 @@ svn_mutex__init(svn_mutex__t *mutex, 
       if (status)
         return svn_error_wrap_apr(status, _("Can't create mutex"));
 
-      mutex->mutex = apr_mutex;
+      *mutex = apr_mutex;
       apr_pool_cleanup_register(pool, mutex, uninit, apr_pool_cleanup_null);
     }
 #else
   if (enable_mutex)
-    return svn_error_wrap_apr(APR_ENOTIMPL, _("APR doesn't support threads"));
+    return svn_error_wrap_apr(SVN_ERR_UNSUPPORTED_FEATURE,
+                              _("APR doesn't support threads"));
 #endif
     
   return SVN_NO_ERROR;
 }
 
 svn_error_t *
-svn_mutex__lock(svn_mutex__t mutex)
+svn_mutex__lock(svn_mutex__t *mutex)
 {
 #if APR_HAS_THREADS
-  if (mutex.mutex)
+  if (mutex)
     {
-      apr_status_t status = apr_thread_mutex_lock(mutex.mutex);
+      apr_status_t status = apr_thread_mutex_lock(mutex);
       if (status)
         return svn_error_wrap_apr(status, _("Can't lock mutex"));
     }
@@ -77,13 +78,13 @@ svn_mutex__lock(svn_mutex__t mutex)
 }
 
 svn_error_t *
-svn_mutex__unlock(svn_mutex__t mutex, 
+svn_mutex__unlock(svn_mutex__t *mutex, 
                   svn_error_t *err)
 {
 #if APR_HAS_THREADS
-  if (mutex.mutex)
+  if (mutex)
     {
-      apr_status_t status = apr_thread_mutex_unlock(mutex.mutex);
+      apr_status_t status = apr_thread_mutex_unlock(mutex);
       if (status && !err)
         return svn_error_wrap_apr(status, _("Can't unlock mutex"));
     }


Reply via email to