[PATCH] D23796: [libcxx] Make it possible to test static builds of libc++ on OSX

2017-04-24 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath abandoned this revision.
rmaprath added a comment.

Looks like I'm the only one interested in this - abandoning.


https://reviews.llvm.org/D23796



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


[PATCH] D29818: [libcxx] Threading support: Attempt to externalize system_clock::now() and steady_clock::now() implementations

2017-04-12 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Hi @EricWF

Apologies for the delay in replying to this.

In https://reviews.llvm.org/D29818#711795, @EricWF wrote:

> I really dislike that `__libcpp_clock_monotonic` and 
> `__libcpp_clock_realtime` are never declared, and are expected to be 
> magically defined by the external threading header.
>  This makes the configuration seem incorrect and unused.


This I can address by conditionally declaring these functions in the 
`__threading_support` header. But I think the the following assessment is not 
right:

> Also the previous threading support changes were beneficial to libc++ because 
> they cleaned up and centralized the threading interface, making it easier to 
> port libc++ to different
>  threading environments. This change has no such benefit.
> 
> Why should libc++ upstream this ARM specific configuration need?

Currently `chrono.cpp` depends on more than what a standard C library provides 
(`clock_gettime()` is specific to Unix, it is not part of the C standard), so 
this is about general portability of `libc++` and not ARM specific.

Anyone porting `libc++` into a bare-metal (or RTOS) environment will have to 
deal with this, so it would make sense to provide an external API for this? Of 
course, the approach proposed in this patch might not be the only way (or the 
best way) to do it.

WDYT?

/ Asiri


https://reviews.llvm.org/D29818



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


[PATCH] D31178: [libcxxabi] Fix exception address alignment test for EHABI

2017-04-04 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 94074.
rmaprath added a comment.
Herald added a subscriber: mgorny.

Addressed review comments from @EricWF .


https://reviews.llvm.org/D31178

Files:
  CMakeLists.txt
  test/libcxxabi/test/config.py
  test/lit.site.cfg.in
  test/test_exception_address_alignment.pass.cpp


Index: test/test_exception_address_alignment.pass.cpp
===
--- test/test_exception_address_alignment.pass.cpp
+++ test/test_exception_address_alignment.pass.cpp
@@ -15,8 +15,8 @@
 // working around this failure.
 // XFAIL: darwin && libcxxabi-has-system-unwinder
 
-// Test that the address of the exception object is properly aligned to the
-// largest supported alignment for the system.
+// Test that the address of the exception object is properly aligned as 
required
+// by the relevant ABI
 
 #include 
 #include 
@@ -24,7 +24,16 @@
 #include 
 
 struct __attribute__((aligned)) AlignedType {};
-static_assert(alignof(AlignedType) == alignof(_Unwind_Exception),
+
+// EHABI  : 8-byte aligned
+// Itanium: Largest supported alignment for the system
+#if defined(_LIBUNWIND_ARM_EHABI)
+#  define EXPECTED_ALIGNMENT 8
+#else
+#  define EXPECTED_ALIGNMENT alignof(AlignedType)
+#endif
+
+static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT,
   "_Unwind_Exception is incorrectly aligned. This test is expected to fail");
 
 struct MinAligned {  };
@@ -35,7 +44,7 @@
 try {
   throw MinAligned{};
 } catch (MinAligned const& ref) {
-  assert(reinterpret_cast() % alignof(AlignedType) == 0);
+  assert(reinterpret_cast() % EXPECTED_ALIGNMENT == 0);
 }
   }
 }
Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -6,6 +6,7 @@
 config.abi_library_path = "@LIBCXXABI_LIBRARY_DIR@"
 config.libcxx_src_root  = "@LIBCXXABI_LIBCXX_PATH@"
 config.cxx_headers  = "@LIBCXXABI_LIBCXX_INCLUDES@"
+config.libunwind_headers= "@LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL@"
 config.cxx_library_root = "@LIBCXXABI_LIBCXX_LIBRARY_PATH@"
 config.llvm_unwinder= "@LIBCXXABI_USE_LLVM_UNWINDER@"
 config.enable_threads   = "@LIBCXXABI_ENABLE_THREADS@"
Index: test/libcxxabi/test/config.py
===
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -84,6 +84,13 @@
   % libcxxabi_headers)
 self.cxx.compile_flags += ['-I' + libcxxabi_headers]
 
+libunwind_headers = self.get_lit_conf('libunwind_headers', None)
+if self.get_lit_bool('llvm_unwinder', False) and libunwind_headers:
+if not os.path.isdir(libunwind_headers):
+self.lit_config.fatal("libunwind_headers='%s' is not a 
directory."
+  % libunwind_headers)
+self.cxx.compile_flags += ['-I' + libunwind_headers]
+
 def configure_compile_flags_exceptions(self):
 pass
 
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -502,9 +502,14 @@
 set(LIBCXXABI_LIBUNWIND_SOURCES "")
   endif()
 
-  if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL 
"LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
+  if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL 
"LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
+set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
+  endif()
+
+  if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
 include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
   endif()
+
   if (NOT LIBCXXABI_LIBUNWIND_SOURCES STREQUAL "")
 include_directories("${LIBCXXABI_LIBUNWIND_SOURCES}")
   endif()


Index: test/test_exception_address_alignment.pass.cpp
===
--- test/test_exception_address_alignment.pass.cpp
+++ test/test_exception_address_alignment.pass.cpp
@@ -15,8 +15,8 @@
 // working around this failure.
 // XFAIL: darwin && libcxxabi-has-system-unwinder
 
-// Test that the address of the exception object is properly aligned to the
-// largest supported alignment for the system.
+// Test that the address of the exception object is properly aligned as required
+// by the relevant ABI
 
 #include 
 #include 
@@ -24,7 +24,16 @@
 #include 
 
 struct __attribute__((aligned)) AlignedType {};
-static_assert(alignof(AlignedType) == alignof(_Unwind_Exception),
+
+// EHABI  : 8-byte aligned
+// Itanium: Largest supported alignment for the system
+#if defined(_LIBUNWIND_ARM_EHABI)
+#  define EXPECTED_ALIGNMENT 8
+#else
+#  define EXPECTED_ALIGNMENT alignof(AlignedType)
+#endif
+
+static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT,
   "_Unwind_Exception is incorrectly aligned. This test is expected to fail");
 
 struct MinAligned {  };
@@ -35,7 +44,7 @@
 try {
   

[PATCH] D31178: [libcxxabi] Fix exception address alignment test for EHABI

2017-03-21 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 92450.
rmaprath added a comment.

Fixed a few paths.


https://reviews.llvm.org/D31178

Files:
  test/libcxxabi/test/config.py
  test/lit.site.cfg.in
  test/test_exception_address_alignment.pass.cpp


Index: test/test_exception_address_alignment.pass.cpp
===
--- test/test_exception_address_alignment.pass.cpp
+++ test/test_exception_address_alignment.pass.cpp
@@ -15,16 +15,25 @@
 // working around this failure.
 // XFAIL: darwin && libcxxabi-has-system-unwinder
 
-// Test that the address of the exception object is properly aligned to the
-// largest supported alignment for the system.
+// Test that the address of the exception object is properly aligned as 
required
+// by the relevant ABI
 
 #include 
 #include 
 
 #include 
 
 struct __attribute__((aligned)) AlignedType {};
-static_assert(alignof(AlignedType) == alignof(_Unwind_Exception),
+
+// EHABI  : 8-byte aligned
+// Itanium: Largest supported alignment for the system
+#if _LIBUNWIND_ARM_EHABI
+#  define EXPECTED_ALIGNMENT 8
+#else
+#  define EXPECTED_ALIGNMENT alignof(AlignedType)
+#endif
+
+static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT,
   "_Unwind_Exception is incorrectly aligned. This test is expected to fail");
 
 struct MinAligned {  };
@@ -35,7 +44,7 @@
 try {
   throw MinAligned{};
 } catch (MinAligned const& ref) {
-  assert(reinterpret_cast() % alignof(AlignedType) == 0);
+  assert(reinterpret_cast() % EXPECTED_ALIGNMENT == 0);
 }
   }
 }
Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -6,6 +6,8 @@
 config.abi_library_path = "@LIBCXXABI_LIBRARY_DIR@"
 config.libcxx_src_root  = "@LIBCXXABI_LIBCXX_PATH@"
 config.cxx_headers  = "@LIBCXXABI_LIBCXX_INCLUDES@"
+config.libunwind_src= "@LIBCXXABI_LIBUNWIND_SOURCES@"
+config.libunwind_headers= "@LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL@"
 config.cxx_library_root = "@LIBCXXABI_LIBCXX_LIBRARY_PATH@"
 config.llvm_unwinder= "@LIBCXXABI_USE_LLVM_UNWINDER@"
 config.enable_threads   = "@LIBCXXABI_ENABLE_THREADS@"
Index: test/libcxxabi/test/config.py
===
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -20,14 +20,18 @@
 self.libcxxabi_obj_root = None
 self.abi_library_path = None
 self.libcxx_src_root = None
+self.libunwind_src = None
 
 def configure_src_root(self):
 self.libcxxabi_src_root = self.get_lit_conf(
 'libcxxabi_src_root',
 os.path.dirname(self.config.test_source_root))
 self.libcxx_src_root = self.get_lit_conf(
 'libcxx_src_root',
 os.path.join(self.libcxxabi_src_root, '/../libcxx'))
+self.libunwind_src = self.get_lit_conf(
+'libunwind_src',
+os.path.join(self.libcxxabi_src_root, '/../libunwind/src'))
 
 def configure_obj_root(self):
 self.libcxxabi_obj_root = self.get_lit_conf('libcxxabi_obj_root')
@@ -84,6 +88,15 @@
   % libcxxabi_headers)
 self.cxx.compile_flags += ['-I' + libcxxabi_headers]
 
+libunwind_headers = self.get_lit_conf(
+   'libunwind_headers',
+   os.path.join(self.libunwind_src, '/../include'))
+if self.get_lit_bool('llvm_unwinder', False):
+if not os.path.isdir(libunwind_headers):
+self.lit_config.fatal("libunwind_headers='%s' is not a 
directory."
+  % libunwind_headers)
+self.cxx.compile_flags += ['-I' + libunwind_headers]
+
 def configure_compile_flags_exceptions(self):
 pass
 


Index: test/test_exception_address_alignment.pass.cpp
===
--- test/test_exception_address_alignment.pass.cpp
+++ test/test_exception_address_alignment.pass.cpp
@@ -15,16 +15,25 @@
 // working around this failure.
 // XFAIL: darwin && libcxxabi-has-system-unwinder
 
-// Test that the address of the exception object is properly aligned to the
-// largest supported alignment for the system.
+// Test that the address of the exception object is properly aligned as required
+// by the relevant ABI
 
 #include 
 #include 
 
 #include 
 
 struct __attribute__((aligned)) AlignedType {};
-static_assert(alignof(AlignedType) == alignof(_Unwind_Exception),
+
+// EHABI  : 8-byte aligned
+// Itanium: Largest supported alignment for the system
+#if _LIBUNWIND_ARM_EHABI
+#  define EXPECTED_ALIGNMENT 8
+#else
+#  define EXPECTED_ALIGNMENT alignof(AlignedType)
+#endif
+
+static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT,
   "_Unwind_Exception is incorrectly aligned. This test is expected to fail");
 
 struct MinAligned {  };
@@ -35,7 +44,7 @@
 

[PATCH] D31178: [libcxxabi] Fix exception address alignment test for EHABI

2017-03-21 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.
Herald added a subscriber: aemerson.

This test was failing on our downstream (bare-metal) runs and only now I got 
around to investigate it.

The problem is, this test assumes the Itanium ABI, whereas EHABI requires the 
exception address to be 8-byte aligned.

I was a bit puzzled at first because this should've failed on the public 
arm-linux builder too. I think the reason it passes there is because we don't 
include libunwind headers in the include path when running the libcxxabi tests, 
so the system `unwind.h` gets picked up.


https://reviews.llvm.org/D31178

Files:
  test/libcxxabi/test/config.py
  test/lit.site.cfg.in
  test/test_exception_address_alignment.pass.cpp


Index: test/test_exception_address_alignment.pass.cpp
===
--- test/test_exception_address_alignment.pass.cpp
+++ test/test_exception_address_alignment.pass.cpp
@@ -15,16 +15,25 @@
 // working around this failure.
 // XFAIL: darwin && libcxxabi-has-system-unwinder
 
-// Test that the address of the exception object is properly aligned to the
-// largest supported alignment for the system.
+// Test that the address of the exception object is properly aligned as 
required
+// by the relevant ABI
 
 #include 
 #include 
 
 #include 
 
 struct __attribute__((aligned)) AlignedType {};
