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 2021/04/06 13:07:05 UTC
svn commit: r1888434 - in /subversion/trunk/subversion:
include/private/svn_thread_cond.h libsvn_fs_x/batch_fsync.c
libsvn_subr/thread_cond.c
Author: stefan2
Date: Tue Apr 6 13:07:05 2021
New Revision: 1888434
URL: http://svn.apache.org/viewvc?rev=1888434&view=rev
Log:
Turn svn_thread_cond__* into a proper internal API.
The APR dependency follows the same logic as svn_mutex__t.
* subversion/include/private/svn_thread_cond.h
(new file): Declare & document the new internal API.
* subversion/libsvn_subr/thread_cond.c
(new file): Implement the new internal API.
* subversion/libsvn_fs_x/batch_fsync.c
(svn_thread_cond__t, svn_thread_cond__create,
svn_thread_cond__broadcast, svn_thread_cond__wait): Remove here.
Added:
subversion/trunk/subversion/include/private/svn_thread_cond.h (with props)
subversion/trunk/subversion/libsvn_subr/thread_cond.c (with props)
Modified:
subversion/trunk/subversion/libsvn_fs_x/batch_fsync.c
Added: subversion/trunk/subversion/include/private/svn_thread_cond.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_thread_cond.h?rev=1888434&view=auto
==============================================================================
--- subversion/trunk/subversion/include/private/svn_thread_cond.h (added)
+++ subversion/trunk/subversion/include/private/svn_thread_cond.h Tue Apr 6 13:07:05 2021
@@ -0,0 +1,105 @@
+/**
+ * @copyright
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ * @endcopyright
+ *
+ * @file svn_thread_cond.h
+ * @brief Structures and functions for thread condition variables
+ */
+
+#ifndef SVN_THREAD_COND_H
+#define SVN_THREAD_COND_H
+
+#include "svn_mutex.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * This is a simple wrapper around @c apr_thread_cond_t and will be a
+ * valid identifier even if APR does not support threading.
+ */
+
+/**
+ * A waitable condition variable.
+ *
+ * If APR does not support threading, this will be a dummy object with no
+ * effect on program execution - because there can't be any other threads to
+ * wake up, synchronize etc.
+ */
+#if APR_HAS_THREADS
+#include <apr_thread_cond.h>
+typedef apr_thread_cond_t svn_thread_cond__t;
+#else
+typedef int svn_thread_cond__t;
+#endif
+
+/**
+ * Construct the condition variable @a cond, allocate it in @a result_pool.
+ * The variable will be "not signalled" state.
+ *
+ * This wraps @c apr_thread_cond_create().
+ * If threading is not supported by APR, this function is a no-op.
+ */
+svn_error_t *
+svn_thread_cond__create(svn_thread_cond__t **cond,
+ apr_pool_t *result_pool);
+
+/**
+ * Signal @a cond once, i.e. wake up exactly one of the threads waiting on
+ * this variable. If no threads are waiting, this is a no-op.
+ *
+ * This wraps @c apr_thread_cond_signal().
+ * If threading is not supported by APR, this function is a no-op.
+ */
+svn_error_t *
+svn_thread_cond__signal(svn_thread_cond__t *cond);
+
+/**
+ * Broadcast @a cond, i.e. wake up all threads waiting on this variable.
+ * If no threads are waiting, this is a no-op.
+ *
+ * This wraps @c apr_thread_cond_broadcast().
+ * If threading is not supported by APR, this function is a no-op.
+ */
+svn_error_t *
+svn_thread_cond__broadcast(svn_thread_cond__t *cond);
+
+/**
+ * Atomically release @a mutex and start waiting for @a cond. @a mutex will
+ * be locked again upon waking up this thread.
+ *
+ * @note Wakeups are usually caused by @a cond being signalled but there may
+ * also be spurious wake-ups. I.e. the caller needs to verify whether the
+ * underlying event actually happened.
+ *
+ * This wraps @c apr_thread_cond_broadcast().
+ * If threading is not supported by APR, this function is a no-op.
+ */
+svn_error_t *
+svn_thread_cond__wait(svn_thread_cond__t *cond,
+ svn_mutex__t *mutex);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* SVN_THREAD_COND_H */
Propchange: subversion/trunk/subversion/include/private/svn_thread_cond.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: subversion/trunk/subversion/libsvn_fs_x/batch_fsync.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_x/batch_fsync.c?rev=1888434&r1=1888433&r2=1888434&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_x/batch_fsync.c (original)
+++ subversion/trunk/subversion/libsvn_fs_x/batch_fsync.c Tue Apr 6 13:07:05 2021
@@ -21,7 +21,6 @@
*/
#include <apr_thread_pool.h>
-#include <apr_thread_cond.h>
#include "batch_fsync.h"
#include "svn_pools.h"
@@ -33,6 +32,7 @@
#include "private/svn_dep_compat.h"
#include "private/svn_mutex.h"
#include "private/svn_subr_private.h"
+#include "private/svn_thread_cond.h"
/* Handy macro to check APR function results and turning them into
* svn_error_t upon failure. */
@@ -43,59 +43,6 @@
return svn_error_wrap_apr(status_, msg); \
}
-
-/* A simple SVN-wrapper around the apr_thread_cond_* API */
-#if APR_HAS_THREADS
-typedef apr_thread_cond_t svn_thread_cond__t;
-#else
-typedef int svn_thread_cond__t;
-#endif
-
-static svn_error_t *
-svn_thread_cond__create(svn_thread_cond__t **cond,
- apr_pool_t *result_pool)
-{
-#if APR_HAS_THREADS
-
- WRAP_APR_ERR(apr_thread_cond_create(cond, result_pool),
- _("Can't create condition variable"));
-
-#else
-
- *cond = apr_pcalloc(result_pool, sizeof(**cond));
-
-#endif
-
- return SVN_NO_ERROR;
-}
-
-static svn_error_t *
-svn_thread_cond__broadcast(svn_thread_cond__t *cond)
-{
-#if APR_HAS_THREADS
-
- WRAP_APR_ERR(apr_thread_cond_broadcast(cond),
- _("Can't broadcast condition variable"));
-
-#endif
-
- return SVN_NO_ERROR;
-}
-
-static svn_error_t *
-svn_thread_cond__wait(svn_thread_cond__t *cond,
- svn_mutex__t *mutex)
-{
-#if APR_HAS_THREADS
-
- WRAP_APR_ERR(apr_thread_cond_wait(cond, svn_mutex__get(mutex)),
- _("Can't broadcast condition variable"));
-
-#endif
-
- return SVN_NO_ERROR;
-}
-
/* Utility construct: Clients can efficiently wait for the encapsulated
* counter to reach a certain value. Currently, only increments have been
* implemented. This whole structure can be opaque to the API users.
Added: subversion/trunk/subversion/libsvn_subr/thread_cond.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/thread_cond.c?rev=1888434&view=auto
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/thread_cond.c (added)
+++ subversion/trunk/subversion/libsvn_subr/thread_cond.c Tue Apr 6 13:07:05 2021
@@ -0,0 +1,91 @@
+/* thread_count.c --- implement SVN's wrapper around apr_thread_cond_t
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ */
+
+#include "private/svn_thread_cond.h"
+
+/* Handy macro to check APR function results and turning them into
+ * svn_error_t upon failure. */
+#define WRAP_APR_ERR(x,msg) \
+ { \
+ apr_status_t status_ = (x); \
+ if (status_) \
+ return svn_error_wrap_apr(status_, msg); \
+ }
+
+
+svn_error_t *
+svn_thread_cond__create(svn_thread_cond__t **cond,
+ apr_pool_t *result_pool)
+{
+#if APR_HAS_THREADS
+
+ WRAP_APR_ERR(apr_thread_cond_create(cond, result_pool),
+ "Can't create condition variable");
+
+#else
+
+ *cond = apr_pcalloc(result_pool, sizeof(**cond));
+
+#endif
+
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_thread_cond__signal(svn_thread_cond__t *cond)
+{
+#if APR_HAS_THREADS
+
+ WRAP_APR_ERR(apr_thread_cond_signal(cond),
+ "Can't signal condition variable");
+
+#endif
+
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_thread_cond__broadcast(svn_thread_cond__t *cond)
+{
+#if APR_HAS_THREADS
+
+ WRAP_APR_ERR(apr_thread_cond_broadcast(cond),
+ "Can't broadcast condition variable");
+
+#endif
+
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_thread_cond__wait(svn_thread_cond__t *cond,
+ svn_mutex__t *mutex)
+{
+#if APR_HAS_THREADS
+
+ WRAP_APR_ERR(apr_thread_cond_wait(cond, svn_mutex__get(mutex)),
+ "Can't wait on condition variable");
+
+#endif
+
+ return SVN_NO_ERROR;
+}
Propchange: subversion/trunk/subversion/libsvn_subr/thread_cond.c
------------------------------------------------------------------------------
svn:eol-style = native