[vlc-devel] [PATCH] Make mutexes mutable

Rémi Denis-Courmont remi at remlab.net
Tue Jan 9 12:53:04 CET 2018


On mardi 9 janvier 2018 12:46:12 EET Romain Vimont wrote:
> Le mardi  9 janvier 2018 à 13:41 +0200, Rémi Denis-Courmont a écrit :
> > On lundi 8 janvier 2018 21:45:16 EET Romain Vimont wrote:
> > > Mutexes must be locked and unlocked even in C++ const methods. To avoid
> > > const casts, simply declare them mutable.
> > 
> > If you need to lock, then your method is not const. Conversely, if the
> > object is guaranteed to be identical before and after the method call,
> > then the methiod does not need to lock any mutex.
> > 
> > I don't agree with your line of reasoning, and it seems that the C, POSIX
> > and C++ don't either - otherwise they'd have lock and unlock as immutable
> > methods too.
> 
> <http://en.cppreference.com/w/cpp/language/cv>

I fail to see the relevance.
> 
> > mutable - applies to non-static class members of non-reference
> > non-const type and specifies that the member does not affect the
> > externally visible state of the class (as often used for mutexes, memo
> > caches, lazy evaluation, and access instrumentation).

Yeah and that's exactly why you should put the const qualifier for methods 
that DO NOT NEED to acquire any lock of any kind.

-- 
Rémi Denis-Courmont


More information about the vlc-devel mailing list