-static_assert(alignof(AlignedType) == alignof(_Unwind_Exception),
+
+// EHABI  : 8-byte aligned
+// Itanium: Largest supported alignment for the system
+#if _LIBUNWIND_ARM_EHABI
+#  define EXPECTED_ALIGNMENT 8
+#else
+#  define EXPECTED_ALIGNMENT alignof(AlignedType)
+#endif
+
+static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT,
   "_Unwind_Exception is incorrectly aligned. This test is expected to fail");
 
 struct MinAligned {  };
@@ -35,7 +44,7 @@
 try {
   throw MinAligned{};
 } catch (MinAligned const& ref) {
-  assert(reinterpret_cast() % alignof(AlignedType) == 0);
+  assert(reinterpret_cast() % EXPECTED_ALIGNMENT == 0);
 }
   }
 }
Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -6,6 +6,8 @@
 config.abi_library_path = "@LIBCXXABI_LIBRARY_DIR@"
 config.libcxx_src_root  = "@LIBCXXABI_LIBCXX_PATH@"
 config.cxx_headers  = "@LIBCXXABI_LIBCXX_INCLUDES@"
+config.libunwind_src= "@LIBCXXABI_LIBUNWIND_SOURCES@"
+config.libunwind_headers= "@LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL@"
 config.cxx_library_root = "@LIBCXXABI_LIBCXX_LIBRARY_PATH@"
 config.llvm_unwinder= "@LIBCXXABI_USE_LLVM_UNWINDER@"
 config.enable_threads   = "@LIBCXXABI_ENABLE_THREADS@"
Index: test/libcxxabi/test/config.py
===
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -20,14 +20,18 @@
 self.libcxxabi_obj_root = None
 self.abi_library_path = None
 self.libcxx_src_root = None
+self.libunwind_src_root = None
 
 def configure_src_root(self):
 self.libcxxabi_src_root = self.get_lit_conf(
 'libcxxabi_src_root',
 os.path.dirname(self.config.test_source_root))
 self.libcxx_src_root = self.get_lit_conf(
 'libcxx_src_root',
 os.path.join(self.libcxxabi_src_root, '/../libcxx'))
+self.libunwind_src_root = self.get_lit_conf(
+'libunwind_src_root',
+os.path.join(self.libcxxabi_src_root, '/../libunwind'))
 
 def configure_obj_root(self):
 self.libcxxabi_obj_root = self.get_lit_conf('libcxxabi_obj_root')
@@ -84,6 +88,15 @@
   % libcxxabi_headers)
 self.cxx.compile_flags += ['-I' + libcxxabi_headers]
 
+libunwind_headers = self.get_lit_conf(
+   'libunwind_headers',
+   os.path.join(self.libunwind_src_root, 'include'))
+if self.get_lit_bool('llvm_unwinder', False):
+if not os.path.isdir(libunwind_headers):
+self.lit_config.fatal("libunwind_headers='%s' is not a 
directory."
+  % libunwind_headers)
+self.cxx.compile_flags += ['-I' + libunwind_headers]
+
 def configure_compile_flags_exceptions(self):
 pass
 


Index: test/test_exception_address_alignment.pass.cpp
===
--- test/test_exception_address_alignment.pass.cpp
+++ test/test_exception_address_alignment.pass.cpp
@@ -15,16 +15,25 @@
 // working around this failure.
 // XFAIL: darwin && libcxxabi-has-system-unwinder
 
-// Test that the address of the exception object is properly aligned to the
-// largest supported alignment for the system.
+// Test that the address of the exception object is properly aligned as required
+// by the relevant ABI
 
 #include 
 #include 
 
 #include 
 
 struct 

[PATCH] D29757: [libcxx] Threading support: Externalize hardware_concurrency()

2017-03-14 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

@EricWF: Ping?


https://reviews.llvm.org/D29757



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


[PATCH] D29818: [libcxx] Threading support: Attempt to externalize system_clock::now() and steady_clock::now() implementations

2017-03-14 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

@EricWF: Ping?


https://reviews.llvm.org/D29818



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


[PATCH] D30516: [libc++] Add option to disable new/delete overloads when libc++abi provides them.

2017-03-02 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Thanks for these patches!

We had some downstream hacks to workaround this, never got around to sort it 
out. Now it looks much better.


https://reviews.llvm.org/D30516



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


[PATCH] D30459: [libcxxabi] Clean up macro usage

2017-03-01 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D30459#689461, @rs wrote:

> Thanks for reviewing. Before I commit could you tell me if I need to update 
> any build systems e.g. buildbots ?


Those two options are not used by any of the current public builders, so I 
think it's safe to commit.

If something breaks, we can revert and have a look :)


https://reviews.llvm.org/D30459



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


[PATCH] D29818: [libcxx] Threading support: Attempt to externalize system_clock::now() and steady_clock::now() implementations

2017-02-28 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 90025.
rmaprath added a comment.

Fixed minor omission.


https://reviews.llvm.org/D29818

Files:
  src/chrono.cpp


Index: src/chrono.cpp
===
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -11,6 +11,7 @@
 #include "cerrno"// errno
 #include "system_error"  // __throw_system_error
 #include // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
+#include "__threading_support"
 
 #if (__APPLE__)
 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
@@ -50,7 +51,8 @@
 #if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
 #if __APPLE__
 #include   // mach_absolute_time, mach_timebase_info_data_t
-#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
+#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC) && \
+  !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #error "Monotonic clock not implemented"
 #endif
 #endif
@@ -67,7 +69,12 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
-#if defined(_LIBCPP_WIN32API)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+struct timespec tp;
+if (0 != __libcpp_clock_realtime())
+__throw_system_error(errno, "__libcpp_clock_realtime() failed");
+return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
+#elif defined(_LIBCPP_WIN32API)
   // FILETIME is in 100ns units
   using filetime_duration =
   _VSTD::chrono::duration<__int64,
@@ -91,8 +98,8 @@
   filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
static_cast<__int64>(ft.dwLowDateTime)};
   return time_point(duration_cast(d - nt_to_unix_epoch));
-#else
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
+
+#elif defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
 struct timespec tp;
 if (0 != clock_gettime(CLOCK_REALTIME, ))
 __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
@@ -102,7 +109,6 @@
 gettimeofday(, 0);
 return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
 #endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME
-#endif
 }
 
 time_t
@@ -126,7 +132,18 @@
 
 const bool steady_clock::is_steady;
 
-#if defined(__APPLE__)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+
+steady_clock::time_point
+steady_clock::now() _NOEXCEPT
+{
+struct timespec tp;
+if (0 != __libcpp_clock_monotonic())
+__throw_system_error(errno, "__libcpp_clock_monotonic() failed");
+return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+}
+
+#elif defined(__APPLE__)
 
 // Darwin libc versions >= 1133 provide ns precision via CLOCK_UPTIME_RAW
 #if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)


Index: src/chrono.cpp
===
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -11,6 +11,7 @@
 #include "cerrno"// errno
 #include "system_error"  // __throw_system_error
 #include // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
+#include "__threading_support"
 
 #if (__APPLE__)
 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
@@ -50,7 +51,8 @@
 #if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
 #if __APPLE__
 #include   // mach_absolute_time, mach_timebase_info_data_t
-#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
+#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC) && \
+  !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #error "Monotonic clock not implemented"
 #endif
 #endif
@@ -67,7 +69,12 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
-#if defined(_LIBCPP_WIN32API)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+struct timespec tp;
+if (0 != __libcpp_clock_realtime())
+__throw_system_error(errno, "__libcpp_clock_realtime() failed");
+return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
+#elif defined(_LIBCPP_WIN32API)
   // FILETIME is in 100ns units
   using filetime_duration =
   _VSTD::chrono::duration<__int64,
@@ -91,8 +98,8 @@
   filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
static_cast<__int64>(ft.dwLowDateTime)};
   return time_point(duration_cast(d - nt_to_unix_epoch));
-#else
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
+
+#elif defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
 struct timespec tp;
 if (0 != clock_gettime(CLOCK_REALTIME, ))
 __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
@@ -102,7 +109,6 @@
 gettimeofday(, 0);
 return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
 #endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME
-#endif
 }
 
 time_t
@@ -126,7 +132,18 @@
 
 const bool steady_clock::is_steady;
 
-#if defined(__APPLE__)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+
+steady_clock::time_point
+steady_clock::now() _NOEXCEPT
+{
+struct timespec tp;
+if (0 != 

[PATCH] D30339: [libcxxabi] Disable calls to fprintf when building for baremetal targets in release mode

2017-02-24 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Perhaps change `config.h` and remove the definition there and adjust other 
places accordingly?

The current form is very easy to trip over.


Repository:
  rL LLVM

https://reviews.llvm.org/D30339



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


[PATCH] D29818: [libcxx] Threading support: Attempt to externalize system_clock::now() and steady_clock::now() implementations

2017-02-24 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 89665.
rmaprath added a comment.

Different approach: Externalize these functions only for the 
external-thread-api library variant.

(Similar to https://reviews.llvm.org/D29757)


https://reviews.llvm.org/D29818

Files:
  src/chrono.cpp


Index: src/chrono.cpp
===
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -12,6 +12,8 @@
 #include "system_error"  // __throw_system_error
 #include // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
 
+#include "__threading_support"
+
 #if (__APPLE__)
 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
@@ -67,7 +69,12 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
-#if defined(_LIBCPP_WIN32API)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+struct timespec tp;
+if (0 != __libcpp_clock_realtime())
+__throw_system_error(errno, "__libcpp_clock_realtime() failed");
+return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
+#elif defined(_LIBCPP_WIN32API)
   // FILETIME is in 100ns units
   using filetime_duration =
   _VSTD::chrono::duration<__int64,
@@ -91,8 +98,8 @@
   filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
static_cast<__int64>(ft.dwLowDateTime)};
   return time_point(duration_cast(d - nt_to_unix_epoch));
-#else
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
+
+#elif defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
 struct timespec tp;
 if (0 != clock_gettime(CLOCK_REALTIME, ))
 __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
@@ -102,7 +109,6 @@
 gettimeofday(, 0);
 return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
 #endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME
-#endif
 }
 
 time_t
@@ -126,7 +132,18 @@
 
 const bool steady_clock::is_steady;
 
-#if defined(__APPLE__)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+
+steady_clock::time_point
+steady_clock::now() _NOEXCEPT
+{
+struct timespec tp;
+if (0 != __libcpp_clock_monotonic())
+__throw_system_error(errno, "__libcpp_clock_monotonic() failed");
+return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+}
+
+#elif defined(__APPLE__)
 
 // Darwin libc versions >= 1133 provide ns precision via CLOCK_UPTIME_RAW
 #if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)


Index: src/chrono.cpp
===
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -12,6 +12,8 @@
 #include "system_error"  // __throw_system_error
 #include // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
 
+#include "__threading_support"
+
 #if (__APPLE__)
 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
@@ -67,7 +69,12 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
-#if defined(_LIBCPP_WIN32API)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+struct timespec tp;
+if (0 != __libcpp_clock_realtime())
+__throw_system_error(errno, "__libcpp_clock_realtime() failed");
+return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
+#elif defined(_LIBCPP_WIN32API)
   // FILETIME is in 100ns units
   using filetime_duration =
   _VSTD::chrono::duration<__int64,
@@ -91,8 +98,8 @@
   filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
static_cast<__int64>(ft.dwLowDateTime)};
   return time_point(duration_cast(d - nt_to_unix_epoch));
-#else
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
+
+#elif defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
 struct timespec tp;
 if (0 != clock_gettime(CLOCK_REALTIME, ))
 __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
@@ -102,7 +109,6 @@
 gettimeofday(, 0);
 return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
 #endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME
-#endif
 }
 
 time_t
@@ -126,7 +132,18 @@
 
 const bool steady_clock::is_steady;
 
-#if defined(__APPLE__)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+
+steady_clock::time_point
+steady_clock::now() _NOEXCEPT
+{
+struct timespec tp;
+if (0 != __libcpp_clock_monotonic())
+__throw_system_error(errno, "__libcpp_clock_monotonic() failed");
+return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+}
+
+#elif defined(__APPLE__)
 
 // Darwin libc versions >= 1133 provide ns precision via CLOCK_UPTIME_RAW
 #if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29757: [libcxx] Threading support: Externalize hardware_concurrency()

2017-02-24 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 89664.
rmaprath added a comment.

Different take on the patch: Externalize this function only for the 
externally-thread-api variant.

This is much less intrusive. Note that I haven't added the declaration of 
`__libcpp_thread_hw_concurrency()` into `__threading_support` because it 
doesn't belong there (needs to be provided through a custom 
`__external_threading` header instead).

There is no easy way to test this apart from building an actual 
external-thread-api libc++ variant. We could do some form of testing with the 
external-thread-library configuration, but it still requires some not-so-pretty 
changes that is probably best avoided.


https://reviews.llvm.org/D29757

