[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2017-01-03 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290889: [libcxx] Add build/test support for the externally 
threaded libc++abi variant (authored by asiri).

Changed prior to commit:
  https://reviews.llvm.org/D27576?vs=81059=82869#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27576

Files:
  libcxx/trunk/CMakeLists.txt
  libcxx/trunk/include/__threading_support
  libcxx/trunk/test/CMakeLists.txt
  libcxx/trunk/test/libcxx/test/config.py
  libcxx/trunk/test/lit.site.cfg.in

Index: libcxx/trunk/CMakeLists.txt
===
--- libcxx/trunk/CMakeLists.txt
+++ libcxx/trunk/CMakeLists.txt
@@ -221,14 +221,21 @@
   " when LIBCXX_ENABLE_THREADS is also set to OFF.")
 endif()
 
-if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS)
-  message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
-  " when LIBCXX_ENABLE_THREADS is also set to ON.")
+if(NOT LIBCXX_ENABLE_THREADS)
+  if(LIBCXX_HAS_PTHREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
+  if(LIBCXX_HAS_EXTERNAL_THREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
 endif()
 
-if(LIBCXX_HAS_EXTERNAL_THREAD_API AND NOT LIBCXX_ENABLE_THREADS)
-  message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
-  " when LIBCXX_ENABLE_THREADS is also set to ON.")
+if(LIBCXX_HAS_PTHREAD_API AND LIBCXX_HAS_EXTERNAL_THREAD_API)
+  message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
+  "and LIBCXX_HAS_PTHREAD_API cannot be both"
+  "set to ON at the same time.")
 endif()
 
 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
Index: libcxx/trunk/include/__threading_support
===
--- libcxx/trunk/include/__threading_support
+++ libcxx/trunk/include/__threading_support
@@ -67,7 +67,11 @@
 typedef pthread_cond_t __libcpp_condvar_t;
 #define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
 
-// THread ID
+// Execute once
+typedef pthread_once_t __libcpp_exec_once_flag;
+#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+// Thread id
 typedef pthread_t __libcpp_thread_id;
 
 // Thread
@@ -110,7 +114,17 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
 
-// Thread ID
+// Execute once
+_LIBCPP_THREAD_ABI_VISIBILITY
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void));
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+_LIBCPP_THREAD_ABI_VISIBILITY
+mach_port_t __libcpp_thread_get_port();
+#endif
+
 _LIBCPP_THREAD_ABI_VISIBILITY
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2);
 
@@ -145,7 +159,7 @@
 void *__libcpp_tls_get(__libcpp_tls_key __key);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
-void __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
+int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
 defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
@@ -221,6 +235,19 @@
   return pthread_cond_destroy(__cv);
 }
 
+// Execute once
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+mach_port_t __libcpp_thread_get_port() {
+return pthread_mach_thread_np(pthread_self());
+}
+#endif
+
 // Returns non-zero if the thread ids are equal, otherwise 0
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
 {
@@ -276,9 +303,9 @@
   return pthread_getspecific(__key);
 }
 
-void __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
+int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
 {
-  pthread_setspecific(__key, __p);
+return pthread_setspecific(__key, __p);
 }
 
 #endif // _LIBCPP_HAS_THREAD_API_PTHREAD
Index: libcxx/trunk/test/lit.site.cfg.in
===
--- libcxx/trunk/test/lit.site.cfg.in
+++ libcxx/trunk/test/lit.site.cfg.in
@@ -28,7 +28,7 @@
 config.use_libatomic= "@LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB@"
 
 config.libcxxabi_shared = "@LIBCXXABI_ENABLE_SHARED@"
-config.libcxx_external_thread_api  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
+config.cxx_ext_threads  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
 
 # Let the main config do the real work.
 config.loaded_site_config = True
Index: libcxx/trunk/test/CMakeLists.txt
===
--- libcxx/trunk/test/CMakeLists.txt
+++ 

