[libcxx-commits] [PATCH] D64299: Make ~mutex and ~condition_variable trivial with Bionic pthreads
Eric Fiselier via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jul 7 10:56:06 PDT 2019
EricWF created this revision.
EricWF added a reviewer: danalbert.
Herald added subscribers: jfb, ldionne.
This optimization, as described in PR27658, is safe to perform with Bionic pthreads. The implementation of pthread_mutex_destroy and pthread_cond_destroy do nothing except poison the lock/condvar to aid in debugging [1][2]
If we choose to apply this patch we'll lose some amount of error checking, but I think it's probably worth it given the codegen improvements for global of function local static mutexes.
What do you think?
[1] https://android.googlesource.com/platform/bionic/+/10ce969/libc/bionic/pthread.c#1567
[2] https://android.googlesource.com/platform/bionic/+/10ce969/libc/bionic/pthread.c#1654
Repository:
rCXX libc++
https://reviews.llvm.org/D64299
Files:
include/__config
Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -1100,17 +1100,18 @@
// The Apple, glibc, and Bionic implementation of pthreads implements
// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
// mutexes have no destroy mechanism.
-// TODO(EricWF): Enable this optimization on Apple and Bionic platforms after
+// TODO(EricWF): Enable this optimization on Apple platforms after
// speaking to their respective stakeholders.
-#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \
+#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) \
+ && (defined(__GLIBC__) || defined(__BIONIC__))) \
|| defined(_LIBCPP_HAS_THREAD_API_WIN32)
# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
#endif
-// Destroying a condvar is a nop on Windows.
-// TODO(EricWF): This is potentially true for some pthread implementations
-// as well.
-#if defined(_LIBCPP_HAS_THREAD_API_WIN32)
+// Destroying a condvar is a nop on Windows, as well as with the Bionic
+// implementations of pthreads
+#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__BIONIC__)) \
+ || defined(_LIBCPP_HAS_THREAD_API_WIN32)
# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64299.208299.patch
Type: text/x-patch
Size: 1272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190707/4b4cca33/attachment.bin>
More information about the libcxx-commits
mailing list