Add a C++11 ThreadPool implementation in LLVM
[oota-llvm.git] / unittests / Support / ManagedStatic.cpp
index b1df2bd6d211561b129b0e8c1690196496543eca..153884ba42986a9d32e5d1bd241f176cad1d20b9 100644 (file)
@@ -19,12 +19,13 @@ using namespace llvm;
 
 namespace {
 
-#ifdef HAVE_PTHREAD_H
+#if LLVM_ENABLE_THREADS != 0 && defined(HAVE_PTHREAD_H) && \
+  !__has_feature(memory_sanitizer)
 namespace test1 {
   llvm::ManagedStatic<int> ms;
   void *helper(void*) {
     *ms;
-    return NULL;
+    return nullptr;
   }
 
   // Valgrind's leak checker complains glibc's stack allocation.
@@ -32,7 +33,9 @@ namespace test1 {
   void *allocate_stack(pthread_attr_t &a, size_t n = 65536) {
     void *stack = malloc(n);
     pthread_attr_init(&a);
+#if defined(__linux__)
     pthread_attr_setstack(&a, stack, n);
+#endif
     return stack;
   }
 }
@@ -44,15 +47,13 @@ TEST(Initialize, MultipleThreads) {
   void *p1 = test1::allocate_stack(a1);
   void *p2 = test1::allocate_stack(a2);
 
-  llvm_start_multithreaded();
   pthread_t t1, t2;
-  pthread_create(&t1, &a1, test1::helper, NULL);
-  pthread_create(&t2, &a2, test1::helper, NULL);
-  pthread_join(t1, NULL);
-  pthread_join(t2, NULL);
+  pthread_create(&t1, &a1, test1::helper, nullptr);
+  pthread_create(&t2, &a2, test1::helper, nullptr);
+  pthread_join(t1, nullptr);
+  pthread_join(t2, nullptr);
   free(p1);
   free(p2);
-  llvm_stop_multithreaded();
 }
 #endif