<html><head></head><body>Hi,<br><br>You can always implement a mutex that does not need to be destroyed. We already have an implementation on Windows in the !dynamic case, but it can be generalized to other OSes. It can also be optimised with futex on Linux (incl. Android) and Windows 8+.<br><br>So that is not an issue. We could eliminate vlc_(mutex|cond|sem)_destroy() if we wanted to.<br><br><div class="gmail_quote">Le 29 janvier 2020 09:46:42 GMT+02:00, Steve Lhomme <robux4@ycbcr.xyz> 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">On 2020-01-28 21:30, 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;">This adds a function to allocate a mutex that automatically gets<br>destroyed when a module fails or terminates.<br><br>I have very mixed feelings about this, as it introduces an error return<br>where there is normally none, i.e., from vlc_mutex_init(). It also<br>requires tedious rework to replace `vlc_mutex_t' with `vlc_mutex_t *'.<br><br>For reference, kernel code entirely solves this conundrum by not<br>requiring explicit mutex destruction (a kernel mutex does not hold any<br>resource besides its own `struct mutex' storage space). This could also<br>be done, but with significant reworking of the VLC threading layer and<br></blockquote><br>Dunno about other OSes, but on Windows our mutex uses a critical section <br>that needs to be released.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">prevents reliable detection of attempt to delete a still-in-use mutex.<hr>  include/vlc_objects.h |  2 ++<br>  src/misc/objres.c     | 15 +++++++++++++++<br>  2 files changed, 17 insertions(+)<br><br>diff --git a/include/vlc_objects.h b/include/vlc_objects.h<br>index 19ee5207fc..32f23abf41 100644<br>--- a/include/vlc_objects.h<br>+++ b/include/vlc_objects.h<br>@@ -295,5 +295,7 @@ VLC_API VLC_MALLOC char *vlc_obj_strdup(vlc_object_t *obj, const char *str);<br>   */<br>  VLC_API void vlc_obj_free(vlc_object_t *obj, void *ptr);<br>  <br>+VLC_API VLC_MALLOC vlc_mutex_t *vlc_obj_mutex_new(vlc_object_t *obj);<br>+<br>  /** @} */<br>  /** @} */<br>diff --git a/src/misc/objres.c b/src/misc/objres.c<br>index cac8624e7e..383dd760a8 100644<br>--- a/src/misc/objres.c<br>+++ b/src/misc/objres.c<br>@@ -174,3 +174,18 @@ void vlc_obj_free(vlc_object_t *obj, void *ptr)<br>  {<br>      vlc_objres_remove(obj, ptr, ptrcmp);<br>  }<br>+<br>+static void mutex_release(void *data)<br>+{<br>+    vlc_mutex_destroy(data);<br>+}<br>+<br>+vlc_mutex_t *vlc_obj_mutex_new(vlc_object_t *obj)<br>+{<br>+    vlc_mutex_t *mtx = vlc_objres_new(sizeof (*mtx), mutex_release);<br>+    if (mtx != NULL) {<br>+        vlc_mutex_init(mtx);<br>+        vlc_objres_push(obj, mtx);<br>+    }<br>+    return mtx;<br>+}<br>-- <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><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>