[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2016-12-23 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: test/CMakeLists.txt:58
 
 if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
+  set(LIBCXX_TEST_DEPS cxx_experimental)

I always prefer `set(LIBCXX_TEST_DEPS "")` to initialize an empty list. Then 
`list(APPEND LIBCXX_TEST_DEPS cxx_experimental)` to add new items.


https://reviews.llvm.org/D27576



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2016-12-19 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Ping.


https://reviews.llvm.org/D27576



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2016-12-15 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath marked an inline comment as done.
rmaprath added a comment.

Gentle ping.


https://reviews.llvm.org/D27576



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2016-12-12 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 81059.

https://reviews.llvm.org/D27576

Files:
  CMakeLists.txt
  include/__threading_support
  test/CMakeLists.txt
  test/libcxx/test/config.py
  test/lit.site.cfg.in

Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -28,7 +28,7 @@
 config.use_libatomic= "@LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB@"
 
 config.libcxxabi_shared = "@LIBCXXABI_ENABLE_SHARED@"
-config.libcxx_external_thread_api  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
+config.cxx_ext_threads  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
 
 # Let the main config do the real work.
 config.loaded_site_config = True
Index: test/libcxx/test/config.py
===
--- test/libcxx/test/config.py
+++ test/libcxx/test/config.py
@@ -576,10 +576,6 @@
 self.cxx.link_flags += [abs_path]
 else:
 self.cxx.link_flags += ['-lc++']
-# This needs to come after -lc++ as we want its unresolved thread-api symbols
-# to be picked up from this one.
-if self.get_lit_bool('libcxx_external_thread_api', default=False):
-self.cxx.link_flags += ['-lc++external_threads']
 
 def configure_link_flags_abi_library(self):
 cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi')
@@ -608,6 +604,8 @@
 'C++ ABI setting %s unsupported for tests' % cxx_abi)
 
 def configure_extra_library_flags(self):
+if self.get_lit_bool('cxx_ext_threads', default=False):
+self.cxx.link_flags += ['-lc++external_threads']
 self.target_info.add_cxx_link_flags(self.cxx.link_flags)
 
 def configure_color_diagnostics(self):
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -56,17 +56,19 @@
   @ONLY)
 
 if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
-  set(experimental_dep cxx_experimental)
+  set(LIBCXX_TEST_DEPS cxx_experimental)
+else()
+  set(LIBCXX_TEST_DEPS "")
 endif()
 
 if (LIBCXX_HAS_EXTERNAL_THREAD_API)
-  set(external_threads_dep cxx_external_threads)
+  list(APPEND LIBCXX_TEST_DEPS cxx_external_threads)
 endif()
 
 add_lit_testsuite(check-cxx
   "Running libcxx tests"
   ${CMAKE_CURRENT_BINARY_DIR}
-  DEPENDS cxx ${experimental_dep} ${external_threads_dep})
+  DEPENDS cxx ${LIBCXX_TEST_DEPS})
 
 add_custom_target(check-libcxx DEPENDS check-cxx)
 
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -71,7 +71,20 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
 
+// Execute once
+typedef pthread_once_t __libcpp_exec_once_flag;
+#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+_LIBCPP_THREAD_ABI_VISIBILITY
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void));
+
 // Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+_LIBCPP_THREAD_ABI_VISIBILITY
+mach_port_t __libcpp_thread_get_port();
+#endif
+
 typedef pthread_t __libcpp_thread_id;
 _LIBCPP_THREAD_ABI_VISIBILITY
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2);
@@ -100,7 +113,7 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 void* __libcpp_tls_get(__libcpp_tls_key __key);
 _LIBCPP_THREAD_ABI_VISIBILITY
-void __libcpp_tls_set(__libcpp_tls_key __key, void* __p);
+int __libcpp_tls_set(__libcpp_tls_key __key, void* __p);
 
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || defined(_LIBCPP_BUILDING_EXTERNAL_THREADS)
 
@@ -176,6 +189,19 @@
 return pthread_cond_destroy(__cv);
 }
 
+// Execute once
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+mach_port_t __libcpp_thread_get_port() {
+return pthread_mach_thread_np(pthread_self());
+}
+#endif
+
 // Returns non-zero if the thread ids are equal, otherwise 0
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
 {
@@ -230,9 +256,9 @@
 return pthread_getspecific(__key);
 }
 
-void __libcpp_tls_set(__libcpp_tls_key __key, void* __p)
+int __libcpp_tls_set(__libcpp_tls_key __key, void* __p)
 {
-pthread_setspecific(__key, __p);
+return pthread_setspecific(__key, __p);
 }
 
 #endif // _LIBCPP_HAS_THREAD_API_PTHREAD || _LIBCPP_BUILDING_EXTERNAL_THREADS
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -211,14 +211,21 @@
   " when LIBCXX_ENABLE_THREADS is also set to OFF.")
 endif()
 
-if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS)
-  message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
-  

