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/05/17 14:54:57 UTC
svn commit: r1104209 - /subversion/trunk/subversion/libsvn_subr/utf.c
Author: stefan2
Date: Tue May 17 12:54:57 2011
New Revision: 1104209
URL: http://svn.apache.org/viewvc?rev=1104209&view=rev
Log:
Fix breakage with pre-1.3 APRs, introduced in r1104160.
Introduce a utility function that checks for APR version as well as threading
settings and provides the suitable implementation for atomic pointer swaps.
* subversion/libsvn_subr/utf.c
(atomic_swap): new utility function
(get_xlate_handle_node, put_xlate_handle_node): call our utility instead
of the APR 1.3+ function
Modified:
subversion/trunk/subversion/libsvn_subr/utf.c
Modified: subversion/trunk/subversion/libsvn_subr/utf.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/utf.c?rev=1104209&r1=1104208&r2=1104209&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/utf.c (original)
+++ subversion/trunk/subversion/libsvn_subr/utf.c Tue May 17 12:54:57 2011
@@ -40,6 +40,7 @@
#include "win32_xlate.h"
#include "private/svn_utf_private.h"
+#include "private/svn_dep_compat.h"
@@ -174,6 +175,30 @@ get_xlate_key(const char *topage,
"-xlate-handle", (char *)NULL);
}
+/* Atomically replace the content in *MEM with NEW_VALUE and return
+ * the previous content of *MEM. If atomicy cannot be guaranteed,
+ * *MEM will not be modified and NEW_VALUE is simply returned to
+ * the caller.
+ */
+static void*
+atomic_swap(volatile void **mem, void *new_value)
+{
+#if APR_HAS_THREADS
+#if APR_VERSION_AT_LEAST(1,3,0)
+ return apr_atomic_xchgptr(mem, new_value);
+#else
+ /* old APRs don't support atomic swaps. Simply return the
+ * input to the caller for further proccessing. */
+ return new_value;
+#endif
+#else
+ /* no threads - no sync. necessary */
+ void *old_value = *mem;
+ *mem = new_value;
+ return old_value;
+#endif
+}
+
/* Set *RET to a handle node for converting from FROMPAGE to TOPAGE,
creating the handle node if it doesn't exist in USERDATA_KEY.
If a node is not cached and apr_xlate_open() returns APR_EINVAL or
@@ -201,9 +226,9 @@ get_xlate_handle_node(xlate_handle_node_
{
/* 1st level: global, static items */
if (userdata_key == SVN_UTF_NTOU_XLATE_HANDLE)
- old_node = apr_atomic_xchgptr(&xlat_ntou_static_handle, NULL);
+ old_node = atomic_swap(&xlat_ntou_static_handle, NULL);
else if (userdata_key == SVN_UTF_UTON_XLATE_HANDLE)
- old_node = apr_atomic_xchgptr(&xlat_uton_static_handle, NULL);
+ old_node = atomic_swap(&xlat_uton_static_handle, NULL);
if (old_node && old_node->valid)
{
@@ -358,12 +383,12 @@ put_xlate_handle_node(xlate_handle_node_
/* 1st level: global, static items */
if (userdata_key == SVN_UTF_NTOU_XLATE_HANDLE)
- node = apr_atomic_xchgptr(&xlat_ntou_static_handle, node);
+ node = atomic_swap(&xlat_ntou_static_handle, node);
else if (userdata_key == SVN_UTF_UTON_XLATE_HANDLE)
- node = apr_atomic_xchgptr(&xlat_uton_static_handle, node);
+ node = atomic_swap(&xlat_uton_static_handle, node);
if (node == NULL)
return;
-
+
#if APR_HAS_THREADS
if (apr_thread_mutex_lock(xlate_handle_mutex) != APR_SUCCESS)
SVN_ERR_MALFUNCTION_NO_RETURN();
Re: svn commit: r1104209 - /subversion/trunk/subversion/libsvn_subr/utf.c
Posted by Stefan Fuhrmann <st...@alice-dsl.de>.
On 17.05.2011 15:01, Ivan Zhakov wrote:
> On Tue, May 17, 2011 at 14:54,<st...@apache.org> wrote:
>> Author: stefan2
>> Date: Tue May 17 12:54:57 2011
>> New Revision: 1104209
>>
>> URL: http://svn.apache.org/viewvc?rev=1104209&view=rev
>> Log:
>> Fix breakage with pre-1.3 APRs, introduced in r1104160.
>> Introduce a utility function that checks for APR version as well as threading
>> settings and provides the suitable implementation for atomic pointer swaps.
>>
>> * subversion/libsvn_subr/utf.c
>> (atomic_swap): new utility function
>> (get_xlate_handle_node, put_xlate_handle_node): call our utility instead
>> of the APR 1.3+ function
>>
>> Modified:
>> subversion/trunk/subversion/libsvn_subr/utf.c
>>
>> Modified: subversion/trunk/subversion/libsvn_subr/utf.c
>> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/utf.c?rev=1104209&r1=1104208&r2=1104209&view=diff
>> ==============================================================================
>> --- subversion/trunk/subversion/libsvn_subr/utf.c (original)
>> +++ subversion/trunk/subversion/libsvn_subr/utf.c Tue May 17 12:54:57 2011
>> @@ -40,6 +40,7 @@
>> #include "win32_xlate.h"
>>
>> #include "private/svn_utf_private.h"
>> +#include "private/svn_dep_compat.h"
>>
>>
>>
>> @@ -174,6 +175,30 @@ get_xlate_key(const char *topage,
>> "-xlate-handle", (char *)NULL);
>> }
>>
>> +/* Atomically replace the content in *MEM with NEW_VALUE and return
>> + * the previous content of *MEM. If atomicy cannot be guaranteed,
>> + * *MEM will not be modified and NEW_VALUE is simply returned to
>> + * the caller.
>> + */
>> +static void*
>> +atomic_swap(volatile void **mem, void *new_value)
> It would be nice to mark this function as inline, since it's optimization.
>
Done in r1104277.
-- Stefan^2.
Re: svn commit: r1104209 - /subversion/trunk/subversion/libsvn_subr/utf.c
Posted by Ivan Zhakov <iv...@visualsvn.com>.
On Tue, May 17, 2011 at 14:54, <st...@apache.org> wrote:
> Author: stefan2
> Date: Tue May 17 12:54:57 2011
> New Revision: 1104209
>
> URL: http://svn.apache.org/viewvc?rev=1104209&view=rev
> Log:
> Fix breakage with pre-1.3 APRs, introduced in r1104160.
> Introduce a utility function that checks for APR version as well as threading
> settings and provides the suitable implementation for atomic pointer swaps.
>
> * subversion/libsvn_subr/utf.c
> (atomic_swap): new utility function
> (get_xlate_handle_node, put_xlate_handle_node): call our utility instead
> of the APR 1.3+ function
>
> Modified:
> subversion/trunk/subversion/libsvn_subr/utf.c
>
> Modified: subversion/trunk/subversion/libsvn_subr/utf.c
> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/utf.c?rev=1104209&r1=1104208&r2=1104209&view=diff
> ==============================================================================
> --- subversion/trunk/subversion/libsvn_subr/utf.c (original)
> +++ subversion/trunk/subversion/libsvn_subr/utf.c Tue May 17 12:54:57 2011
> @@ -40,6 +40,7 @@
> #include "win32_xlate.h"
>
> #include "private/svn_utf_private.h"
> +#include "private/svn_dep_compat.h"
>
>
>
> @@ -174,6 +175,30 @@ get_xlate_key(const char *topage,
> "-xlate-handle", (char *)NULL);
> }
>
> +/* Atomically replace the content in *MEM with NEW_VALUE and return
> + * the previous content of *MEM. If atomicy cannot be guaranteed,
> + * *MEM will not be modified and NEW_VALUE is simply returned to
> + * the caller.
> + */
> +static void*
> +atomic_swap(volatile void **mem, void *new_value)
It would be nice to mark this function as inline, since it's optimization.
--
Ivan Zhakov