[vlc-devel] [RFC] [NOT FOR MERGE] objres: add mutex support

Rémi Denis-Courmont remi at remlab.net
Wed Jan 29 09:13:19 CET 2020


Hi,

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+.

So that is not an issue. We could eliminate vlc_(mutex|cond|sem)_destroy() if we wanted to.

Le 29 janvier 2020 09:46:42 GMT+02:00, Steve Lhomme <robux4 at ycbcr.xyz> a écrit :
>On 2020-01-28 21:30, Rémi Denis-Courmont wrote:
>> This adds a function to allocate a mutex that automatically gets
>> destroyed when a module fails or terminates.
>> 
>> I have very mixed feelings about this, as it introduces an error
>return
>> where there is normally none, i.e., from vlc_mutex_init(). It also
>> requires tedious rework to replace `vlc_mutex_t' with `vlc_mutex_t
>*'.
>> 
>> For reference, kernel code entirely solves this conundrum by not
>> requiring explicit mutex destruction (a kernel mutex does not hold
>any
>> resource besides its own `struct mutex' storage space). This could
>also
>> be done, but with significant reworking of the VLC threading layer
>and
>
>Dunno about other OSes, but on Windows our mutex uses a critical
>section 
>that needs to be released.
>
>> prevents reliable detection of attempt to delete a still-in-use
>mutex.
>> ---
>>   include/vlc_objects.h |  2 ++
>>   src/misc/objres.c     | 15 +++++++++++++++
>>   2 files changed, 17 insertions(+)
>> 
>> diff --git a/include/vlc_objects.h b/include/vlc_objects.h
>> index 19ee5207fc..32f23abf41 100644
>> --- a/include/vlc_objects.h
>> +++ b/include/vlc_objects.h
>> @@ -295,5 +295,7 @@ VLC_API VLC_MALLOC char
>*vlc_obj_strdup(vlc_object_t *obj, const char *str);
>>    */
>>   VLC_API void vlc_obj_free(vlc_object_t *obj, void *ptr);
>>   
>> +VLC_API VLC_MALLOC vlc_mutex_t *vlc_obj_mutex_new(vlc_object_t
>*obj);
>> +
>>   /** @} */
>>   /** @} */
>> diff --git a/src/misc/objres.c b/src/misc/objres.c
>> index cac8624e7e..383dd760a8 100644
>> --- a/src/misc/objres.c
>> +++ b/src/misc/objres.c
>> @@ -174,3 +174,18 @@ void vlc_obj_free(vlc_object_t *obj, void *ptr)
>>   {
>>       vlc_objres_remove(obj, ptr, ptrcmp);
>>   }
>> +
>> +static void mutex_release(void *data)
>> +{
>> +    vlc_mutex_destroy(data);
>> +}
>> +
>> +vlc_mutex_t *vlc_obj_mutex_new(vlc_object_t *obj)
>> +{
>> +    vlc_mutex_t *mtx = vlc_objres_new(sizeof (*mtx), mutex_release);
>> +    if (mtx != NULL) {
>> +        vlc_mutex_init(mtx);
>> +        vlc_objres_push(obj, mtx);
>> +    }
>> +    return mtx;
>> +}
>> -- 
>> 2.25.0
>> 
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>> 
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200129/16d908fb/attachment.html>


More information about the vlc-devel mailing list