[libcxx-commits] [libcxx] ce6153a - [libc++] Split dylib instantiations for deprecated std::random_shuffle into a separate source file

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 30 10:50:37 PDT 2020


Author: Louis Dionne
Date: 2020-06-30T13:50:17-04:00
New Revision: ce6153a5282c2a66a814ac321d5af442cbb5614a

URL: https://github.com/llvm/llvm-project/commit/ce6153a5282c2a66a814ac321d5af442cbb5614a
DIFF: https://github.com/llvm/llvm-project/commit/ce6153a5282c2a66a814ac321d5af442cbb5614a.diff

LOG: [libc++] Split dylib instantiations for deprecated std::random_shuffle into a separate source file

That makes it easier to exclude from the build if one wants to build libc++
without support for the deprecated std::random_shuffle.

Added: 
    libcxx/src/random_shuffle.cpp

Modified: 
    libcxx/src/CMakeLists.txt
    libcxx/src/algorithm.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 898ec027f326..3e48d96f44cf 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -29,6 +29,7 @@ set(LIBCXX_SOURCES
   new.cpp
   optional.cpp
   random.cpp
+  random_shuffle.cpp
   regex.cpp
   shared_mutex.cpp
   stdexcept.cpp

diff  --git a/libcxx/src/algorithm.cpp b/libcxx/src/algorithm.cpp
index 40669fb9e756..9f11dc38b15b 100644
--- a/libcxx/src/algorithm.cpp
+++ b/libcxx/src/algorithm.cpp
@@ -7,13 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "algorithm"
-#include "random"
-#ifndef _LIBCPP_HAS_NO_THREADS
-#include "mutex"
-#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
-#endif
-#endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -51,45 +44,4 @@ template bool __insertion_sort_incomplete<__less<long double>&, long double*>(lo
 
 template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
 
-#ifndef _LIBCPP_HAS_NO_THREADS
-_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
-#endif
-unsigned __rs_default::__c_ = 0;
-
-__rs_default::__rs_default()
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
-    __libcpp_mutex_lock(&__rs_mut);
-#endif
-    __c_ = 1;
-}
-
-__rs_default::__rs_default(const __rs_default&)
-{
-    ++__c_;
-}
-
-__rs_default::~__rs_default()
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
-    if (--__c_ == 0)
-       __libcpp_mutex_unlock(&__rs_mut);
-#else
-    --__c_;
-#endif
-}
-
-__rs_default::result_type
-__rs_default::operator()()
-{
-    static mt19937 __rs_g;
-    return __rs_g();
-}
-
-__rs_default
-__rs_get()
-{
-    return __rs_default();
-}
-
 _LIBCPP_END_NAMESPACE_STD

diff  --git a/libcxx/src/random_shuffle.cpp b/libcxx/src/random_shuffle.cpp
new file mode 100644
index 000000000000..be2c47fa0def
--- /dev/null
+++ b/libcxx/src/random_shuffle.cpp
@@ -0,0 +1,61 @@
+//===----------------------- random_shuffle.cpp ---------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "algorithm"
+#include "random"
+#ifndef _LIBCPP_HAS_NO_THREADS
+#   include "mutex"
+#   if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
+#       pragma comment(lib, "pthread")
+#   endif
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
+#endif
+unsigned __rs_default::__c_ = 0;
+
+__rs_default::__rs_default()
+{
+#ifndef _LIBCPP_HAS_NO_THREADS
+    __libcpp_mutex_lock(&__rs_mut);
+#endif
+    __c_ = 1;
+}
+
+__rs_default::__rs_default(const __rs_default&)
+{
+    ++__c_;
+}
+
+__rs_default::~__rs_default()
+{
+#ifndef _LIBCPP_HAS_NO_THREADS
+    if (--__c_ == 0)
+       __libcpp_mutex_unlock(&__rs_mut);
+#else
+    --__c_;
+#endif
+}
+
+__rs_default::result_type
+__rs_default::operator()()
+{
+    static mt19937 __rs_g;
+    return __rs_g();
+}
+
+__rs_default
+__rs_get()
+{
+    return __rs_default();
+}
+
+_LIBCPP_END_NAMESPACE_STD


        


More information about the libcxx-commits mailing list