[libcxx-commits] [PATCH] D61087: [libcxxabi] Fix build of cxa_guard.cpp on configurations with _LIBCXXABI_HAS_NO_THREADS

James Nagurne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Apr 24 13:09:08 PDT 2019


JamesNagurne created this revision.
JamesNagurne added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, christof.
Herald added a project: libc++.

Fix build of cxa_guard.cpp on configurations with _LIBCXXABI_HAS_NO_THREADS

cxa_guard_impl.h currently contains a forward declaration of two classes,
LibcppMutex and LibcppCondVar, whose definitions are guarded by
!defined(_LIBCXXABI_HAS_NO_THREADS). When this configuration is set, the
definitions are not seen, and the compiler emits an error when the
incomplete types are used.

I've refined the locations of the guards around these definitions to only the
spots where not having thread support matters, and have stubbed those
definitions with the expected return code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61087

Files:
  libcxxabi/src/cxa_guard_impl.h


Index: libcxxabi/src/cxa_guard_impl.h
===================================================================
--- libcxxabi/src/cxa_guard_impl.h
+++ libcxxabi/src/cxa_guard_impl.h
@@ -230,18 +230,24 @@
 struct LibcppMutex;
 struct LibcppCondVar;
 
-#ifndef _LIBCXXABI_HAS_NO_THREADS
 struct LibcppMutex {
   LibcppMutex() = default;
   LibcppMutex(LibcppMutex const&) = delete;
   LibcppMutex& operator=(LibcppMutex const&) = delete;
 
+#ifndef _LIBCXXABI_HAS_NO_THREADS
   bool lock() { return std::__libcpp_mutex_lock(&mutex); }
   bool unlock() { return std::__libcpp_mutex_unlock(&mutex); }
+#else
+  bool lock() { return 0; }
+  bool unlock() { return 0; }
+#endif
 
 private:
   friend struct LibcppCondVar;
+#ifndef _LIBCXXABI_HAS_NO_THREADS
   std::__libcpp_mutex_t mutex = _LIBCPP_MUTEX_INITIALIZER;
+#endif
 };
 
 struct LibcppCondVar {
@@ -249,15 +255,23 @@
   LibcppCondVar(LibcppCondVar const&) = delete;
   LibcppCondVar& operator=(LibcppCondVar const&) = delete;
 
+#ifndef _LIBCXXABI_HAS_NO_THREADS
   bool wait(LibcppMutex& mut) {
     return std::__libcpp_condvar_wait(&cond, &mut.mutex);
   }
   bool broadcast() { return std::__libcpp_condvar_broadcast(&cond); }
+#else
+  bool wait(LibcppMutex& mut) {
+    return 0;
+  }
+  bool broadcast() { return 0; }
+#endif
 
 private:
+#ifndef _LIBCXXABI_HAS_NO_THREADS
   std::__libcpp_condvar_t cond = _LIBCPP_CONDVAR_INITIALIZER;
+#endif
 };
-#endif // !defined(_LIBCXXABI_HAS_NO_THREADS)
 
 
 template <class Mutex, class CondVar, Mutex& global_mutex, CondVar& global_cond,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61087.196506.patch
Type: text/x-patch
Size: 1536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190424/c4ac4695/attachment.bin>


More information about the libcxx-commits mailing list