Files:
  src/thread.cpp


Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -77,7 +77,10 @@
 unsigned
 thread::hardware_concurrency() _NOEXCEPT
 {
-#if defined(CTL_HW) && defined(HW_NCPU)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+// Defer to the external threading implementation
+return __libcpp_thread_hw_concurrency();
+#elif defined(CTL_HW) && defined(HW_NCPU)
 unsigned n;
 int mib[2] = {CTL_HW, HW_NCPU};
 std::size_t s = sizeof(n);


Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -77,7 +77,10 @@
 unsigned
 thread::hardware_concurrency() _NOEXCEPT
 {
-#if defined(CTL_HW) && defined(HW_NCPU)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+// Defer to the external threading implementation
+return __libcpp_thread_hw_concurrency();
+#elif defined(CTL_HW) && defined(HW_NCPU)
 unsigned n;
 int mib[2] = {CTL_HW, HW_NCPU};
 std::size_t s = sizeof(n);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30290: [libcxx][zorg] Fix no-exceptions builder configurations

2017-02-23 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath marked an inline comment as done.
rmaprath added a comment.

Thanks!

Committed as r295963.

@gkistanova: Could you please let me know when the next restart is due? I would 
like to keep an eye on the builders.

Cheers,

/ Asiri


Repository:
  rL LLVM

https://reviews.llvm.org/D30290



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


[PATCH] D30290: [libcxx][zorg] Fix no-exceptions builder configurations

2017-02-23 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath marked an inline comment as done.
rmaprath added inline comments.



Comment at: buildbot/osuosl/master/config/builders.py:1196
+lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread -ldl 
-L/opt/llvm/lib/clang/3.9.0/lib/linux -lclang_rt.builtins-armhf"'},
+cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+  'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF',

rengolin wrote:
> rmaprath wrote:
> > rengolin wrote:
> > > Why remove the unwinder?
> > The unwinder should not be required for the no-exceptions library testing, 
> > as these libraries do not throw/catch any exceptions.
> > 
> > / Asiri
> But the requirement is not only to test it, but to make them work. We had 
> trouble making the bot pass without the unwinder, due to dependencies.
> 
> Regardless, this is a *different* change and should be made later, with 
> proper research. For now, just add the new flag, please.
If you have a time (heh!), please do try out without the unwinder and see if it 
still works fine. I'll be quite interested if it doesn't.

Downstream we have even more stricter tests to make sure there are no exception 
tables in the final binaries, but this require special linker options. It would 
be good to make sure that we can at least do without the unwinder upstream :)


https://reviews.llvm.org/D30290



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


[PATCH] D30290: [libcxx][zorg] Fix no-exceptions builder configurations

2017-02-23 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 89485.
rmaprath added a comment.

Updated to address comments from @rengolin.

In theory, it should not be necessary to link-in or enable the unwinder for 
these tests. However, it is best to leave this for a separate patch (after some 
local testing), just to make sure that none of those other libraries attempt to 
reference symbols from the unwinder (they should not, but who knows...).


https://reviews.llvm.org/D30290

Files:
  buildbot/osuosl/master/config/builders.py


Index: buildbot/osuosl/master/config/builders.py
===
--- buildbot/osuosl/master/config/builders.py
+++ buildbot/osuosl/master/config/builders.py
@@ -1044,7 +1044,8 @@
  'builddir': 'libcxx-libcxxabi-x86_64-linux-debian-noexceptions',
  'factory': LibcxxAndAbiBuilder.getLibcxxAndAbiBuilder(
  env={'CC': 'clang', 'CXX': 'clang++'},
- cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF'},
+ cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+   'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF'},
  lit_extra_args=['--shuffle']),
  'category': 'libcxx'},
 
@@ -1194,6 +1195,7 @@
 lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread 
-lunwind -ldl -L/opt/llvm/lib/clang/3.9.0/lib/linux 
-lclang_rt.builtins-armhf"'},
 cmake_extra_opts={'LIBCXXABI_USE_LLVM_UNWINDER': 'ON',
   'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+  'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF',
   'CMAKE_C_FLAGS': '-mcpu=cortex-a15 -mthumb',
   'CMAKE_CXX_FLAGS': '-mcpu=cortex-a15 -mthumb',
   'LLVM_PARALLEL_LINK_JOBS': '2'})},
@@ -1224,6 +1226,7 @@
 lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread 
-lunwind -ldl -L/opt/llvm/lib/clang/3.9.0/lib/linux 
-lclang_rt.builtins-aarch64"'},
 cmake_extra_opts={'LIBCXXABI_USE_LLVM_UNWINDER': 'ON',
   'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+  'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF',
   'LLVM_PARALLEL_LINK_JOBS': '4'})},
 
 ]


Index: buildbot/osuosl/master/config/builders.py
===
--- buildbot/osuosl/master/config/builders.py
+++ buildbot/osuosl/master/config/builders.py
@@ -1044,7 +1044,8 @@
  'builddir': 'libcxx-libcxxabi-x86_64-linux-debian-noexceptions',
  'factory': LibcxxAndAbiBuilder.getLibcxxAndAbiBuilder(
  env={'CC': 'clang', 'CXX': 'clang++'},
- cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF'},
+ cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+   'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF'},
  lit_extra_args=['--shuffle']),
  'category': 'libcxx'},
 
@@ -1194,6 +1195,7 @@
 lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread -lunwind -ldl -L/opt/llvm/lib/clang/3.9.0/lib/linux -lclang_rt.builtins-armhf"'},
 cmake_extra_opts={'LIBCXXABI_USE_LLVM_UNWINDER': 'ON',
   'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+  'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF',
   'CMAKE_C_FLAGS': '-mcpu=cortex-a15 -mthumb',
   'CMAKE_CXX_FLAGS': '-mcpu=cortex-a15 -mthumb',
   'LLVM_PARALLEL_LINK_JOBS': '2'})},
@@ -1224,6 +1226,7 @@
 lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread -lunwind -ldl -L/opt/llvm/lib/clang/3.9.0/lib/linux -lclang_rt.builtins-aarch64"'},
 cmake_extra_opts={'LIBCXXABI_USE_LLVM_UNWINDER': 'ON',
   'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+  'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF',
   'LLVM_PARALLEL_LINK_JOBS': '4'})},
 
 ]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30290: [libcxx][zorg] Fix no-exceptions builder configurations

2017-02-23 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added inline comments.



Comment at: buildbot/osuosl/master/config/builders.py:1196
+lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread -ldl 
-L/opt/llvm/lib/clang/3.9.0/lib/linux -lclang_rt.builtins-armhf"'},
+cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+  'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF',

rengolin wrote:
> Why remove the unwinder?
The unwinder should not be required for the no-exceptions library testing, as 
these libraries do not throw/catch any exceptions.

/ Asiri


https://reviews.llvm.org/D30290



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


[PATCH] D30290: [libcxx][zorg] Fix no-exceptions builder configurations

2017-02-23 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.
Herald added a reviewer: EricWF.

The no-exceptions builders are missing the -DLIBCXXABI_ENABLE_EXCEPTIONS=OFF 
flag (without this, only the libc++ libraries will be built without exceptions 
support, libc++abi will still be built with exceptions support - this is not a 
meaningful configuration).

Also we should not need to link in libunwind for these configurations. 
No-exceptions libraries by definition should not require an unwinder.


https://reviews.llvm.org/D30290

Files:
  buildbot/osuosl/master/config/builders.py


Index: buildbot/osuosl/master/config/builders.py
===
--- buildbot/osuosl/master/config/builders.py
+++ buildbot/osuosl/master/config/builders.py
@@ -1044,7 +1044,8 @@
  'builddir': 'libcxx-libcxxabi-x86_64-linux-debian-noexceptions',
  'factory': LibcxxAndAbiBuilder.getLibcxxAndAbiBuilder(
  env={'CC': 'clang', 'CXX': 'clang++'},
- cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF'},
+ cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+   'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF'},
  lit_extra_args=['--shuffle']),
  'category': 'libcxx'},
 
@@ -1183,17 +1184,17 @@
   'CMAKE_CXX_FLAGS': '-mcpu=cortex-a15 -marm',
   'LLVM_PARALLEL_LINK_JOBS': '2'})},
 
-{'name': 'libcxx-libcxxabi-libunwind-arm-linux-noexceptions',
+{'name': 'libcxx-libcxxabi-arm-linux-noexceptions',
  'slavenames': ['linaro-tk1-01'],
- 'builddir': 'libcxx-libcxxabi-libunwind-arm-linux-noexceptions',
+ 'builddir': 'libcxx-libcxxabi-arm-linux-noexceptions',
  'category': 'libcxx',
  'factory': LibcxxAndAbiBuilder.getLibcxxAndAbiBuilder(
 env={'CC': 'clang', 'CXX': 'clang++', 'PATH': 
'/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/llvm/bin'},
 # FIXME: there should be a way to merge autodetected with 
user-defined linker flags
 # See: libcxxabi/test/lit.cfg
-lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread 
-lunwind -ldl -L/opt/llvm/lib/clang/3.9.0/lib/linux 
-lclang_rt.builtins-armhf"'},
-cmake_extra_opts={'LIBCXXABI_USE_LLVM_UNWINDER': 'ON',
-  'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread -ldl 
-L/opt/llvm/lib/clang/3.9.0/lib/linux -lclang_rt.builtins-armhf"'},
+cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+  'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF',
   'CMAKE_C_FLAGS': '-mcpu=cortex-a15 -mthumb',
   'CMAKE_CXX_FLAGS': '-mcpu=cortex-a15 -mthumb',
   'LLVM_PARALLEL_LINK_JOBS': '2'})},
@@ -1212,18 +1213,18 @@
 cmake_extra_opts={'LIBCXXABI_USE_LLVM_UNWINDER': 'ON',
   'LLVM_PARALLEL_LINK_JOBS': '4'})},
 
-{'name': 'libcxx-libcxxabi-libunwind-aarch64-linux-noexceptions',
+{'name': 'libcxx-libcxxabi-aarch64-linux-noexceptions',
  'slavenames': ['linaro-apm-03'],
- 'builddir': 'libcxx-libcxxabi-libunwind-aarch64-linux-noexceptions',
+ 'builddir': 'libcxx-libcxxabi-aarch64-linux-noexceptions',
  'category': 'libcxx',
  'factory': LibcxxAndAbiBuilder.getLibcxxAndAbiBuilder(
 # FIXME: CFLAGS / CXXFLAGS are here because cmake_extra_opts 
doesn't quote correctly
 env={'CC': 'clang', 'CXX': 'clang++', 'CFLAGS': 
'-mcpu=cortex-a57', 'CXXFLAGS': '-mcpu=cortex-a57'},
 # FIXME: there should be a way to merge autodetected with 
user-defined linker flags
 # See: libcxxabi/test/lit.cfg
-lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread 
-lunwind -ldl -L/opt/llvm/lib/clang/3.9.0/lib/linux 
-lclang_rt.builtins-aarch64"'},
-cmake_extra_opts={'LIBCXXABI_USE_LLVM_UNWINDER': 'ON',
-  'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+lit_extra_opts={'link_flags': '"-lc++abi -lc -lm -lpthread -ldl 
-L/opt/llvm/lib/clang/3.9.0/lib/linux -lclang_rt.builtins-aarch64"'},
+cmake_extra_opts={'LIBCXX_ENABLE_EXCEPTIONS': 'OFF',
+  'LIBCXXABI_ENABLE_EXCEPTIONS': 'OFF',
   'LLVM_PARALLEL_LINK_JOBS': '4'})},
 
 ]


Index: buildbot/osuosl/master/config/builders.py
===
--- buildbot/osuosl/master/config/builders.py
+++ buildbot/osuosl/master/config/builders.py
@@ -1044,7 +1044,8 @@
  'builddir': 'libcxx-libcxxabi-x86_64-linux-debian-noexceptions',
  'factory': LibcxxAndAbiBuilder.getLibcxxAndAbiBuilder(
  env={'CC': 'clang', 'CXX': 'clang++'},
- 

[PATCH] D29818: [libcxx] Threading support: Attempt to externalize system_clock::now() and steady_clock::now() implementations

2017-02-15 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Ping?


https://reviews.llvm.org/D29818



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


[PATCH] D29757: [libcxx] Threading support: Externalize hardware_concurrency()

2017-02-15 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Ping?


https://reviews.llvm.org/D29757



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


[PATCH] D13289: [libc++] Provide additional templates for valarray transcendentals that satisfy the standard synopsis

2017-02-15 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

I've raised PR31966 to poke this :)


https://reviews.llvm.org/D13289



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


[PATCH] D29818: [libcxx] Threading support: Attempt to externalize system_clock::now() and steady_clock::now() implementations

2017-02-13 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 88190.
rmaprath added a comment.

Re-based.


https://reviews.llvm.org/D29818

Files:
  include/__threading_support
  src/chrono.cpp

Index: src/chrono.cpp
===
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -10,50 +10,7 @@
 #include "chrono"
 #include "cerrno"// errno
 #include "system_error"  // __throw_system_error
-#include // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
-
-#if (__APPLE__)
-#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif
-#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 10
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif
-#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 10
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif
-#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 3
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif
-#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__
-#else
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif // __APPLE__
-
-#if defined(_LIBCPP_WIN32API)
-#define WIN32_LEAN_AND_MEAN
-#define VC_EXTRA_LEAN
-#include 
-#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
-#include 
-#endif
-#else
-#if !defined(CLOCK_REALTIME) || !defined(_LIBCXX_USE_CLOCK_GETTIME)
-#include // for gettimeofday and timeval
-#endif // !defined(CLOCK_REALTIME)
-#endif // defined(_LIBCPP_WIN32API)
-
-#if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
-#if __APPLE__
-#include   // mach_absolute_time, mach_timebase_info_data_t
-#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
-#error "Monotonic clock not implemented"
-#endif
-#endif
+#include "__threading_support"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -67,42 +24,7 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
-#if defined(_LIBCPP_WIN32API)
-  // FILETIME is in 100ns units
-  using filetime_duration =
-  _VSTD::chrono::duration<__int64,
-  _VSTD::ratio_multiply<_VSTD::ratio<100, 1>,
-nanoseconds::period>>;
-
-  // The Windows epoch is Jan 1 1601, the Unix epoch Jan 1 1970.
-  static _LIBCPP_CONSTEXPR const seconds nt_to_unix_epoch{11644473600};
-
-  FILETIME ft;
-#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
-  GetSystemTimePreciseAsFileTime();
-#else
-  GetSystemTimeAsFileTime();
-#endif
-#else
-  GetSystemTimeAsFileTime();
-#endif
-
-  filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
-   static_cast<__int64>(ft.dwLowDateTime)};
-  return time_point(duration_cast(d - nt_to_unix_epoch));
-#else
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
-struct timespec tp;
-if (0 != clock_gettime(CLOCK_REALTIME, ))
-__throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
-return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
-#else
-timeval tv;
-gettimeofday(, 0);
-return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
-#endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME
-#endif
+return __libcpp_clock_system_now();
 }
 
 time_t
