Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] v2/shared_mutex bitmask refactoring
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-03-26 02:16:05


Le 26/03/13 05:57, Vicente J. Botet Escriba a écrit :
> Le 25/03/13 13:53, Fredrik Orderud a écrit :
>> The "bitmask" manipulation in v2/shared_mutex and v2/upgrade_mutex
>> makes the code difficult to understand. The attached patch attempts
>> to replace the bitmasks with more manageable "bitfields". This leads
>> to shorter and more readable code with equivalent performance.
>>
>> All "thread" tests still pass on my Win7/x64 computer with
>> v2/shared_mutex.hpp manually included from thread/shared_mutex.hpp.
>>
>> If the patch is appreciated, then I can also send a similar patch for
>> v2/upgrade_mutex.
>>
> Hi,
>
> I appreciate your efforts going to a more understandable code. I don't
> know why HH has written the code like that, but usually he has good
> reasons.
>
I guess that I have the answer why HH wrote the code like this.
Portability, if unsigned is 64 bits, your bitfield patch can not take
advantage of it as you need to give the number of bits

+ n_readers_ : 31;

Or can you?

> In order to ensure the same performance, what about a patch using
> getters/setters instead of the direct use of the bitfields, and define
> these functions either using the current code either using the
> bitfields so that we can have both and compare easily.
>
Anyway, forget the patch I will do it myself using inline functions.

Best,
Vicente


Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk