<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div><br></div><div><br></div><div>On Mon, Mar 30, 2020, at 10:27, Rémi Denis-Courmont wrote:<br></div><blockquote type="cite" id="qt"><div>Hi,<br></div><div><br></div><div>It's a very peculiar and disagreeable opinion that the existing code is more readable. This patch follows the same logic as normal single thread lazy init would, which is more readable to me than the pthread_once() (anti)pattern.<br></div></blockquote><div><br></div><div><br></div><blockquote type="cite" id="qt"><div><br></div><div>As for why, it's much faster than pthread_once since it removes unnecessary barriers, and it removes the last (non-Linux) vlc_once usage.<br></div></blockquote><div><br></div><div>Thanks for the explanation, I think it  deserves to be in the commit log.<br></div><div><br></div><blockquote type="cite" id="qt"><div class="qt-gmail_quote"><div>Le 30 mars 2020 10:37:01 GMT+03:00, Thomas Guillem <thomas@gllm.fr> a écrit :<br></div><blockquote class="qt-gmail_quote" style="margin-top:0pt;margin-right:0pt;margin-bottom:0pt;margin-left:0.8ex;border-left-color:rgb(204, 204, 204);border-left-style:solid;border-left-width:1px;padding-left:1ex;"><pre class="qt-k9mail"><div>Hello,<br></div><div><br></div><div>On Sun, Mar 29, 2020, at 22:43, Rémi Denis-Courmont wrote:<br></div><blockquote class="qt-gmail_quote" style="margin-top:0pt;margin-right:0pt;margin-bottom:1ex;margin-left:0.8ex;border-left-color:rgb(114, 159, 207);border-left-style:solid;border-left-width:1px;padding-left:1ex;"><div>In the unlikely event that multiple threads want to check the CPU<br></div><div>flags concurrently, simply compute them as many times.<hr> src/misc/cpu.c | 20 +++++++++++---------<br></div><div> 1 file changed, 11 insertions(+), 9 deletions(-)<br></div><div><br></div><div>diff --git a/src/misc/cpu.c b/src/misc/cpu.c<br></div><div>index 7f3a89a3cb..7053a391e7 100644<br></div><div>--- a/src/misc/cpu.c<br></div><div>+++ b/src/misc/cpu.c<br></div><div>@@ -29,6 +29,8 @@<br></div><div> # include "config.h"<br></div><div> #endif<br></div><div> <br></div><div>+#include <stdatomic.h><br></div><div>+<br></div><div> #include <vlc_common.h><br></div><div> #include <vlc_cpu.h><br></div><div> #include <vlc_memstream.h><br></div><div>@@ -247,18 +249,18 @@ out:<br></div><div>     return i_capabilities;<br></div><div> }<br></div><div> <br></div><div>-static uint32_t cpu_flags;<br></div><div>-<br></div><div>-static void vlc_CPU_init(void)<br></div><div>-{<br></div><div>-    cpu_flags = vlc_CPU_raw();<br></div><div>-}<br></div><div>+static atomic_uint cpu_flags = ATOMIC_VAR_INIT(-1);<br></div><div> <br></div><div> VLC_WEAK unsigned vlc_CPU(void)<br></div><div> {<br></div><div>-    static vlc_once_t once = VLC_STATIC_ONCE;<br></div><div>-    vlc_once(&once, vlc_CPU_init);<br></div><div>-    return cpu_flags;<br></div><div>+    unsigned flags = atomic_load_explicit(&cpu_flags, memory_order_relaxed);<br></div><div>+<br></div><div>+    if (unlikely(flags == -1U)) {<br></div><div>+        flags = vlc_CPU_raw();<br></div><div>+        atomic_store_explicit(&cpu_flags, flags, memory_order_relaxed);<br></div><div>+    }<br></div><div>+<br></div><div>+    return flags;<br></div></blockquote><div><br></div><div>I don't understand why we should need this optimization. pthread_once will very likely use an atomic to do the check.<br></div><div>Furthermore, the previous code is more readable for me.<br></div><div><br></div><blockquote class="qt-gmail_quote" style="margin-top:0pt;margin-right:0pt;margin-bottom:1ex;margin-left:0.8ex;border-left-color:rgb(114, 159, 207);border-left-style:solid;border-left-width:1px;padding-left:1ex;"><div> }<br></div><div> <br></div><div> void vlc_CPU_dump (vlc_object_t *obj)<br></div><div>-- <br></div><div>2.26.0<hr>vlc-devel mailing list<br></div><div>To unsubscribe or modify your subscription options:<br></div><div><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></div></blockquote><div><hr>vlc-devel mailing list<br></div><div>To unsubscribe or modify your subscription options:<br></div><div><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></div></pre></blockquote></div><div><br></div><div>-- <br></div><div>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté. <br></div><div>_______________________________________________<br></div><div>vlc-devel mailing list<br></div><div>To unsubscribe or modify your subscription options:<br></div><div>https://mailman.videolan.org/listinfo/vlc-devel<br></div></blockquote><div><br></div></body></html>