This is an archive of the discontinued LLVM Phabricator instance.

Implement variadic lock_guard.
ClosedPublic

Authored by EricWF on Jun 11 2016, 1:54 PM.

Details

Summary

This patch implements the variadic lock_guard paper.

Making lock_guard variadic is a ABI breaking change because the specialization lock_guard<_Mutex> mangles differently then when it was the primary template. This change only provides variadic lock_guard in ABI V2 or when _LIBCPP_ABI_VARIADIC_LOCK_GUARD is defined.

Note that in ABI V2 lock_guard must always be declared as a variadic template, even in C++03, in order to keep the ABI consistent. For this reason lock_guard is forward declared as a variadic template in all standard dialects and therefore depends on variadic templates being provided as an extension in C++03. All supported versions of Clang and GCC provide this extension.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 60444.Jun 11 2016, 1:54 PM
EricWF retitled this revision from to Implement variadic lock_guard..
EricWF updated this object.
EricWF added a reviewer: mclow.lists.
EricWF added subscribers: cfe-commits, mclow.lists.
EricWF updated this revision to Diff 60602.Jun 13 2016, 2:08 PM
EricWF updated this object.

Address K-ballo's comments:

  • Remove mutex_type typedef when sizeof...(MutexTypes) > 1.
  • Move the variadic lock_guard implementation into <mutex> instead of <__mutex_base>. This prevents a lot of code reshuffling.
  • Fix accidental explicit on deleted copy constructor.
  • Mark non-variadic lock_guard copy ctor and assignment as deleted using _LIBCPP_EQUAL_DELETE.
  • Fix mismatched struct and class tags.
EricWF updated this revision to Diff 60605.Jun 13 2016, 2:15 PM

Add a variadic lock_guard test that compiles in C++03. This tests the C++11 behavior of lock_guard but using the new implementation.

EricWF updated this revision to Diff 60609.Jun 13 2016, 2:20 PM
  • Add missing _LIBCPP_ABI_VARIADIC_LOCK_GUARD macro in __config.
  • Update cxx1z_status.html.
mclow.lists edited edge metadata.Jun 13 2016, 2:51 PM

You should only get the multi-mutex version in C++17.

include/mutex
579

You need to update the synopsis at the top of the file.

EricWF updated this revision to Diff 60619.Jun 13 2016, 3:12 PM
EricWF edited edge metadata.

Address review comments:

  • Update synopsis it <mutex>
  • Add missing // UNSUPPORTED: libcpp-has-no-threads in tests.
EricWF marked an inline comment as done.Jun 13 2016, 3:22 PM
EricWF added inline comments.
include/mutex
579–640

Done, but you might want to check that change. I tried to do it so that it's clear that the variadic lock_guard is only available in ABI V2.

EricWF updated this revision to Diff 60646.Jun 13 2016, 8:41 PM
EricWF marked an inline comment as done.

Add a __unlock helper function.

EricWF updated this revision to Diff 60647.Jun 13 2016, 8:46 PM

Use primary template lock_guard<_MArgs...> for the variadic implementation instead of specialization lock_guard<_M1, _M2, _MRest...>.

mclow.lists accepted this revision.Jun 13 2016, 8:49 PM
mclow.lists edited edge metadata.

LGTM. Thanks.

This revision is now accepted and ready to land.Jun 13 2016, 8:49 PM
EricWF closed this revision.Jun 13 2016, 8:54 PM