This is an archive of the discontinued LLVM Phabricator instance.

Implement Pp0156r2 "Variadic Lock Guard, version 5"
ClosedPublic

Authored by mclow.lists on Mar 20 2017, 7:10 PM.

Details

Reviewers
EricWF
Summary

WG21 has decided that the ABI-breaking lock_guard proposal that we (@EricWF) implemented (and hid behind an ABI-break macro) is not the way to go. Instead, we're introducing a new class, scoped_lock, which is variadic, and leaving lock_guard as non-variadic.

So, delete Eric's work, nuke the ABI macro, and implement the non-ABI breaking stuff.

While I'm in the neighborhood, implement the mutex-ey parts of P0433: "Deduction guides for the standard library". This bit has the guides for lock_guard, scoped_lock, unique_lock, and shared_lock.

Note: If you're using the variadic version of lock_guard, then this is a breaking change. Good news is that you just switch to using scoped_lock, and everything works the same.

Diff Detail

Event Timeline

mclow.lists created this revision.Mar 20 2017, 7:10 PM
EricWF edited edge metadata.Mar 22 2017, 3:07 PM

So Clang only very recently added support for deduction guides. We'll need to add _LIBCPP_HAS_NO_DEDUCTION_GUIDES and use it to guard the declarations and the tests.

Also I think the explicit deduction guides are incorrect and unneeded. The deduction guides you declare are template <class Mutex> unique_lock(unique_lock<Mutex>) -> unique_lock<Mutex> but no such constructor exists. I suspect the intent was to support deduction for the unique_lock(mutex_type) constructor but that already works implicitly.

include/mutex
176

This should be guarded behind a feature test macro. I would suggest adding this to __config.

#if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611
# define _LIBCPP_HAS_NO_DEDUCTION_GUIDES
#endif
705

This should be guarded as well.

test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp
99

The tests for deduction guides should static_assert(std::is_same_v<decltype(sl), Expected>);.

test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex.pass.cpp
57

The tests for deduction guides should static_assert(std::is_same_v<decltype(sl), Expected>);.

mclow.lists added inline comments.Mar 22 2017, 4:29 PM
include/mutex
176

That sounds right to me.

177

And what's with the 'M'? (here and below)

test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp
99

Agreed.

EricWF added inline comments.Mar 22 2017, 5:33 PM
include/mutex
177

No idea, but I would remove the explicit deduction guides from this patch. They are not correct and are unneeded.

Removed the deduction guides. Guarded the tests for the deduction guides with #ifdefs.

mclow.lists marked 8 inline comments as done.Mar 23 2017, 8:44 PM
mclow.lists added inline comments.
include/mutex
176

Actually, this is in the synopsis; so no guard needed.

EricWF accepted this revision.Mar 23 2017, 8:45 PM

LGTM. I'll send something to the reflectors about the explicit deduction guides over the weekend.

This revision is now accepted and ready to land.Mar 23 2017, 8:45 PM
mclow.lists closed this revision.Mar 23 2017, 11:00 PM
mclow.lists marked an inline comment as done.

Committed as revision 298681.

test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex.pass.cpp