[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2016-12-12 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added inline comments.



Comment at: include/__threading_support:193
+// Execute once
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void)) {

EricWF wrote:
> These should have `inline`. In fact all of the functions in this header must 
> be declared inline but have not been.
Actually, all the declarations on this header have 
`_LIBCPP_THREAD_ABI_VISIBILITY` , which includes the `inline` modifier. I've 
forgotten to include any context with this patch though, that might've made it 
bit unclear.


https://reviews.llvm.org/D27576



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2016-12-11 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

This bit LGTM.




Comment at: include/__threading_support:193
+// Execute once
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void)) {

These should have `inline`. In fact all of the functions in this header must be 
declared inline but have not been.



Comment at: test/libcxx/test/config.py:605
+if self.get_lit_bool('cxx_ext_threads', default=False):
+self.cxx.link_flags += ['-lcxx_external_threads']
 self.target_info.add_cxx_link_flags(self.cxx.link_flags)

I would rather use `libc++external_threads` since it uses the same prefix as 
`-lc++` and `-lc++experimental`


https://reviews.llvm.org/D27576



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2016-12-08 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: EricWF, mclow.lists.
rmaprath added a subscriber: cfe-commits.
Herald added a subscriber: mgorny.

This patch adds support for https://reviews.llvm.org/D27575. A couple of new 
threading API calls has been introduced (libc++abi requires these).

I've also done a few minor cleanups/renames here.


https://reviews.llvm.org/D27576

Files:
  CMakeLists.txt
  include/__threading_support
  lib/CMakeLists.txt
  test/CMakeLists.txt
  test/libcxx/test/config.py
  test/lit.site.cfg.in

Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -28,7 +28,7 @@
 config.use_libatomic= "@LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB@"
 
 config.libcxxabi_shared = "@LIBCXXABI_ENABLE_SHARED@"
-config.libcxx_external_thread_api  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
+config.cxx_ext_threads  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
 
 # Let the main config do the real work.
 config.loaded_site_config = True
Index: test/libcxx/test/config.py
===
--- test/libcxx/test/config.py
+++ test/libcxx/test/config.py
@@ -573,10 +573,6 @@
 self.cxx.link_flags += [abs_path]
 else:
 self.cxx.link_flags += ['-lc++']
-# This needs to come after -lc++ as we want its unresolved thread-api symbols
-# to be picked up from this one.
-if self.get_lit_bool('libcxx_external_thread_api', default=False):
-self.cxx.link_flags += ['-lc++external_threads']
 
 def configure_link_flags_abi_library(self):
 cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi')
@@ -605,6 +601,8 @@
 'C++ ABI setting %s unsupported for tests' % cxx_abi)
 
 def configure_extra_library_flags(self):
+if self.get_lit_bool('cxx_ext_threads', default=False):
+self.cxx.link_flags += ['-lcxx_external_threads']
 self.target_info.add_cxx_link_flags(self.cxx.link_flags)
 
 def configure_color_diagnostics(self):
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -56,17 +56,19 @@
   @ONLY)
 
 if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
-  set(experimental_dep cxx_experimental)
+  set(LIBCXX_TEST_DEPS cxx_experimental)
+else()
+  set(LIBCXX_TEST_DEPS "")
 endif()
 
 if (LIBCXX_HAS_EXTERNAL_THREAD_API)
-  set(external_threads_dep cxx_external_threads)
+  list(APPEND LIBCXX_TEST_DEPS cxx_external_threads)
 endif()
 
 add_lit_testsuite(check-cxx
   "Running libcxx tests"
   ${CMAKE_CURRENT_BINARY_DIR}
-  DEPENDS cxx ${experimental_dep} ${external_threads_dep})
+  DEPENDS cxx ${LIBCXX_TEST_DEPS})
 
 add_custom_target(check-libcxx DEPENDS check-cxx)
 
Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -257,7 +257,7 @@
 PROPERTIES
   LINK_FLAGS"${LIBCXX_LINK_FLAGS}"
   COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
-  OUTPUT_NAME   "c++external_threads"
+  OUTPUT_NAME   "cxx_external_threads"
   )
 endif()
 
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -71,7 +71,20 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
 
+// Execute once
+typedef pthread_once_t __libcpp_exec_once_flag;
+#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+_LIBCPP_THREAD_ABI_VISIBILITY
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void));
+
 // Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+_LIBCPP_THREAD_ABI_VISIBILITY
+mach_port_t __libcpp_thread_get_port();
+#endif
+
 typedef pthread_t __libcpp_thread_id;
 _LIBCPP_THREAD_ABI_VISIBILITY
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2);
@@ -100,7 +113,7 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 void* __libcpp_tls_get(__libcpp_tls_key __key);
 _LIBCPP_THREAD_ABI_VISIBILITY
-void __libcpp_tls_set(__libcpp_tls_key __key, void* __p);
+int __libcpp_tls_set(__libcpp_tls_key __key, void* __p);
 
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || defined(_LIBCPP_BUILDING_EXTERNAL_THREADS)
 
@@ -176,6 +189,19 @@
 return pthread_cond_destroy(__cv);
 }
 
+// Execute once
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+mach_port_t __libcpp_thread_get_port() {
+return pthread_mach_thread_np(pthread_self());
+}
+#endif
+
 // Returns non-zero if the thread ids are equal, otherwise 0
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
 {
@@ -230,9 +256,9 @@
 return