@@ -193,42 +115,15 @@
 }
 #endif // defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)
 
-#elif defined(_LIBCPP_WIN32API)
-
-steady_clock::time_point
-steady_clock::now() _NOEXCEPT
-{
-  static LARGE_INTEGER freq;
-  static BOOL initialized = FALSE;
-  if (!initialized)
-initialized = QueryPerformanceFrequency(); // always succceeds
-
-  LARGE_INTEGER counter;
-  QueryPerformanceCounter();
-  return time_point(duration(counter.QuadPart * nano::den / freq.QuadPart));
-}
-
-#elif defined(CLOCK_MONOTONIC)
-
-// On Apple platforms only CLOCK_UPTIME_RAW or mach_absolute_time are able to
-// time functions in the nanosecond range. Thus, they are the only acceptable
-// implementations of steady_clock.
-#ifdef __APPLE__
-#error "Never use CLOCK_MONOTONIC for steady_clock::now on Apple platforms"
-#endif
+#else
 
 steady_clock::time_point
 steady_clock::now() _NOEXCEPT
 {
-struct timespec tp;
-if (0 != clock_gettime(CLOCK_MONOTONIC, ))
-__throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
-return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+return __libcpp_clock_steady_now();
 }
 
-#else
-#error "Monotonic clock not implemented"
-#endif
+#endif // __APPLE__
 
 #endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK
 
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -13,7 +13,9 @@
 
 #include <__config>
 #include 
-#include 
+#include 
+#include 
+#include 
 
 #ifndef 

[PATCH] D29757: [libcxx] Threading support: Externalize hardware_concurrency()

2017-02-13 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 88189.
rmaprath retitled this revision from "Threading support: Externalize 
hardware_concurrency()" to "[libcxx] Threading support: Externalize 
hardware_concurrency()".
rmaprath added a comment.

Re-based on trunk.


https://reviews.llvm.org/D29757

Files:
  include/__threading_support
  src/thread.cpp

Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -15,26 +15,6 @@
 #include "vector"
 #include "future"
 #include "limits"
-#include 
-
-#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
-# include 
-# if defined(BSD)
-#   include 
-# endif // defined(BSD)
-#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
-
-#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__)
-# include 
-#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__)
-
-#if defined(__NetBSD__)
-#pragma weak pthread_create // Do not create libpthread dependency
-#endif
-
-#if defined(_LIBCPP_WIN32API)
-#include 
-#endif // defined(_LIBCPP_WIN32API)
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -77,35 +57,13 @@
 unsigned
 thread::hardware_concurrency() _NOEXCEPT
 {
-#if defined(CTL_HW) && defined(HW_NCPU)
-unsigned n;
-int mib[2] = {CTL_HW, HW_NCPU};
-std::size_t s = sizeof(n);
-sysctl(mib, 2, , , 0, 0);
-return n;
-#elif defined(_SC_NPROCESSORS_ONLN)
-long result = sysconf(_SC_NPROCESSORS_ONLN);
-// sysconf returns -1 if the name is invalid, the option does not exist or
-// does not have a definite limit.
-// if sysconf returns some other negative number, we have no idea
-// what is going on. Default to something safe.
+int result = __libcpp_thread_hw_concurrency();
+
+// Treat negative values as errors. Use a safe default value.
 if (result < 0)
 return 0;
-return static_cast(result);
-#elif defined(_LIBCPP_WIN32API)
-SYSTEM_INFO info;
-GetSystemInfo();
-return info.dwNumberOfProcessors;
-#else  // defined(CTL_HW) && defined(HW_NCPU)
-// TODO: grovel through /proc or check cpuid on x86 and similar
-// instructions on other architectures.
-#   if defined(_LIBCPP_MSVC)
-_LIBCPP_WARNING("hardware_concurrency not yet implemented")
-#   else
-#   warning hardware_concurrency not yet implemented
-#   endif
-return 0;  // Means not computable [thread.thread.static]
-#endif  // defined(CTL_HW) && defined(HW_NCPU)
+
+return result;
 }
 
 namespace this_thread
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -26,6 +26,22 @@
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 # include 
 # include 
+
+#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
+# include 
+# if defined(BSD)
+#   include 
+# endif // defined(BSD)
+#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
+
+#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__)
+# include 
+#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__)
+
+#if defined(__NetBSD__)
+#pragma weak pthread_create // Do not create libpthread dependency
+#endif
+
 #elif defined(_LIBCPP_HAS_THREAD_API_WIN32)
 #include 
 #include 
@@ -186,6 +202,9 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns);
 
+_LIBCPP_THREAD_ABI_VISIBILITY
+int __libcpp_thread_hw_concurrency();
+
 // Thread local storage
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_tls_create(__libcpp_tls_key* __key,
@@ -370,6 +389,28 @@
while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
 }
 
+int __libcpp_thread_hw_concurrency()
+{
+#if defined(CTL_HW) && defined(HW_NCPU)
+  int __n;
+  int __mib[2] = {CTL_HW, HW_NCPU};
+  std::size_t __sz = sizeof(__n);
+  sysctl(__mib, 2, &__n, &__sz, 0, 0);
+  return __n;
+#elif defined(_SC_NPROCESSORS_ONLN)
+  return sysconf(_SC_NPROCESSORS_ONLN);
+#else  // !(defined(CTL_HW) && defined(HW_NCPU))
+  // TODO: grovel through /proc or check cpuid on x86 and similar
+  // instructions on other architectures.
+# if defined(_LIBCPP_MSVC)
+_LIBCPP_WARNING("hardware_concurrency not yet implemented")
+# else
+#   warning hardware_concurrency not yet implemented
+# endif
+  return 0;  // Means not computable [thread.thread.static]
+#endif  // defined(CTL_HW) && defined(HW_NCPU
+}
+
 // Thread local storage
 int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
 {
@@ -596,6 +637,13 @@
   Sleep(__ms.count());
 }
 
+int __libcpp_thread_hw_concurrency()
+{
+  SYSTEM_INFO __info;
+  GetSystemInfo(&__info);
+  return __info.dwNumberOfProcessors;
+}
+
 // Thread Local Storage
 int __libcpp_tls_create(__libcpp_tls_key* __key,
 void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*))

[PATCH] D29818: [libcxx] Threading support: Attempt to externalize system_clock::now() and steady_clock::now() implementations

2017-02-10 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.

These implementations depend heavily on the underlying platform. It would be 
good to put them behind a porting function within the threading API as quite a 
bit of threading functionality depend on the clocks.

The `steady_clock::now()` implementation was difficult to pluck out for 
`__APPLE__` because it uses some static functions within the library sources.

I have tested these changes on linux, I will test them on Windows and Mac 
before committing (if this gets approved).


https://reviews.llvm.org/D29818

Files:
  include/__threading_support
  src/chrono.cpp

Index: src/chrono.cpp
===
--- src/chrono.cpp
+++ src/chrono.cpp
@@ -10,50 +10,7 @@
 #include "chrono"
 #include "cerrno"// errno
 #include "system_error"  // __throw_system_error
-#include // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
-
-#if (__APPLE__)
-#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif
-#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 10
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif
-#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 10
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif
-#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 3
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif
-#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__
-#else
-#define _LIBCXX_USE_CLOCK_GETTIME
-#endif // __APPLE__
-
-#if defined(_LIBCPP_WIN32API)
-#define WIN32_LEAN_AND_MEAN
-#define VC_EXTRA_LEAN
-#include 
-#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
-#include 
-#endif
-#else
-#if !defined(CLOCK_REALTIME) || !defined(_LIBCXX_USE_CLOCK_GETTIME)
-#include // for gettimeofday and timeval
-#endif // !defined(CLOCK_REALTIME)
-#endif // defined(_LIBCPP_WIN32API)
-
-#if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
-#if __APPLE__
-#include   // mach_absolute_time, mach_timebase_info_data_t
-#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
-#error "Monotonic clock not implemented"
-#endif
-#endif
+#include "__threading_support"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -67,42 +24,7 @@
 system_clock::time_point
 system_clock::now() _NOEXCEPT
 {
-#if defined(_LIBCPP_WIN32API)
-  // FILETIME is in 100ns units
-  using filetime_duration =
-  _VSTD::chrono::duration<__int64,
-  _VSTD::ratio_multiply<_VSTD::ratio<100, 1>,
-nanoseconds::period>>;
-
-  // The Windows epoch is Jan 1 1601, the Unix epoch Jan 1 1970.
-  static _LIBCPP_CONSTEXPR const seconds nt_to_unix_epoch{11644473600};
-
-  FILETIME ft;
-#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
-  GetSystemTimePreciseAsFileTime();
-#else
-  GetSystemTimeAsFileTime();
-#endif
-#else
-  GetSystemTimeAsFileTime();
-#endif
-
-  filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
-   static_cast<__int64>(ft.dwLowDateTime)};
-  return time_point(duration_cast(d - nt_to_unix_epoch));
-#else
-#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
-struct timespec tp;
-if (0 != clock_gettime(CLOCK_REALTIME, ))
-__throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
-return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
-#else
-timeval tv;
-gettimeofday(, 0);
-return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
-#endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME
-#endif
+return __libcpp_clock_system_now();
 }
 
 time_t
@@ -193,42 +115,15 @@
 }
 #endif // defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)
 
