[vlc-devel] [PATCH 6/7] threads: remove cancellation from vlc_cond_t
RĂ©mi Denis-Courmont
remi at remlab.net
Tue Apr 14 21:45:43 CEST 2020
This is no longer used.
---
include/vlc_threads.h | 8 --------
src/misc/threads.c | 25 +++----------------------
2 files changed, 3 insertions(+), 30 deletions(-)
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index b0aabdb624..b1b35c3851 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -412,20 +412,15 @@ VLC_API void vlc_cond_broadcast(vlc_cond_t *);
* The canonical way to use a condition variable to wait for event foobar is:
@code
vlc_mutex_lock(&lock);
- mutex_cleanup_push(&lock); // release the mutex in case of cancellation
while (!foobar)
vlc_cond_wait(&wait, &lock);
// -- foobar is now true, do something about it here --
- vlc_cleanup_pop();
vlc_mutex_unlock(&lock);
@endcode
*
- * \note This function is a cancellation point. In case of thread cancellation,
- * the mutex is always locked before cancellation proceeds.
- *
* \param cond condition variable to wait on
* \param mutex mutex which is unlocked while waiting,
* then locked again when waking up.
@@ -439,9 +434,6 @@ VLC_API void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex);
* The time-out is expressed as an absolute timestamp using the same arbitrary
* time reference as the vlc_tick_now() and vlc_tick_wait() functions.
*
- * \note This function is a cancellation point. In case of thread cancellation,
- * the mutex is always locked before cancellation proceeds.
- *
* \param cond condition variable to wait on
* \param mutex mutex which is unlocked while waiting,
* then locked again when waking up
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 5bbfa7b74b..e32e5d58d4 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -243,8 +243,6 @@ void vlc_cond_init(vlc_cond_t *cond)
struct vlc_cond_waiter {
struct vlc_cond_waiter **pprev, *next;
atomic_uint value;
- vlc_cond_t *cond;
- vlc_mutex_t *mutex;
};
static void vlc_cond_signal_waiter(struct vlc_cond_waiter *waiter)
@@ -308,8 +306,6 @@ static void vlc_cond_wait_prepare(struct vlc_cond_waiter *waiter,
waiter->pprev = &cond->head;
atomic_init(&waiter->value, 0);
- waiter->cond = cond;
- waiter->mutex = mutex;
vlc_mutex_lock(&cond->lock);
next = cond->head;
@@ -320,7 +316,6 @@ static void vlc_cond_wait_prepare(struct vlc_cond_waiter *waiter,
next->pprev = &waiter->next;
vlc_mutex_unlock(&cond->lock);
- vlc_cancel_addr_prepare(&waiter->value);
vlc_mutex_unlock(mutex);
}
@@ -343,14 +338,6 @@ static void vlc_cond_wait_finish(struct vlc_cond_waiter *waiter,
/* Lock the caller's mutex as required by condition variable semantics. */
vlc_mutex_lock(mutex);
- vlc_cancel_addr_finish(&waiter->value);
-}
-
-static void vlc_cond_wait_cleanup(void *data)
-{
- struct vlc_cond_waiter *waiter = data;
-
- vlc_cond_wait_finish(waiter, waiter->cond, waiter->mutex);
}
void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
@@ -358,10 +345,8 @@ void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
struct vlc_cond_waiter waiter;
vlc_cond_wait_prepare(&waiter, cond, mutex);
- vlc_cleanup_push(vlc_cond_wait_cleanup, &waiter);
vlc_atomic_wait(&waiter.value, 0);
- vlc_cleanup_pop();
- vlc_cond_wait_cleanup(&waiter);
+ vlc_cond_wait_finish(&waiter, cond, mutex);
}
int vlc_cond_timedwait(vlc_cond_t *cond, vlc_mutex_t *mutex,
@@ -371,10 +356,8 @@ int vlc_cond_timedwait(vlc_cond_t *cond, vlc_mutex_t *mutex,
int ret;
vlc_cond_wait_prepare(&waiter, cond, mutex);
- vlc_cleanup_push(vlc_cond_wait_cleanup, &waiter);
ret = vlc_atomic_timedwait(&waiter.value, 0, deadline);
- vlc_cleanup_pop();
- vlc_cond_wait_cleanup(&waiter);
+ vlc_cond_wait_finish(&waiter, cond, mutex);
return ret;
}
@@ -386,10 +369,8 @@ int vlc_cond_timedwait_daytime(vlc_cond_t *cond, vlc_mutex_t *mutex,
int ret;
vlc_cond_wait_prepare(&waiter, cond, mutex);
- vlc_cleanup_push(vlc_cond_wait_cleanup, &waiter);
ret = vlc_atomic_timedwait_daytime(&waiter.value, 0, deadline);
- vlc_cleanup_pop();
- vlc_cond_wait_cleanup(&waiter);
+ vlc_cond_wait_finish(&waiter, cond, mutex);
return ret;
}
--
2.26.0
More information about the vlc-devel
mailing list