summaryrefslogtreecommitdiff
path: root/src/lib/thread
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2019-09-30 13:56:51 +0300
committerGeorge Kadianakis <desnacked@riseup.net>2019-09-30 13:56:51 +0300
commit9318682109c5b8742bc868f3d30cb5cd39095f98 (patch)
treee132f4fc90195467957a9bba33c9a3795fd73590 /src/lib/thread
parentae8d36db313a548d9828384f2131f481640c6173 (diff)
parentd1eab05834566f998721d3a16107767885711c57 (diff)
downloadtor-9318682109c5b8742bc868f3d30cb5cd39095f98.tar.gz
tor-9318682109c5b8742bc868f3d30cb5cd39095f98.zip
Merge branch 'tor-github/pr/1346'
Diffstat (limited to 'src/lib/thread')
-rw-r--r--src/lib/thread/compat_threads.c10
-rw-r--r--src/lib/thread/threads.h12
2 files changed, 20 insertions, 2 deletions
diff --git a/src/lib/thread/compat_threads.c b/src/lib/thread/compat_threads.c
index 1c4a5c4e3f..5c8ffa55c6 100644
--- a/src/lib/thread/compat_threads.c
+++ b/src/lib/thread/compat_threads.c
@@ -67,7 +67,15 @@ atomic_counter_init(atomic_counter_t *counter)
memset(counter, 0, sizeof(*counter));
tor_mutex_init_nonrecursive(&counter->mutex);
}
-/** Clean up all resources held by an atomic counter. */
+/** Clean up all resources held by an atomic counter.
+ *
+ * Destroying a locked mutex is undefined behaviour. Global mutexes may be
+ * locked when they are passed to this function, because multiple threads can
+ * still access them. So we can either:
+ * - destroy on shutdown, and re-initialise when tor re-initialises, or
+ * - skip destroying and re-initialisation, using a sentinel variable.
+ * See #31735 for details.
+ */
void
atomic_counter_destroy(atomic_counter_t *counter)
{
diff --git a/src/lib/thread/threads.h b/src/lib/thread/threads.h
index ecf60641b5..de3da6a585 100644
--- a/src/lib/thread/threads.h
+++ b/src/lib/thread/threads.h
@@ -131,7 +131,17 @@ atomic_counter_init(atomic_counter_t *counter)
{
atomic_init(&counter->val, 0);
}
-/** Clean up all resources held by an atomic counter. */
+/** Clean up all resources held by an atomic counter.
+ *
+ * This usage note applies to the compat_threads implementation of
+ * atomic_counter_destroy():
+ * Destroying a locked mutex is undefined behaviour. Global mutexes may be
+ * locked when they are passed to this function, because multiple threads can
+ * still access them. So we can either:
+ * - destroy on shutdown, and re-initialise when tor re-initialises, or
+ * - skip destroying and re-initialisation, using a sentinel variable.
+ * See #31735 for details.
+ */
static inline void
atomic_counter_destroy(atomic_counter_t *counter)
{