-#elif defined(_LIBCPP_WIN32API)
-
-steady_clock::time_point
-steady_clock::now() _NOEXCEPT
-{
-  static LARGE_INTEGER freq;
-  static BOOL initialized = FALSE;
-  if (!initialized)
-initialized = QueryPerformanceFrequency(); // always succceeds
-
-  LARGE_INTEGER counter;
-  QueryPerformanceCounter();
-  return time_point(duration(counter.QuadPart * nano::den / freq.QuadPart));
-}
-
-#elif defined(CLOCK_MONOTONIC)
-
-// On Apple platforms only CLOCK_UPTIME_RAW or mach_absolute_time are able to
-// time functions in the nanosecond range. Thus, they are the only acceptable
-// implementations of steady_clock.
-#ifdef __APPLE__
-#error "Never use CLOCK_MONOTONIC for steady_clock::now on Apple platforms"
-#endif
+#else
 
 steady_clock::time_point
 steady_clock::now() _NOEXCEPT
 {
-struct timespec tp;
-if (0 != clock_gettime(CLOCK_MONOTONIC, ))
-__throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
-return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+return 

[PATCH] D29757: Threading support: Externalize hardware_concurrency()

2017-02-09 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.

Another one of those platform-dependent methods which should live behind the 
threading API.


https://reviews.llvm.org/D29757

Files:
  include/__threading_support
  src/thread.cpp

Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -15,26 +15,6 @@
 #include "vector"
 #include "future"
 #include "limits"
-#include 
-
-#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
-# include 
-# if defined(BSD)
-#   include 
-# endif // defined(BSD)
-#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
-
-#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
-# include 
-#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
-
-#if defined(__NetBSD__)
-#pragma weak pthread_create // Do not create libpthread dependency
-#endif
-
-#if defined(_LIBCPP_WIN32API)
-#include 
-#endif // defined(_LIBCPP_WIN32API)
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -77,35 +57,13 @@
 unsigned
 thread::hardware_concurrency() _NOEXCEPT
 {
-#if defined(CTL_HW) && defined(HW_NCPU)
-unsigned n;
-int mib[2] = {CTL_HW, HW_NCPU};
-std::size_t s = sizeof(n);
-sysctl(mib, 2, , , 0, 0);
-return n;
-#elif defined(_SC_NPROCESSORS_ONLN)
-long result = sysconf(_SC_NPROCESSORS_ONLN);
-// sysconf returns -1 if the name is invalid, the option does not exist or
-// does not have a definite limit.
-// if sysconf returns some other negative number, we have no idea
-// what is going on. Default to something safe.
+int result = __libcpp_thread_hw_concurrency();
+
+// Treat negative values as errors. Use a safe default value.
 if (result < 0)
 return 0;
-return static_cast(result);
-#elif defined(_LIBCPP_WIN32API)
-SYSTEM_INFO info;
-GetSystemInfo();
-return info.dwNumberOfProcessors;
-#else  // defined(CTL_HW) && defined(HW_NCPU)
-// TODO: grovel through /proc or check cpuid on x86 and similar
-// instructions on other architectures.
-#   if defined(_LIBCPP_MSVC)
-_LIBCPP_WARNING("hardware_concurrency not yet implemented")
-#   else
-#   warning hardware_concurrency not yet implemented
-#   endif
-return 0;  // Means not computable [thread.thread.static]
-#endif  // defined(CTL_HW) && defined(HW_NCPU)
+
+return result;
 }
 
 namespace this_thread
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -26,6 +26,19 @@
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 # include 
 # include 
+
+#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
+# include 
+# if defined(BSD)
+#   include 
+# endif // defined(BSD)
+# include 
+#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
+
+#if defined(__NetBSD__)
+#pragma weak pthread_create // Do not create libpthread dependency
+#endif
+
 #elif defined(_LIBCPP_HAS_THREAD_API_WIN32)
 #include 
 #include 
@@ -186,6 +199,9 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 void __libcpp_thread_sleep_for(const chrono::nanoseconds& ns);
 
+_LIBCPP_THREAD_ABI_VISIBILITY
+int __libcpp_thread_hw_concurrency();
+
 // Thread local storage
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_tls_create(__libcpp_tls_key* __key,
@@ -370,6 +386,28 @@
while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
 }
 
+int __libcpp_thread_hw_concurrency()
+{
+#if defined(CTL_HW) && defined(HW_NCPU)
+  int __n;
+  int __mib[2] = {CTL_HW, HW_NCPU};
+  std::size_t __sz = sizeof(__n);
+  sysctl(__mib, 2, &__n, &__sz, 0, 0);
+  return __n;
+#elif defined(_SC_NPROCESSORS_ONLN)
+  return sysconf(_SC_NPROCESSORS_ONLN);
+#else  // !(defined(CTL_HW) && defined(HW_NCPU))
+  // TODO: grovel through /proc or check cpuid on x86 and similar
+  // instructions on other architectures.
+# if defined(_LIBCPP_MSVC)
+_LIBCPP_WARNING("hardware_concurrency not yet implemented")
+# else
+#   warning hardware_concurrency not yet implemented
+# endif
+  return 0;  // Means not computable [thread.thread.static]
+#endif  // defined(CTL_HW) && defined(HW_NCPU
+}
+
 // Thread local storage
 int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
 {
@@ -595,6 +633,13 @@
   Sleep(__ms.count());
 }
 
+int __libcpp_thread_hw_concurrency()
+{
+  SYSTEM_INFO __info;
+  GetSystemInfo(&__info);
+  return __info.dwNumberOfProcessors;
+}
+
 // Thread Local Storage
 int __libcpp_tls_create(__libcpp_tls_key* __key,
 void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29630: [libcxx] Threading support: externalize sleep_for()

2017-02-08 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D29630#670876, @EricWF wrote:

> In https://reviews.llvm.org/D29630#670873, @rmaprath wrote:
>
> > Sorry for the delay, I've updated the patch with all the comments addressed.
> >
> > @EricWF: Got one question before I commit: The `sleep_for` function in the 
> > dylib (`thread.cpp`) is now quite small. Is there a particular reason to 
> > keep it there? I was wondering if we should move that bit to the `` 
> > header altogether.
>
>
> Removing the definition in the dylib would be ABI breaking.


Ah! of course.

Thanks.


https://reviews.llvm.org/D29630



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


[PATCH] D29630: [libcxx] Threading support: externalize sleep_for()

2017-02-08 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath updated this revision to Diff 87669.
rmaprath added a comment.

Sorry for the delay, I've updated the patch with all the comments addressed.

@EricWF: Got one question before I commit: The `sleep_for` function in the 
dylib (`thread.cpp`) is now quite small. Is there a particular reason to keep 
it there? I was wondering if we should move that bit to the `` header 
altogether.


https://reviews.llvm.org/D29630

Files:
  include/__threading_support
  src/thread.cpp

Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -114,33 +114,9 @@
 void
 sleep_for(const chrono::nanoseconds& ns)
 {
-using namespace chrono;
-if (ns > nanoseconds::zero())
+if (ns > chrono::nanoseconds::zero())
 {
-#if defined(_LIBCPP_WIN32API)
-milliseconds ms = duration_cast(ns);
-if (ms.count() == 0 || ns > duration_cast(ms))
-  ++ms;
-Sleep(ms.count());
-#else
-seconds s = duration_cast(ns);
-timespec ts;
-typedef decltype(ts.tv_sec) ts_sec;
-_LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits::max();
-if (s.count() < ts_sec_max)
-{
-ts.tv_sec = static_cast(s.count());
-ts.tv_nsec = static_cast((ns-s).count());
-}
-else
-{
-ts.tv_sec = ts_sec_max;
-ts.tv_nsec = giga::num - 1;
-}
-
-while (nanosleep(, ) == -1 && errno == EINTR)
-;
-#endif
+__libcpp_thread_sleep_for(ns);
 }
 }
 
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -12,6 +12,8 @@
 #define _LIBCPP_THREADING_SUPPORT
 
 #include <__config>
+#include 
+#include 
 
 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
 #pragma GCC system_header
@@ -28,8 +30,6 @@
 #include 
 #include 
 #include 
-
-#include 
 #endif
 
 #if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
@@ -183,6 +183,9 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 void __libcpp_thread_yield();
 
+_LIBCPP_THREAD_ABI_VISIBILITY
+void __libcpp_thread_sleep_for(const chrono::nanoseconds& ns);
+
 // Thread local storage
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_tls_create(__libcpp_tls_key* __key,
@@ -345,6 +348,28 @@
   sched_yield();
 }
 
+void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
+{
+   using namespace chrono;
+   seconds __s = duration_cast(__ns);
+   timespec __ts;
+   typedef decltype(__ts.tv_sec) ts_sec;
+   _LIBCPP_CONSTEXPR ts_sec __ts_sec_max = numeric_limits::max();
+
+   if (__s.count() < __ts_sec_max)
+   {
+ __ts.tv_sec = static_cast(__s.count());
+ __ts.tv_nsec = static_cast((__ns - __s).count());
+   }
+   else
+   {
+ __ts.tv_sec = __ts_sec_max;
+ __ts.tv_nsec = 9; // (10^9 - 1)
+   }
+
+   while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
+}
+
 // Thread local storage
 int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
 {
@@ -562,6 +587,14 @@
   SwitchToThread();
 }
 
+void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
+{
+  using namespace chrono;
+  // round-up to the nearest milisecond
+  milliseconds __ms = duration_cast(__ns + 99);
+  Sleep(__ms.count());
+}
+
 // Thread Local Storage
 int __libcpp_tls_create(__libcpp_tls_key* __key,
 void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29630: [libcxx] Threading support: externalize sleep_for()

2017-02-07 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added inline comments.



Comment at: include/__threading_support:593
+  using namespace chrono;
+  milliseconds ms = duration_cast(ns);
+  if (ms.count() == 0 || ns > duration_cast(ms))

joerg wrote:
> Use (ns + 99) so that the cast rounds up.
So, this code was lifted from the sources as-is. I will do this change, I think 
it makes sense.



Comment at: include/__threading_support:594
+  milliseconds ms = duration_cast(ns);
+  if (ms.count() == 0 || ns > duration_cast(ms))
+++ms;

joerg wrote:
> Why is ns == 0 supposed to sleep at all? In fact, the caller already ensures 
> that can't happen?
IIUC, this is trying to detect round-downs and then compensate for it. With the 
above suggestion, this should no longer be needed. Will get rid of it as well.


https://reviews.llvm.org/D29630



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


[PATCH] D29630: [libcxx] Threading support: externalize sleep_for()

2017-02-07 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.

Different platforms implement the wait/sleep behaviour in very different ways. 
It makes sense to hoist this functionality into the threading API.

I also feel similarly about `hardware_concurrecy()` implementation. Any 
thoughts on that?


https://reviews.llvm.org/D29630

Files:
  include/__threading_support
  src/thread.cpp

Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -114,33 +114,9 @@
 void
 sleep_for(const chrono::nanoseconds& ns)
 {
-using namespace chrono;
-if (ns > nanoseconds::zero())
+if (ns > chrono::nanoseconds::zero())
 {
-#if defined(_LIBCPP_WIN32API)
-milliseconds ms = duration_cast(ns);
-if (ms.count() == 0 || ns > duration_cast(ms))
-  ++ms;
-Sleep(ms.count());
-#else
-seconds s = duration_cast(ns);
-timespec ts;
-typedef decltype(ts.tv_sec) ts_sec;
-_LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits::max();
-if (s.count() < ts_sec_max)
-{
-ts.tv_sec = static_cast(s.count());
-ts.tv_nsec = static_cast((ns-s).count());
-}
-else
-{
-ts.tv_sec = ts_sec_max;
-ts.tv_nsec = giga::num - 1;
-}
-
-while (nanosleep(, ) == -1 && errno == EINTR)
-;
-#endif
+__libcpp_thread_sleep_for(ns);
 }
 }
 
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -12,6 +12,8 @@
 #define _LIBCPP_THREADING_SUPPORT
 
 #include <__config>
+#include 
+#include 
 
 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
 #pragma GCC system_header
@@ -28,8 +30,6 @@
 #include 
 #include 
 #include 
-
-#include 
 #endif
 
 #if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
@@ -183,6 +183,9 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 void __libcpp_thread_yield();
 
+_LIBCPP_THREAD_ABI_VISIBILITY
+void __libcpp_thread_sleep_for(const chrono::nanoseconds& ns);
+
 // Thread local storage
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_tls_create(__libcpp_tls_key* __key,
@@ -345,6 +348,28 @@
   sched_yield();
 }
 
+void __libcpp_thread_sleep_for(const chrono::nanoseconds& ns)
+{
+   using namespace chrono;
+   seconds s = duration_cast(ns);
+   timespec ts;
+   typedef decltype(ts.tv_sec) ts_sec;
+   _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits::max();
+
+   if (s.count() < ts_sec_max)
+   {
+ ts.tv_sec = static_cast(s.count());
+ ts.tv_nsec = static_cast((ns-s).count());
+   }
+   else
+   {
+ ts.tv_sec = ts_sec_max;
+ ts.tv_nsec = giga::num - 1;
+   }
+
+   while (nanosleep(, ) == -1 && errno == EINTR);
+}
+
 // Thread local storage
 int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
 {
@@ -562,6 +587,15 @@
   SwitchToThread();
 }
 
+void __libcpp_thread_sleep_for(const chrono::nanoseconds& ns)
+{
+  using namespace chrono;
+  milliseconds ms = duration_cast(ns);
+  if (ms.count() == 0 || ns > duration_cast(ms))
+++ms;
+  Sleep(ms.count());
+}
+
 // Thread Local Storage
 int __libcpp_tls_create(__libcpp_tls_key* __key,
 void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29063: [libcxx] Never use within libc++

2017-01-24 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Sorry, I meant `-DLIBCXX_ENABLE_ASSERTIONS=ON`.


https://reviews.llvm.org/D29063



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


[PATCH] D29063: [libcxx] Never use within libc++

2017-01-24 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

@EricWF: My downstream builds have `-DLLVM_ENABLE_ASSERTIONS=ON` by default and 
they are showing some failures after this commit. Log attached:

F3019711: log.txt 

It should be pretty easy to reproduce these (I'm on Ubuntu 16.04) if you enable 
assertions. Since the default has changed, the public builders won't be seeing 
these.

Are these failures expected?

Thanks.

/ Asiri


https://reviews.llvm.org/D29063



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


[PATCH] D28610: [libcxx] Improve design documentation for the external-thread-library configuration

2017-01-12 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: EricWF, mclow.lists.
rmaprath added a subscriber: cfe-commits.

Trying to improve the documentation for the external-thread-library 
configuration of `libc++`.


https://reviews.llvm.org/D28610

Files:
  docs/DesignDocs/ThreadingSupportAPI.rst


Index: docs/DesignDocs/ThreadingSupportAPI.rst
===
--- docs/DesignDocs/ThreadingSupportAPI.rst
+++ docs/DesignDocs/ThreadingSupportAPI.rst
@@ -33,13 +33,22 @@
 External Threading Library
 ==
 
-Normally ``<__threading_support>`` provides inline definitions to each internal
-threading API function it declares. However libc++ also supports using an
-external library to provide the definitions.
-
-When ``_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL`` libc++ does not provide inline
-definitions for the internal API, instead assuming the definitions will be
-provided by an external library.
+libc++ can be compiled with its internal threading API delegated to an external
+library. Such a configuration is useful for library vendors who wish to
+distribute a thread-agnostic libc++ library, where the users of the library are
+expected to provide the implementation of the libc++ internal threading API.
+
+On a production setting, this would be achieved through a custom
+``<__external_threading>`` header, which declares the libc++ internal threading
+API but leaves out the implementation.
+
+The ``-DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY`` option allows building libc++ in
+such a configuration while allowing it to be tested on a platform that supports
+any of the threading implementations available in ``__threading_support``
+header. Therefore, the main purpose of this option is to allow testing of this
+paricular configuration of the library without being tied to a vendor-specific
+threading implementation. This option is only meant to be used by libc++ 
library
+developers.
 
 Threading Configuration Macros
 ==


Index: docs/DesignDocs/ThreadingSupportAPI.rst
===
--- docs/DesignDocs/ThreadingSupportAPI.rst
+++ docs/DesignDocs/ThreadingSupportAPI.rst
@@ -33,13 +33,22 @@
 External Threading Library
 ==
 
-Normally ``<__threading_support>`` provides inline definitions to each internal
-threading API function it declares. However libc++ also supports using an
-external library to provide the definitions.
-
-When ``_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL`` libc++ does not provide inline
-definitions for the internal API, instead assuming the definitions will be
-provided by an external library.
+libc++ can be compiled with its internal threading API delegated to an external
+library. Such a configuration is useful for library vendors who wish to
+distribute a thread-agnostic libc++ library, where the users of the library are
+expected to provide the implementation of the libc++ internal threading API.
+
+On a production setting, this would be achieved through a custom
+``<__external_threading>`` header, which declares the libc++ internal threading
+API but leaves out the implementation.
+
+The ``-DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY`` option allows building libc++ in
+such a configuration while allowing it to be tested on a platform that supports
+any of the threading implementations available in ``__threading_support``
+header. Therefore, the main purpose of this option is to allow testing of this
+paricular configuration of the library without being tied to a vendor-specific
+threading implementation. This option is only meant to be used by libc++ library
+developers.
 
 Threading Configuration Macros
 ==
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28608: [libcxx] Don't assume __libcpp_thread_t is an integral type.

2017-01-12 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: compnerd, EricWF.
rmaprath added a subscriber: cfe-commits.

We have refactored the underlying platform thread type into 
`__libcpp_thread_t`, but there are few places in the source where it is assumed 
to be an integral type.

This was discovered while trying to port `libcxx` onto a platform with a 
slightly wonkier threading system.


https://reviews.llvm.org/D28608

Files:
  include/__threading_support
  include/thread


Index: include/thread
===
--- include/thread
+++ include/thread
@@ -290,7 +290,7 @@
 typedef __libcpp_thread_t native_handle_type;
 
 _LIBCPP_INLINE_VISIBILITY
-thread() _NOEXCEPT : __t_(0) {}
+thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 template (data.__func(data.__arg));
 }
 
+bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
+  return *__t == 0;
+}
+
 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
void *__arg)
 {


Index: include/thread
===
--- include/thread
+++ include/thread
@@ -290,7 +290,7 @@
 typedef __libcpp_thread_t native_handle_type;
 
 _LIBCPP_INLINE_VISIBILITY
-thread() _NOEXCEPT : __t_(0) {}
+thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 template (data.__func(data.__arg));
 }
 
+bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
+  return *__t == 0;
+}
+
 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
void *__arg)
 {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28316: [libc++] Cleanup and document <__threading_support>

2017-01-05 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D28316#636700, @EricWF wrote:

> In https://reviews.llvm.org/D28316#636686, @rmaprath wrote:
>
> > (btw, do those docs updates land on some web URL automagically when 
> > committed?).
>
>
> Assuming the builder isn't broken then yes, the docs should automagically 
> update within ~3 minutes.
>
> > I think we should point out on the docs that 
> > `_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL` is only meant for `libc++` developers 
> > / testers. The purpose of this library variant is to:
> > 
> > - Demonstrate that `libc++` can be built with threading support 
> > externalised. We use `pthreads` as the underlying implementation in this 
> > case because that's the one we can easily test on any platform. I don't 
> > think anyone wants to distribute this library variant to users; they would 
> > rather compile `libc++` for `pthread` directly instead.
> > - Write tests that applies to the `LIBCXX_HAS_EXTERNAL_THREAD_API` variant. 
> > For example, I hope to write a test to check that the produced `libc++` 
> > dylib has no references to `pthread_` symbols within it. Such a test will 
> > ensure that the core sources of `libc++` remains pthread-free (all 
> > threading should be wired through the threading API). If a library vendors 
> > really wants to distribute a variant of `libc++` with the threading support 
> > externalised, they should use a custom `__external_threading` header to 
> > replicate the behaviour of `_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL`.
> > 
> >   Hope that makes sense?
>
> All of that makes sense. I think you could write those docs better than I 
> could. Would you be willing to update them?


Sure, please go ahead with the commit. I'll have to do some downstream 
adjustments first, then I will update the docs.

Thanks for sorting this out!




Comment at: include/__threading_support:33
+#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
+defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)
 #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS

