<html><head></head><body>The intent is to provide an implementation of the APIs to fall back on. What it already says.<br><br><div class="gmail_quote">Le 17 février 2020 15:58:07 GMT+02:00, Alexandre Janniaux <ajanni@videolabs.io> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">Hi,<br><br>On Mon, Feb 17, 2020 at 03:35:40PM +0200, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> I want the APIs to work on all platforms, and this adds a generic POSIX implementation. Exactly what it says already. I don't know what else you want to explain.<br><br></blockquote><br>You could probably describe the intent (in which case is it need<br>and why?) and give a general guideline to help review.<br><br>What you add is always supposed to be written in the diff section<br>of the patch itself or the naming is bad. Here it is correct but<br>I feel the intent and guidelines could be helpful.<br><br>Regards,<br>--<br>Alexandre Janniaux<br>Videolabs<br><br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">Le 17 février 2020 14:39:08 GMT+02:00, Thomas Guillem <thomas@gllm.fr> a écrit :<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"><br>On Sun, Feb 16, 2020, at 18:50, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;"><hr> src/Makefile.am  |   3 ++<br> src/posix/wait.c | 128<br></blockquote>+++++++++++++++++++++++++++++++++++++++++++++++<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">  2 files changed, 131 insertions(+)<br>  create mode 100644 src/posix/wait.c<br><br> diff --git a/src/Makefile.am b/src/Makefile.am<br> index f2adf61095..0ad47fc105 100644<br> --- a/src/Makefile.am<br> +++ b/src/Makefile.am<br> @@ -482,6 +482,9 @@ libvlccore_la_SOURCES += \<br>        posix/plugin.c \<br>      posix/rand.c \<br>        posix/timer.c<br> +if !HAVE_LINUX<br> +libvlccore_la_SOURCES += posix/wait.c<br> +endif<br>  if !HAVE_ANDROID<br>  libvlccore_la_SOURCES += posix/sort.c<br>  if !HAVE_DARWIN<br> diff --git a/src/posix/wait.c b/src/posix/wait.c<br> new file mode 100644<br> index 0000000000..60f9c7626f<br> --- /dev/null<br> +++ b/src/posix/wait.c<br> @@ -0,0 +1,128 @@<br><br></blockquote>+/*****************************************************************************<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+ * wait.c : pthread back-end for vlc_atomic_wait<br>+<br></blockquote>*****************************************************************************<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+ * Copyright (C) 2019-2020 Rémi Denis-Courmont<br>+ *<br>+ * This program is free software; you can redistribute it and/or<br></blockquote>modify it<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+ * under the terms of the GNU Lesser General Public License as<br></blockquote>published by<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+ * the Free Software Foundation; either version 2.1 of the License,<br></blockquote>or<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+ * (at your option) any later version.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>+ * GNU Lesser General Public License for more details.<br>+ *<br>+ * You should have received a copy of the GNU Lesser General Public<br></blockquote>License<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+ * along with this program; if not, write to the Free Software<br></blockquote>Foundation,<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br>+<br></blockquote>*****************************************************************************/<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+<br>+#ifdef HAVE_CONFIG_H<br>+# include "config.h"<br>+#endif<br>+<br>+#include <vlc_common.h><br>+<br>+#include <stdalign.h><br>+#include <stdatomic.h><br>+#include <errno.h><br>+#include <time.h><br>+<br>+#include <sys/types.h><br>+#include <pthread.h><br>+<br>+#define WAIT_BUCKET_INIT \<br>+     { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 }<br>+#define WAIT_BUCKET_INIT_2 WAIT_BUCKET_INIT, WAIT_BUCKET_INIT<br>+#define WAIT_BUCKET_INIT_4 WAIT_BUCKET_INIT_2, WAIT_BUCKET_INIT_2<br>+#define WAIT_BUCKET_INIT_8 WAIT_BUCKET_INIT_4, WAIT_BUCKET_INIT_4<br>+#define WAIT_BUCKET_INIT_16 WAIT_BUCKET_INIT_8, WAIT_BUCKET_INIT_8<br>+#define WAIT_BUCKET_INIT_32 WAIT_BUCKET_INIT_16, WAIT_BUCKET_INIT_16<br></blockquote><br>If I understand correctly, this bucket is here to minimize the number<br>of spurious wake, but it doesn't prevent it from happening, which is<br>fine ?<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+<br>+static struct wait_bucket<br>+{<br>+    pthread_mutex_t lock;<br>+    pthread_cond_t wait;<br>+    unsigned waiters;<br>+} wait_buckets[32] = { WAIT_BUCKET_INIT_32 };<br>+<br>+static struct wait_bucket *wait_bucket_get(atomic_uint *addr)<br>+{<br>+    uintptr_t u = (uintptr_t)addr;<br>+    size_t idx = (u / alignof (*addr)) % ARRAY_SIZE(wait_buckets);<br>+<br>+    return &wait_buckets[idx];<br>+}<br>+<br>+static struct wait_bucket *wait_bucket_enter(atomic_uint *addr)<br>+{<br>+    struct wait_bucket *bucket = wait_bucket_get(addr);<br>+<br>+    pthread_mutex_lock(&bucket->lock);<br>+    bucket->waiters++;<br>+    return bucket;<br>+}<br>+<br>+static void wait_bucket_leave(void *data)<br>+{<br>+    struct wait_bucket *bucket = data;<br>+<br>+    bucket->waiters--;<br>+    pthread_mutex_unlock(&bucket->lock);<br>+}<br>+<br>+void vlc_atomic_wait(void *addr, unsigned value)<br>+{<br>+    atomic_uint *futex = addr;<br>+    struct wait_bucket *bucket = wait_bucket_enter(futex);<br>+<br>+    pthread_cleanup_push(wait_bucket_leave, bucket);<br>+<br>+    if (value == atomic_load_explicit(futex, memory_order_relaxed))<br>+        pthread_cond_wait(&bucket->wait, &bucket->lock);<br>+<br>+    pthread_cleanup_pop(1);<br>+}<br>+<br>+bool vlc_atomic_timedwait(void *addr, unsigned value, vlc_tick_t<br></blockquote>delay)<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+{<br>+    atomic_uint *futex = addr;<br>+    struct wait_bucket *bucket;<br>+    struct timespec ts;<br>+    lldiv_t d = lldiv(delay, CLOCK_FREQ);<br>+    int ret = 0;<br>+<br>+    clock_gettime(CLOCK_MONOTONIC, &ts);<br>+    ts.tv_sec += d.quot;<br>+    ts.tv_nsec += NS_FROM_VLC_TICK(d.rem);<br>+<br>+    if (ts.tv_nsec >= 1000000000) {<br>+        ts.tv_sec++;<br>+        ts.tv_nsec -= 1000000000;<br>+    }<br>+<br>+    bucket = wait_bucket_enter(futex);<br>+    pthread_cleanup_push(wait_bucket_leave, bucket);<br>+<br>+    if (value == atomic_load_explicit(futex, memory_order_relaxed))<br>+        ret = pthread_cond_timedwait(&bucket->wait, &bucket->lock,<br></blockquote>&ts);<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">+<br>+    pthread_cleanup_pop(1);<br>+    return ret == 0;<br>+}<br>+<br>+void vlc_atomic_notify_one(void *addr)<br>+{<br>+    vlc_atomic_notify_all(addr);<br>+}<br>+<br>+void vlc_atomic_notify_all(void *addr)<br>+{<br>+    struct wait_bucket *bucket = wait_bucket_get(addr);<br>+<br>+    pthread_mutex_lock(&bucket->lock);<br>+    if (bucket->waiters > 0)<br>+        pthread_cond_broadcast(&bucket->wait);<br>+    pthread_mutex_unlock(&bucket->lock);<br>+}<br></blockquote>OK for me, but it deserves a git message and/or few comments. It took<br>me some time to understand what you wanted to do.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;"> --<br> 2.25.0<hr> vlc-devel mailing list<br> To unsubscribe or modify your subscription options:<br> <a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote>--<br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.<br></blockquote><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>