[libcxx-commits] [PATCH] D113065: [libcxx][SystemZ][z/OS] Update libcxx/src/debug.cpp to accommodate POSIX(OFF)

Daniel McIntosh via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 2 15:13:32 PDT 2021


DanielMcIntosh-IBM created this revision.
DanielMcIntosh-IBM added reviewers: Quuxplusone, EricWF, jroelofs, mclow.lists, ldionne.
DanielMcIntosh-IBM requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Use a wrapper class around std::mutex to prevent calls to mutex functions when
the threading API is disabled.

Depends on D110349 <https://reviews.llvm.org/D110349>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113065

Files:
  libcxx/src/debug.cpp


Index: libcxx/src/debug.cpp
===================================================================
--- libcxx/src/debug.cpp
+++ libcxx/src/debug.cpp
@@ -62,7 +62,31 @@
 {
 
 #ifndef _LIBCPP_HAS_NO_THREADS
-typedef mutex mutex_type;
+/// Simple wrapper around std::mutex that checks threads are enabled before doing anything.
+class mutex_check_threading : public mutex {
+    /// Threads enabled/disabled status should not change over the life of the process.
+    static const bool threadsEnabled;
+
+  public:
+    void lock() {
+        if (!threadsEnabled)
+            return;
+        mutex::lock();
+    }
+    bool try_lock() {
+        if (!threadsEnabled)
+            return true;
+        return mutex::try_lock();
+    }
+    void unlock() {
+        if (!threadsEnabled)
+            return;
+        mutex::unlock();
+    }
+};
+const bool mutex_check_threading::threadsEnabled = __libcpp_are_threads_enabled();
+
+typedef mutex_check_threading mutex_type;
 typedef lock_guard<mutex_type> WLock;
 typedef lock_guard<mutex_type> RLock;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113065.384257.patch
Type: text/x-patch
Size: 1049 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211102/bfe1d53f/attachment.bin>


More information about the libcxx-commits mailing list