EricWF wrote:
> rmaprath wrote:
> > Do we need the second check? I think `_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL` 
> > is already set through `__config` header (through `__config_site.in`) when 
> > this header gets included `external_threads.cpp` (?).
> I think it seems useful enough to make 
> `_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL` work on its own to build a 
> standalone threading library.
Makes sense.



Comment at: include/__threading_support:38
 #endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD

EricWF wrote:
> rmaprath wrote:
> > Can we add a second check here like:
> > 
> > ```
> > #if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) && \
> > !defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
> > #error "Don't know how to declare the thread API without pthreads".
> > #endif
> > ```
> > Or we can enforce this on the cmake file itself (or both). This ties up to 
> > my comment about `_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL` only meant to be for 
> > `libc++` developers / testers.
> I think that's already done in the `__config` header if we can't find a 
> threading API.
Indeed, missed that.


https://reviews.llvm.org/D28316



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


[PATCH] D28316: [libc++] Cleanup and document <__threading_support>

2017-01-05 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

This is much better (few nits inline). And many thanks for the docs update 
(btw, do those docs updates land on some web URL automagically when committed?).

I think we should point out on the docs that 
`_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL` is only meant for `libc++` developers / 
testers. The purpose of this library variant is to:

- Demonstrate that `libc++` can be built with threading support externalised. 
We use `pthreads` as the underlying implementation in this case because that's 
the one we can easily test on any platform. I don't think anyone wants to 
distribute this library variant to users; they would rather compile `libc++` 
for `pthread` directly instead.
- Write tests that applies to the `LIBCXX_HAS_EXTERNAL_THREAD_API` variant. For 
example, I hope to write a test to check that the produced `libc++` dylib has 
no references to `pthread_` symbols within it. Such a test will ensure that the 
core sources of `libc++` remains pthread-free (all threading should be wired 
through the threading API).

If a library vendors really wants to distribute a variant of `libc++` with the 
threading support externalised, they should use a custom `__external_threading` 
header to replicate the behaviour of `_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL`.

Hope that makes sense?




Comment at: CMakeLists.txt:172
This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
+option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY
+"Build libc++ with an externalized threading library.

Can you add another check so that this is not used together with 
`LIBCXX_HAS_EXTERNAL_THREAD_API` ?



Comment at: include/__config:894
 // Thread API
-#if !defined(_LIBCPP_HAS_NO_THREADS) && \
-!defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
-!defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+#if !defined(_LIBCPP_HAS_NO_THREADS)
 # if defined(__FreeBSD__) || \

// ignore this comment please (phab won't allow me to delete draft comments)



Comment at: include/__threading_support:21
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+# ifdef _LIBCPP_HAS_NO_THREADS
+#   error _LIBCPP_HAS_NO_THREADS cannot be defined with 
_LIBCPP_HAS_THREAD_API_EXTERNAL

This is already enforced in the `__config` header (just below where it derives 
the thread API). I think we can remove this check.



Comment at: include/__threading_support:33
+#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
+defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)
 #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS

Do we need the second check? I think `_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL` is 
already set through `__config` header (through `__config_site.in`) when this 
header gets included `external_threads.cpp` (?).



Comment at: include/__threading_support:38
 #endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD

Can we add a second check here like:

```
#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) && \
!defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
#error "Don't know how to declare the thread API without pthreads".
#endif
```
Or we can enforce this on the cmake file itself (or both). This ties up to my 
comment about `_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL` only meant to be for 
`libc++` developers / testers.


https://reviews.llvm.org/D28316



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


[PATCH] D28229: [libcxx] Fix testing of the externally-threaded library build after r290850

2017-01-04 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D28229#634278, @compnerd wrote:

> I dont think that making Win32 threading an external one makes much sense 
> unless we also do the same for pthreads.  Its just as valid a threading model 
> as pthreads, so why give preferential treatment to that?  (Sure, there are 
> more buildbots using it, but thats not a strong technical justification).


If the Win32 threading is support is going to be upstreamed, yes, it makes 
sense to give it the same treatment as pthreads (keep it inside 
`__threading_support`). libcxx has been tied to pthreads for a while, would be 
good to see something else supported as well. This will also allow us to iron 
out pthread-isms from the sources into the threading API. I have a couple of 
patches in that area (which I discovered while implementing the libcxx 
threading API with a different thread implementation), will put them up for 
review soon.




Comment at: include/__threading_support:30-50
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
+!__libcpp_has_include(<__external_threading>)
+// If the <__external_threading> header is absent, build libc++ against a
+// pthread-oriented thread api but leave out its implementation. This setup
+// allows building+testing of an externally-threaded library variant (on any
+// platform that supports pthreads). Here, an 'externally-threaded' library
+// variant is one where the implementation of the libc++ thread api is provided

compnerd wrote:
> Can you break this down into this which IMO is far more readable:
> 
> #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
> #if __libcpp_has_include()
> #include <__external_threading>
> #else
> // Why pthread?
> #define _LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD
> #endif
> #endif
> 
> #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) ||
> defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
> #include 
> #include 
> #endif
The reason I kept it in the current form is, when `__external_threading` is 
present, everything else in this header needs to be silenced. This is enforced 
by the current form because everything else in this header lives inside the 
`#else` side of the `__external_threading` inclusion.

Sure, the header will be a bit more readable if we arrange it the way you 
suggested, but then it's easy to add something to the header in a way that does 
not get removed when `__external_threading` is present.


https://reviews.llvm.org/D28229



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


[PATCH] D28229: [libcxx] Fix testing of the externally-threaded library build after r290850

2017-01-03 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

I will commit this now to get the testing working again. Thought of putting up 
the patch for review in case if there is a better way to do this.

@compnerd: I wondered, for windows threading support, why not do something 
similar to `__external_threading` (and how it is handled in 
`__threading_support`) and offload the entire implementation to a separate 
windows-only header?


https://reviews.llvm.org/D28229



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


[PATCH] D28229: [libcxx] Fix testing of the externally-threaded library build after r290850

2017-01-03 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: compnerd, EricWF.
rmaprath added a subscriber: cfe-commits.

Before r290850, building libcxx with `-DLIBCXX_HAS_EXTERNAL_THREAD_API=ON` had 
two uses:

- Allow platform vendors to plug-in an `__external_threading` header which 
should take care of the entire threading infrastructure of libcxx
- Allow testing of an externally-threaded library build; where the thread API 
is declared using pthread data structures, and the implementation of this API 
is provided as a separate library (`test/support/external_threads.cpp`) and 
linked-in when running the test suite.

r290850 breaks the second use case (pthread data structures are no longer 
available). This patch re-stores the ability to build+test an 
externally-threaded library variant on a pthread based system.

This wasn't caught on any of the official bots because we don't have any builds 
of the externally-threaded library build at the moment (apart from my 
downstream one).


https://reviews.llvm.org/D28229

Files:
  include/__threading_support
  test/support/external_threads.cpp


