[llvm] r369056 - [Support] Re-introduce the RWMutexImpl for macOS < 10.12

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 15:19:38 PDT 2019


Author: jdevlieghere
Date: Thu Aug 15 15:19:38 2019
New Revision: 369056

URL: http://llvm.org/viewvc/llvm-project?rev=369056&view=rev
Log:
[Support] Re-introduce the RWMutexImpl for macOS < 10.12

In r369018, Benjamin replaced the custom RWMutex implementation with
their C++14 counterpart. Unfortunately, std::shared_timed_mutex is only
available on macOS 10.12 and later. This prevents LLVM from compiling
even on newer versions of the OS when you have an older deployment
target. This patch reintroduced the old RWMutexImpl but guards it by the
macOS availability macro.

Differential revision: https://reviews.llvm.org/rL369018

Modified:
    llvm/trunk/include/llvm/Support/RWMutex.h

Modified: llvm/trunk/include/llvm/Support/RWMutex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/RWMutex.h?rev=369056&r1=369055&r2=369056&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/RWMutex.h (original)
+++ llvm/trunk/include/llvm/Support/RWMutex.h Thu Aug 15 15:19:38 2019
@@ -32,8 +32,71 @@ namespace sys {
 #if defined(_MSC_VER) || __cplusplus > 201402L
       std::shared_mutex impl;
 #else
+      // std::shared_timed_mutex is only availble on macOS 10.12 and later.
+#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                  \
+    defined(__MAC_10_12) &&                                                    \
+    __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < __MAC_10_12
+      /// Platform agnostic RWMutex class.
+      /// Platform agnostic RWMutex class.
+      class RWMutexImpl {
+        /// @name Constructors
+        /// @{
+      public:
+        /// Initializes the lock but doesn't acquire it.
+        /// Default Constructor.
+        explicit RWMutexImpl();
+
+        /// @}
+        /// @name Do Not Implement
+        /// @{
+        RWMutexImpl(const RWMutexImpl &original) = delete;
+        RWMutexImpl &operator=(const RWMutexImpl &) = delete;
+        /// @}
+
+        /// Releases and removes the lock
+        /// Destructor
+        ~RWMutexImpl();
+
+        /// @}
+        /// @name Methods
+        /// @{
+      public:
+        /// Attempts to unconditionally acquire the lock in reader mode. If the
+        /// lock is held by a writer, this method will wait until it can acquire
+        /// the lock.
+        /// @returns false if any kind of error occurs, true otherwise.
+        /// Unconditionally acquire the lock in reader mode.
+        bool reader_acquire();
+
+        /// Attempts to release the lock in reader mode.
+        /// @returns false if any kind of error occurs, true otherwise.
+        /// Unconditionally release the lock in reader mode.
+        bool reader_release();
+
+        /// Attempts to unconditionally acquire the lock in reader mode. If the
+        /// lock is held by any readers, this method will wait until it can
+        /// acquire the lock.
+        /// @returns false if any kind of error occurs, true otherwise.
+        /// Unconditionally acquire the lock in writer mode.
+        bool writer_acquire();
+
+        /// Attempts to release the lock in writer mode.
+        /// @returns false if any kind of error occurs, true otherwise.
+        /// Unconditionally release the lock in write mode.
+        bool writer_release();
+
+        //@}
+        /// @name Platform Dependent Data
+        /// @{
+      private:
+#if defined(LLVM_ENABLE_THREADS) && LLVM_ENABLE_THREADS != 0
+        void *data_ = nullptr; ///< We don't know what the data will be
+#endif
+      } impl;
+#else
       std::shared_timed_mutex impl;
 #endif
+#endif
       unsigned readers = 0;
       unsigned writers = 0;
 




More information about the llvm-commits mailing list