RFR (L, tedious) 8222811: Consolidate MutexLockerEx and MutexLocker

Kim Barrett kim.barrett at oracle.com
Thu May 2 17:02:15 UTC 2019


> On Apr 24, 2019, at 8:14 AM, David Holmes <david.holmes at oracle.com> wrote:
> 
> On 24/04/2019 9:23 pm, coleen.phillimore at oracle.com wrote:
>> On 4/23/19 9:48 PM, David Holmes wrote:
>>> I couldn't easily see how often you used this new constructor, but avoiding an unnecessary call to Thread::current() is good. However the duplicated code in the two constructors is not good and they differ only in the "thread" argument use. I don't know how C++ does constructor chaining but the no-thread version should just call the thread-taking version passing Thread::current() - or fact the body into a helper. Can I also request that the "thread" parameter be renamed "currentThread" (we're far too lax when it comes to clearly identifying when a Thread* must be the current thread) - thanks.
>> I tried to do this but calling Thread::current() in the constructor and having a common initialize function, required including thread.hpp into mutex.hpp which then make it circular.   In the end the duplicated code was preferrable to any tricks I could find.
> 
> That's a shame. If Kim were around he might be able to suggest a trick :)

What you are looking for here is constructor delegation, a C++11 feature.




More information about the hotspot-dev mailing list