Index: test/support/external_threads.cpp
===
--- test/support/external_threads.cpp
+++ test/support/external_threads.cpp
@@ -6,5 +6,5 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 
//===--===//
-#define _LIBCPP_HAS_THREAD_API_PTHREAD
+#define _LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD
 #include <__threading_support>
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -28,11 +28,23 @@
 #endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
+!__libcpp_has_include(<__external_threading>)
+// If the <__external_threading> header is absent, build libc++ against a
+// pthread-oriented thread api but leave out its implementation. This setup
+// allows building+testing of an externally-threaded library variant (on any
+// platform that supports pthreads). Here, an 'externally-threaded' library
+// variant is one where the implementation of the libc++ thread api is provided
+// as a separate library.
+#define _LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD
+#endif
+
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
 __libcpp_has_include(<__external_threading>)
 #include <__external_threading>
 #else
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 #include 
 #include 
 #endif
@@ -45,7 +57,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 // Mutex
 typedef pthread_mutex_t __libcpp_mutex_t;
 #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@@ -134,7 +147,8 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 void __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
 
 int __libcpp_recursive_mutex_init(__libcpp_mutex_t *__m)
 {


Index: test/support/external_threads.cpp
===
--- test/support/external_threads.cpp
+++ test/support/external_threads.cpp
@@ -6,5 +6,5 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 //===--===//
-#define _LIBCPP_HAS_THREAD_API_PTHREAD
+#define _LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD
 #include <__threading_support>
Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -28,11 +28,23 @@
 #endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
+!__libcpp_has_include(<__external_threading>)
+// If the <__external_threading> header is absent, build libc++ against a
+// pthread-oriented thread api but leave out its implementation. This setup
+// allows building+testing of an externally-threaded library variant (on any
+// platform that supports pthreads). Here, an 'externally-threaded' library
+// variant is one where the implementation of the libc++ thread api is provided
+// as a separate library.
+#define _LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD
+#endif
+
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
 __libcpp_has_include(<__external_threading>)
 #include <__external_threading>
 #else
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 #include 
 #include 
 #endif
@@ -45,7 +57,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if 

[PATCH] D20874: [libcxx] Two more threading dependencies

2016-12-30 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath abandoned this revision.
rmaprath added a comment.

Most of this is no longer needed. I'll submit patches for the parts that are 
actually needed (e.g. nanosleep) later on. Thanks.


https://reviews.llvm.org/D20874



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


[PATCH] D27575: [libcxxabi] Introduce an externally threaded libc++abi variant (take-2)

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



Comment at: src/fallback_malloc.cpp:37
 class mutexor {
 public:

EricWF wrote:
> rmaprath wrote:
> > EricWF wrote:
> > > Can't we replace this class with `std::mutex` directly?
> > Again, I should've included more context to the patch :(
> > 
> > The `mutexor` here is supposed to degrade to a nop when threading is 
> > disabled. I think we cannot use `std::mutex` without threading support.
> > 
> > Will update the patch with more context.
> We cannot use `std::mutex` without threading support but I would still rather 
> use it.
> 
> I would `typedef std::lock_guard mutexor` when threading is 
> enabled and otherwise I would just `#ifdef` all usages away.
> 
> Also please add `_LIBCPP_SAFE_STATIC` to the heap_mutex declaration.
Hmmm, using `std::mutex` here breaks the shared library builds of `libcxxabi`. 
The problem is that methods like `std::mutex::lock()` and `~std::mutex()` are 
only declared in the `` header, with the implementation going into the 
dylib.

I was just about to update the patch because it worked for all my other 
configurations, but those configurations are either static builds or ones that 
suppress the `-Wl, -z defs` linker option passed to the shared library builds 
by default (this is an inherited option).

Perhaps it's time to get rid of `-Wl, -z defs` for all the `libcxxabi` 
configurations? That makes sense if `libcxxabi` is inherently dependent on 
`libcxx`.


https://reviews.llvm.org/D27575



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


[PATCH] D27575: [libcxxabi] Introduce an externally threaded libc++abi variant (take-2)

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

Ping.


https://reviews.llvm.org/D27575



___
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] D27575: [libcxxabi] Introduce an externally threaded libc++abi variant (take-2)

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

Gentle ping.


https://reviews.llvm.org/D27575



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


[PATCH] D27614: Mark tests as unsupported under libcpp-no-exceptions

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

LGTM. Needs approval from @EricWF or @mclow.lists.


https://reviews.llvm.org/D27614



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


[PATCH] D27575: [libcxxabi] Introduce an externally threaded libc++abi variant (take-2)

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

Patch updated with more context.


https://reviews.llvm.org/D27575



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


[PATCH] D27575: [libcxxabi] Introduce an externally threaded libc++abi variant (take-2)

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

https://reviews.llvm.org/D27575

Files:
  CMakeLists.txt
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/cxa_thread_atexit.cpp
  src/fallback_malloc.cpp
  src/threading_support.h
  test/CMakeLists.txt
  test/libcxxabi/test/config.py
  test/lit.site.cfg.in
  test/test_exception_storage.pass.cpp
  test/test_fallback_malloc.pass.cpp

Index: test/test_fallback_malloc.pass.cpp
===
--- test/test_fallback_malloc.pass.cpp
+++ test/test_fallback_malloc.pass.cpp
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-#include "../src/threading_support.h"
+#include <__threading_support>
 
 typedef std::deque container;
 
Index: test/test_exception_storage.pass.cpp
===
--- test/test_exception_storage.pass.cpp
+++ test/test_exception_storage.pass.cpp
@@ -12,7 +12,7 @@
 #include 
 #include 
 #include 
-#include "../src/threading_support.h"
+#include <__threading_support>
 #include 
 
 #include "../src/cxa_exception.hpp"
@@ -39,18 +39,18 @@
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 #define NUMTHREADS  10
 size_t thread_globals [ NUMTHREADS ] = { 0 };
-__libcxxabi_thread_t   threads[ NUMTHREADS ];
+std::__libcpp_thread_t   threads[ NUMTHREADS ];
 #endif
 
 int main ( int argc, char *argv [] ) {
 int retVal = 0;
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 //  Make the threads, let them run, and wait for them to finish
 for ( int i = 0; i < NUMTHREADS; ++i )
-__libcxxabi_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
+std::__libcpp_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
 for ( int i = 0; i < NUMTHREADS; ++i )
-__libcxxabi_thread_join (  [ i ] );
+std::__libcpp_thread_join (  [ i ] );
 
 for ( int i = 0; i < NUMTHREADS; ++i )
 if ( 0 == thread_globals [ i ] ) {
Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -19,6 +19,7 @@
 config.host_triple  = "@LLVM_HOST_TRIPLE@"
 config.target_triple= "@TARGET_TRIPLE@"
 config.use_target   = len("@LIBCXXABI_TARGET_TRIPLE@") > 0
+config.cxx_ext_threads  = "@LIBCXXABI_HAS_EXTERNAL_THREAD_API@"
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LIBCXXABI_SOURCE_DIR@/test/lit.cfg")
Index: test/libcxxabi/test/config.py
===
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -42,6 +42,9 @@
 self.config.available_features.add('libcxxabi-no-exceptions')
 if not self.has_cpp_feature('noexcept_function_type', 201510):
 self.config.available_features.add('libcxxabi-no-noexcept-function-type')
+# test_exception_storage_nodynmem.pass.cpp fails under this specific configuration
+if self.get_lit_bool('cxx_ext_threads', False) and self.get_lit_bool('libcxxabi_shared', False):
+self.config.available_features.add('libcxxabi-shared-externally-threaded')
 
 def configure_compile_flags(self):
 self.cxx.compile_flags += ['-DLIBCXXABI_NO_TIMER']
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -17,6 +17,7 @@
 pythonize_bool(LIBCXXABI_ENABLE_THREADS)
 pythonize_bool(LIBCXXABI_ENABLE_EXCEPTIONS)
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
+pythonize_bool(LIBCXXABI_HAS_EXTERNAL_THREAD_API)
 set(LIBCXXABI_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING
 "TargetInfo to use when setting up test environment.")
 set(LIBCXXABI_EXECUTOR "None" CACHE STRING
@@ -34,6 +35,10 @@
   set(LIBCXXABI_TEST_DEPS cxxabi_static)
 endif()
 
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  list(APPEND LIBCXXABI_TEST_DEPS cxx_external_threads)
+endif()
+
 if (NOT LIBCXXABI_STANDALONE_BUILD)
   list(APPEND LIBCXXABI_TEST_DEPS cxx)
   if (LIBCXXABI_USE_LLVM_UNWINDER)
Index: src/threading_support.h
===
--- src/threading_support.h
+++ /dev/null
@@ -1,107 +0,0 @@
-//=== threading_support.h -===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===--===//
-
-#ifndef _LIBCXXABI_THREADING_SUPPORT_H
-#define _LIBCXXABI_THREADING_SUPPORT_H
-
-#include "__cxxabi_config.h"
-#include "config.h"
-
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-
-#if defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
-#include 
-
-#define _LIBCXXABI_THREAD_ABI_VISIBILITY inline 

[PATCH] D27575: [libcxxabi] Introduce an externally threaded libc++abi variant (take-2)

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



Comment at: CMakeLists.txt:121
 option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of 
pthread API" OFF)
+option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
+  "Build libc++abi with an externalized threading API.

EricWF wrote:
> Maybe use a dependent option that sets it to the value of 
> `LIBCXX_ENABLE_THREADS` when it is defined?
Are you referring to `CMAKE_DEPENDENT_OPTION` macro? I don't see this macro 
used anywhere else in llvm, but I suppose that's not a concern?

Although, it would have to be something like:

```
CMAKE_DEPENDENT_OPTION(LIBCXXABI_HAS_EXTERNAL_THREAD_API "Externally Threaded 
libcxxabi" OFF  "LIBCXX_ENABLE_THREADS" OFF)
```

Because, `LIBCXX_ENABLE_THREADS=ON` should not mean 
`LIBCXXABI_HAS_EXTERNAL_THREAD_API=ON`.




Comment at: src/fallback_malloc.cpp:37
 class mutexor {
 public:

EricWF wrote:
> Can't we replace this class with `std::mutex` directly?
Again, I should've included more context to the patch :(

The `mutexor` here is supposed to degrade to a nop when threading is disabled. 
I think we cannot use `std::mutex` without threading support.

Will update the patch with more context.



Comment at: test/test_exception_storage.pass.cpp:42
 size_t thread_globals [ NUMTHREADS ] = { 0 };
-__libcxxabi_thread_t   threads[ NUMTHREADS ];
+std::__libcpp_thread_t   threads[ NUMTHREADS ];
 #endif

EricWF wrote:
> What happened to the initializer?
I don't think it needs one here?

`std::__licpp_thread_create()` does not require `std::__libcpp_thread_t` 
argument to be statically initialized.


https://reviews.llvm.org/D27575



___
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] D27206: [libcxx] Test support for the externally threaded libcxxabi variant

2016-12-08 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath abandoned this revision.
rmaprath added a comment.

Abandoning (replaced with 
https://reviews.llvm.org/D27575/https://reviews.llvm.org/D27576).


https://reviews.llvm.org/D27206



___
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 

[PATCH] D27204: [libcxxabi] Introduce an externally threaded libc++abi variant

2016-12-08 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath abandoned this revision.
rmaprath added a comment.

Abandoning as this has been replaced with https://reviews.llvm.org/D27575.


https://reviews.llvm.org/D27204



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


[PATCH] D27575: [libcxxabi] Introduce an externally threaded libc++abi variant (take-2)

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 is a replacement for https://reviews.llvm.org/D27204. Re-worked so that we 
use the threading API of `libcxx` instead of creating a whole new API for 
`libcxxabi`.


https://reviews.llvm.org/D27575

Files:
  CMakeLists.txt
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/cxa_thread_atexit.cpp
  src/fallback_malloc.cpp
  src/threading_support.h
  test/CMakeLists.txt
  test/libcxxabi/test/config.py
  test/lit.site.cfg.in
  test/test_exception_storage.pass.cpp
  test/test_fallback_malloc.pass.cpp

Index: test/test_fallback_malloc.pass.cpp
===
--- test/test_fallback_malloc.pass.cpp
+++ test/test_fallback_malloc.pass.cpp
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-#include "../src/threading_support.h"
+#include <__threading_support>
 
 typedef std::deque container;
 
Index: test/test_exception_storage.pass.cpp
===
--- test/test_exception_storage.pass.cpp
+++ test/test_exception_storage.pass.cpp
@@ -12,7 +12,7 @@
 #include 
 #include 
 #include 
-#include "../src/threading_support.h"
+#include <__threading_support>
 #include 
 
 #include "../src/cxa_exception.hpp"
@@ -39,7 +39,7 @@
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 #define NUMTHREADS  10
 size_t thread_globals [ NUMTHREADS ] = { 0 };
-__libcxxabi_thread_t   threads[ NUMTHREADS ];
+std::__libcpp_thread_t   threads[ NUMTHREADS ];
 #endif
 
 int main ( int argc, char *argv [] ) {
@@ -48,9 +48,9 @@
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 //  Make the threads, let them run, and wait for them to finish
 for ( int i = 0; i < NUMTHREADS; ++i )
-__libcxxabi_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
+std::__libcpp_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
 for ( int i = 0; i < NUMTHREADS; ++i )
-__libcxxabi_thread_join (  [ i ] );
+std::__libcpp_thread_join (  [ i ] );
 
 for ( int i = 0; i < NUMTHREADS; ++i )
 if ( 0 == thread_globals [ i ] ) {
Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -19,6 +19,7 @@
 config.host_triple  = "@LLVM_HOST_TRIPLE@"
 config.target_triple= "@TARGET_TRIPLE@"
 config.use_target   = len("@LIBCXXABI_TARGET_TRIPLE@") > 0
+config.cxx_ext_threads  = "@LIBCXXABI_HAS_EXTERNAL_THREAD_API@"
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LIBCXXABI_SOURCE_DIR@/test/lit.cfg")
Index: test/libcxxabi/test/config.py
===
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -42,6 +42,9 @@
 self.config.available_features.add('libcxxabi-no-exceptions')
 if not self.has_cpp_feature('noexcept_function_type', 201510):
 self.config.available_features.add('libcxxabi-no-noexcept-function-type')
+# test_exception_storage_nodynmem.pass.cpp fails under this specific configuration
+if self.get_lit_bool('cxx_ext_threads', False) and self.get_lit_bool('libcxxabi_shared', False):
+self.config.available_features.add('libcxxabi-shared-externally-threaded')
 
 def configure_compile_flags(self):
 self.cxx.compile_flags += ['-DLIBCXXABI_NO_TIMER']
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -17,6 +17,7 @@
 pythonize_bool(LIBCXXABI_ENABLE_THREADS)
 pythonize_bool(LIBCXXABI_ENABLE_EXCEPTIONS)
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
+pythonize_bool(LIBCXXABI_HAS_EXTERNAL_THREAD_API)
 set(LIBCXXABI_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING
 "TargetInfo to use when setting up test environment.")
 set(LIBCXXABI_EXECUTOR "None" CACHE STRING
@@ -34,6 +35,10 @@
   set(LIBCXXABI_TEST_DEPS cxxabi_static)
 endif()
 
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  list(APPEND LIBCXXABI_TEST_DEPS cxx_external_threads)
+endif()
+
 if (NOT LIBCXXABI_STANDALONE_BUILD)
   list(APPEND LIBCXXABI_TEST_DEPS cxx)
   if (LIBCXXABI_USE_LLVM_UNWINDER)
Index: src/threading_support.h
===
--- src/threading_support.h
+++ /dev/null
@@ -1,107 +0,0 @@
-//=== threading_support.h -===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===--===//
-
-#ifndef 

[PATCH] D27204: [libcxxabi] Introduce an externally threaded libc++abi variant

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

In https://reviews.llvm.org/D27204#613177, @EricWF wrote:

> In https://reviews.llvm.org/D27204#613172, @rmaprath wrote:
>
> > In https://reviews.llvm.org/D27204#613122, @EricWF wrote:
> >
> > > My main issue with this patch (and https://reviews.llvm.org/D27206) is 
> > > that there are now two different CMake options for building two different 
> > > external threading libraries. I would much prefer having libc++abi use 
> > > libc++'s `__threading_support` header and `cxx_external_threads` library.
> >
> >
> > I would like to do that too!
> >
> > But I always viewed `libcxx` and `libcxxabi` as two independent libraries 
> > that should be usable on their own. In this case, binding `libcxxabi` to 
> > `__threading_support` from `libcxx` sounded wrong, because 
> > `__threading_support` is something internal to `libcxx` (e.g. all the 
> > functions there are prefixed with `__libcpp_` - there may be other 
> > `libcpp`-isms arising from `__config` in there too).
>
>
> Ironically I've always viewed `libcxxabi` as fully dependent on `libcxx` (and 
> personally I would like to see the repos merged; Although using libc++ w/o 
> libc++abi would still be supported).
>
> 
>
> > Is that not a concern? I could give it a shot and try to merge the two APIs 
> > into one if not.
>
> It's not a concern. Libc++abi already depends on libc++ internals to build 
> (See the `#include "__refstring" in `stdlib_stdexcept.cpp`).


Thanks for the clarification. I'll re-spin the patch.

Responses to inline comments follow, but some of those would go away with the 
re-spin I imagine.




Comment at: CMakeLists.txt:124
+  This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
+option(LIBCXX_HAS_EXTERNAL_THREAD_API
+  "Build libc++ with an externalized threading API.

EricWF wrote:
> It's weird that libc++abi needs to define a libc++ option? Can you elaborate 
> on the need for this?
The `libcxxabi` test suite builds `libcxx` as part of running the test suite, I 
thought a separate option would be appropriate here to allow users to select 
which configuration they want to build `libcxx` for those tests. 

Given the new knowledge I have, I think the right thing to do here is configure 
`libcxx` to also use external threads when `libcxxabi` is configured to use 
external threads, rather than providing a separate option here. Will fix.



Comment at: src/CMakeLists.txt:132
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  file(GLOB LIBCXXABI_EXTERNAL_THREADING_SUPPORT_SOURCES 
../test/support/external_threads.cpp)
+

EricWF wrote:
> Do you really need to glob a single file?
Copy-paste, will fix.



Comment at: test/CMakeLists.txt:41
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  list(APPEND LIBCXXABI_TEST_DEPS "cxxabi_external_threads")
+endif()

EricWF wrote:
> Target names shouldn't be in quotes.
Will fix.



Comment at: test/CMakeLists.txt:45
+if (LIBCXX_HAS_EXTERNAL_THREAD_API)
+  list(APPEND LIBCXXABI_TEST_DEPS "cxx_external_threads")
+endif()

EricWF wrote:
> For the in-tree libc++/libc++abi builds libc++abi gets configured before 
> libc++, so I don't think libc++ target names are visible in this context.
> Are you sure this works?
This worked fine for me. All my builds are in-tree as well.

I also checked if the order in which tests are run (whether `libcxx` runs 
before `libcxxabi` and vice-versa) makes no difference.

I will double check still.



Comment at: test/libcxxabi/test/config.py:43
+# test_exception_storage_nodynmem.pass.cpp fails under this specific 
configuration
+if self.get_lit_bool('cxxabi_ext_threads', False) and 
self.get_lit_bool('libcxxabi_shared', False):
+
self.config.available_features.add('libcxxabi-shared-externally-threaded')

EricWF wrote:
> `libcxxabi_shared` should default to `True` like it does within the libc++ 
> config.
> 
Not sure if I follow, I'm trying to detect this particular combination of 
configs so that I can xfail a particular test.



Comment at: test/lit.cfg:21
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.cpp', '.s']
+config.suffixes = ['.pass.cpp', '.sh.s', '.sh.cpp']
 

EricWF wrote:
> I'm not sure I understand the reason for this change.
I should've put a comment. The test suite keeps trying to run 
`test/support/external_threading.cpp` as a test case without this. Perhaps 
there is a better way to handle that situation?


https://reviews.llvm.org/D27204



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


[PATCH] D27204: [libcxxabi] Introduce an externally threaded libc++abi variant

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

In https://reviews.llvm.org/D27204#613122, @EricWF wrote:

> My main issue with this patch (and https://reviews.llvm.org/D27206) is that 
> there are now two different CMake options for building two different external 
> threading libraries. I would much prefer having libc++abi use libc++'s 
> `__threading_support` header and `cxx_external_threads` library.


I would like to do that too!

But I always viewed `libcxx` and `libcxxabi` as two independent libraries that 
should be usable on their own. In this case, binding `libcxxabi` to 
`__threading_support` from `libcxx` sounded wrong, because 
`__threading_support` is something internal to `libcxx` (e.g. all the functions 
there are prefixed with `__libcpp_` - there may be other `libcpp`-isms arising 
from `__config` in there too).

Is that not a concern? I could give it a shot and try to merge the two APIs 
into one if not.


https://reviews.llvm.org/D27204



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


[PATCH] D27204: [libcxxabi] Introduce an externally threaded libc++abi variant

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

This is more-or-less a mirror image of https://reviews.llvm.org/D21968, 
repeated for libcxxabi.

I will soon upload a dependent patch for libcxx which makes it possible to run 
the libcxx test suite with the externally-threaded libcxxabi variant.


https://reviews.llvm.org/D27204

Files:
  CMakeLists.txt
  src/CMakeLists.txt
  src/config.h
  src/threading_support.h
  test/CMakeLists.txt
  test/libcxxabi/test/config.py
  test/lit.cfg
  test/lit.site.cfg.in
  test/support/external_threads.cpp

Index: test/support/external_threads.cpp
===
--- /dev/null
+++ test/support/external_threads.cpp
@@ -0,0 +1,10 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+#define _LIBCXXABI_BUILDING_EXTERNAL_THREADS
+#include 
Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -19,6 +19,8 @@
 config.host_triple  = "@LLVM_HOST_TRIPLE@"
 config.target_triple= "@TARGET_TRIPLE@"
 config.use_target   = len("@LIBCXXABI_TARGET_TRIPLE@") > 0
+config.cxx_ext_threads  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
+config.cxxabi_ext_threads   = "@LIBCXXABI_HAS_EXTERNAL_THREAD_API@"
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LIBCXXABI_SOURCE_DIR@/test/lit.cfg")
Index: test/lit.cfg
===
--- test/lit.cfg
+++ test/lit.cfg
@@ -18,7 +18,7 @@
 config.name = 'libc++abi'
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.cpp', '.s']
+config.suffixes = ['.pass.cpp', '.sh.s', '.sh.cpp']
 
 # test_source_root: The root path where tests are located.
 config.test_source_root = os.path.dirname(__file__)
Index: test/libcxxabi/test/config.py
===
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -39,6 +39,9 @@
 self.config.available_features.add('libcxxabi-no-exceptions')
 if not self.cxx.addCompileFlagIfSupported(['-Xclang', '-mqualified-function-type-info']):
 self.config.available_features.add("libcxxabi-no-qualified-function-types")
+# test_exception_storage_nodynmem.pass.cpp fails under this specific configuration
+if self.get_lit_bool('cxxabi_ext_threads', False) and self.get_lit_bool('libcxxabi_shared', False):
+self.config.available_features.add('libcxxabi-shared-externally-threaded')
 
 def configure_compile_flags(self):
 self.cxx.compile_flags += ['-DLIBCXXABI_NO_TIMER']
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -17,6 +17,9 @@
 pythonize_bool(LIBCXXABI_ENABLE_THREADS)
 pythonize_bool(LIBCXXABI_ENABLE_EXCEPTIONS)
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
+pythonize_bool(LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
+pythonize_bool(LIBCXX_HAS_EXTERNAL_THREAD_API)
+pythonize_bool(LIBCXXABI_HAS_EXTERNAL_THREAD_API)
 set(LIBCXXABI_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING
 "TargetInfo to use when setting up test environment.")
 set(LIBCXXABI_EXECUTOR "None" CACHE STRING
@@ -34,6 +37,14 @@
   set(LIBCXXABI_TEST_DEPS cxxabi_static)
 endif()
 
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  list(APPEND LIBCXXABI_TEST_DEPS "cxxabi_external_threads")
+endif()
+
+if (LIBCXX_HAS_EXTERNAL_THREAD_API)
+  list(APPEND LIBCXXABI_TEST_DEPS "cxx_external_threads")
+endif()
+
 if (NOT LIBCXXABI_STANDALONE_BUILD)
   list(APPEND LIBCXXABI_TEST_DEPS cxx)
   if (LIBCXXABI_USE_LLVM_UNWINDER)
Index: src/threading_support.h
===
--- src/threading_support.h
+++ src/threading_support.h
@@ -15,93 +15,149 @@
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 
-#if defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
+#ifndef __libcxxabi_has_include
+  #ifndef __has_include
+#define __libcxxabi_has_include(x) 0
+  #else
+#define __libcxxabi_has_include(x) __has_include(x)
+  #endif
+#endif
+
+#if defined(_LIBCXXABI_HAS_THREAD_API_EXTERNAL) && \
+__libcxxabi_has_include()
+#include 
+#else
 #include 
 
+#if defined(_LIBCXXABI_HAS_THREAD_API_EXTERNAL)
+#define _LIBCXXABI_THREAD_ABI_VISIBILITY _LIBCXXABI_FUNC_VIS
+#else
 #define _LIBCXXABI_THREAD_ABI_VISIBILITY inline _LIBCXXABI_INLINE_VISIBILITY
+#endif
 
 // Mutex
 typedef pthread_mutex_t __libcxxabi_mutex_t;