You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2011/07/02 12:35:56 UTC

svn commit: r1142193 - in /subversion/branches/svn_mutex/subversion: include/private/svn_mutex.h libsvn_subr/svn_mutex.c

Author: stefan2
Date: Sat Jul  2 10:35:55 2011
New Revision: 1142193

URL: http://svn.apache.org/viewvc?rev=1142193&view=rev
Log:
Introduce a *__with_lock function to the svn_mutex__* API.

* subversion/include/private/svn_mutex.h
  (svn_mutex__callback_t): new callback function
  (svn_mutex__with_lock): new API function
* subversion/libsvn_subr/svn_mutex.c
  (svn_mutex__with_lock): implement the new function

Suggested by: danielsh, greg

Modified:
    subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h
    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=1142193&r1=1142192&r2=1142193&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:35:55 2011
@@ -90,6 +90,20 @@ svn_error_t *
 svn_mutex__unlock(svn_mutex__t *mutex,
                   svn_error_t *err);
 
+/** Callback function to for use with @ref svn_mutex__with_lock.
+ * @a baton contains all the actual function parameters.
+ */
+typedef svn_error_t *(*svn_mutex__callback_t)(void *baton);
+
+/** Executes the function @a func with parameters given in @a cb_baton
+ * while locking @a mutex just before and unlocking it immediately after
+ * @a func has been executed.
+ */
+svn_error_t *
+svn_mutex__with_lock(svn_mutex__t *mutex,
+                     svn_mutex__callback_t func,
+                     void *cb_baton);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

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=1142193&r1=1142192&r2=1142193&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:35:55 2011
@@ -92,3 +92,12 @@ svn_mutex__unlock(svn_mutex__t *mutex, 
 
   return err;
 }
+
+svn_error_t *
+svn_mutex__with_lock(svn_mutex__t *mutex,
+                     svn_mutex__callback_t func,
+                     void *cb_baton)
+{
+  SVN_ERR(svn_mutex__lock(mutex));
+  return svn_mutex__unlock(mutex, func(cb_baton));
+}
\ No newline at end of file