Check for std::this_thread::sleep_for.
authorPeter Griess <pgriess@fb.com>
Wed, 9 Oct 2013 03:57:32 +0000 (20:57 -0700)
committerSara Golemon <sgolemon@fb.com>
Thu, 24 Oct 2013 21:53:41 +0000 (14:53 -0700)
Summary:
- Some installations of libstdc++ don't have this defined. This happens
if they were built without --enable-libstdcxx-time. Detect this and
avoid tests that rely on this behavior.

Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Ubuntu/FC/Mac

Reviewed By: meyering@fb.com

FB internal diff: D1002963

folly/configure.ac
folly/test/ThreadLocalTest.cpp

index 29ae18fd3f5a83dbacba3c70e2978e47e28102d1..1b5e7b10fb84e16885fd32b7a90597985b78fe5c 100644 (file)
@@ -78,6 +78,15 @@ AC_COMPILE_IFELSE(
    AC_DEFINE([OVERRIDE], [],
              [Define to "override" if the compiler supports C++11 "override"])]
 )
+
+AC_COMPILE_IFELSE(
+  [AC_LANG_SOURCE[
+    #include <thread>
+    #include <chrono>
+    void func() { std::this_thread::sleep_for(std::chrono::seconds(1)); }]],
+  [AC_DEFINE([HAVE_STD__THIS_THREAD__SLEEP_FOR], [1],
+             [Define to 1 if std::this_thread::sleep_for() is defined.])])
+
 AC_COMPILE_IFELSE(
   [AC_LANG_SOURCE[
     #include <type_traits>
index b9f69a0fd812e1485545be7d1c3c34b73ef76670..d78e07eac2156e625437b4452c908cd418f04603 100644 (file)
@@ -346,6 +346,7 @@ class FillObject {
 
 }  // namespace
 
+#if FOLLY_HAVE_STD__THIS_THREAD__SLEEP_FOR
 TEST(ThreadLocal, Stress) {
   constexpr size_t numFillObjects = 250;
   std::array<ThreadLocalPtr<FillObject>, numFillObjects> objects;
@@ -376,6 +377,7 @@ TEST(ThreadLocal, Stress) {
 
   EXPECT_EQ(numFillObjects * numThreads * numReps, gDestroyed);
 }
+#endif
 
 // Yes, threads and fork don't mix
 // (http://cppwisdom.quora.com/Why-threads-and-fork-dont-mix) but if you're