[vlc-commits] threads: mwait() and msleep() using futex
Rémi Denis-Courmont
git at videolan.org
Fri May 27 23:43:04 CEST 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu May 26 22:19:48 2016 +0300| [cb4e56bdd5908044f190fdbf63f9ac58bb7c91e8] | committer: Rémi Denis-Courmont
threads: mwait() and msleep() using futex
This can be used to handle cancellation during msleep() and mwait() if
it would not otherwise work out of the box.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cb4e56bdd5908044f190fdbf63f9ac58bb7c91e8
---
src/misc/threads.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 2f9be7e..044296f 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -49,8 +49,7 @@ void vlc_global_mutex (unsigned n, bool acquire)
vlc_mutex_unlock (lock);
}
-#ifdef LIBVLC_NEED_CONDVAR
-#include <stdalign.h>
+#if defined(LIBVLC_NEED_SLEEP) || defined(LIBVLC_NEED_CONDVAR)
#include <vlc_atomic.h>
static void vlc_cancel_addr_prepare(void *addr)
@@ -69,6 +68,30 @@ static void vlc_cancel_addr_finish(void *addr)
/* Act on cancellation as potential wake-up source */
vlc_testcancel();
}
+#endif
+
+#ifdef LIBVLC_NEED_SLEEP
+void (mwait)(mtime_t deadline)
+{
+ mtime_t delay;
+ atomic_int value = ATOMIC_VAR_INIT(0);
+
+ vlc_cancel_addr_prepare(&value);
+
+ while ((delay = (deadline - mdate())) > 0)
+ vlc_addr_timedwait(&value, 0, delay);
+
+ vlc_cancel_addr_finish(&value);
+}
+
+void (msleep)(mtime_t delay)
+{
+ mwait(mdate() + delay);
+}
+#endif
+
+#ifdef LIBVLC_NEED_CONDVAR
+#include <stdalign.h>
static inline atomic_int *vlc_cond_value(vlc_cond_t *cond)
{
More information about the vlc-commits
mailing list