Author: stefan2
Date: Mon Jul 11 19:49:46 2011
New Revision: 1145310
URL: http://svn.apache.org/viewvc?rev=1145310&view=rev
Log:
On svn_mutex branch:
turn *__WITH_LOCK into a macro, thus making it actually useful.
* subversion/include/private/svn_mutex.h
(svn_mutex__with_lock, svn_mutex__callback_t): drop
(SVN_MUTEX__WITH_LOCK): new
(svn_mutex__lock, svn_mutex__unlock): in docstrings, suggest to use _WITH_LOCK
* subversion/libsvn_subr/svn_mutex.c
(svn_mutex__with_lock): drop
Suggested by: gstein
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=1145310&r1=1145309&r2=1145310&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h
(original)
+++ subversion/branches/svn_mutex/subversion/include/private/svn_mutex.h Mon
Jul 11 19:49:46 2011
@@ -72,6 +72,9 @@ svn_mutex__init(svn_mutex__t **mutex,
/** Acquire the @a mutex, if that has been enabled in @ref svn_mutex__init.
* Make sure to call @ref svn_mutex__unlock some time later in the same
* thread to release the mutex again. Recursive locking are not supported.
+ *
+ * @note You should use @ref SVN_MUTEX__WITH_LOCK instead of explicit lock
+ * aquisition and release.
*/
svn_error_t *
svn_mutex__lock(svn_mutex__t *mutex);
@@ -85,24 +88,31 @@ svn_mutex__lock(svn_mutex__t *mutex);
* irrespective of the possible internal failures during unlock. If @a err
* is @ref SVN_NO_ERROR, internal failures of this function will be
* reported in the return value.
+ *
+ * @note You should use @ref SVN_MUTEX__WITH_LOCK instead of explicit lock
+ * aquisition and release.
*/
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.
+/** Aquires the @a mutex, executes the expression @a expr and finally
+ * releases the @a mutex. If any of these steps fail, the function using
+ * this macro will return an @ref svn_error_t. This macro guarantees that
+ * the @a mutex will always be unlocked again if it got locked successfully
+ * locked by the first step.
+ *
+ * @note Prefer using this macro instead of explicit lock aquisition and
+ * release.
*/
-svn_error_t *
-svn_mutex__with_lock(svn_mutex__t *mutex,
- svn_mutex__callback_t func,
- void *cb_baton);
+#define SVN_MUTEX__WITH_LOCK(mutex, expr) \
+do { \
+ svn_mutex__t *m = (mutex); \
+ svn_error_t *e = svn_mutex__lock(m); \
+ if (e) return svn_error_trace(e); \
+ e = svn_mutex__unlock(m, expr); \
+ if (e) return svn_error_trace(e); \
+} while (0);
#ifdef __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=1145310&r1=1145309&r2=1145310&view=diff
==============================================================================
--- subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c (original)
+++ subversion/branches/svn_mutex/subversion/libsvn_subr/svn_mutex.c Mon Jul 11
19:49:46 2011
@@ -92,12 +92,3 @@ 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