[vlc-commits] [Git][videolan/vlc][master] android: allow vlc_tick_wait to be called from a non-killable thread
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Aug 6 08:49:43 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
6c2b7c06 by Pierre Lamot at 2024-08-06T08:36:11+00:00
android: allow vlc_tick_wait to be called from a non-killable thread
fixes: #28727
- - - - -
1 changed file:
- src/android/thread.c
Changes:
=====================================
src/android/thread.c
=====================================
@@ -45,6 +45,16 @@
#include <vlc_atomic.h>
+static unsigned vlc_clock_prec;
+
+static void vlc_clock_setup_once (void)
+{
+ struct timespec res;
+ if (unlikely(clock_getres(CLOCK_MONOTONIC, &res) != 0 || res.tv_sec != 0))
+ abort ();
+ vlc_clock_prec = (res.tv_nsec + 500) / 1000;
+}
+
/* debug */
#ifndef NDEBUG
@@ -213,9 +223,26 @@ void *vlc_threadvar_get (vlc_threadvar_t key)
/* time */
void (vlc_tick_wait)(vlc_tick_t deadline)
{
- do
- vlc_testcancel();
- while (vlc_atomic_timedwait(&thread->killed, false, deadline) == 0);
+ static pthread_once_t vlc_clock_once = PTHREAD_ONCE_INIT;
+
+ if (likely(thread != NULL) && thread->killable)
+ {
+ do
+ vlc_testcancel();
+ while (vlc_atomic_timedwait(&thread->killed, false, deadline) == 0);
+ }
+ else
+ {
+ /* If the deadline is already elapsed, or within the clock precision,
+ * do not even bother the system timer. */
+ pthread_once(&vlc_clock_once, vlc_clock_setup_once);
+ deadline -= vlc_clock_prec;
+
+ struct timespec ts;
+
+ vlc_tick_to_timespec(&ts, deadline);
+ while (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL) == EINTR);
+ }
}
void (vlc_tick_sleep)(vlc_tick_t delay)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6c2b7c06625b80f8074cf2a131a8a2740ec88f48
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6c2b7c06625b80f8074cf2a131a8a2740ec88f48
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list