aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxxmsvc/src/random_shuffle.cpp
diff options
context:
space:
mode:
authormikhnenko <mikhnenko@yandex-team.com>2023-09-20 11:01:13 +0300
committermikhnenko <mikhnenko@yandex-team.com>2023-09-20 11:29:08 +0300
commitf5b051f5e09f00265229985ba5fd47aa5c8959ff (patch)
tree7e11605ad566f09451623a1ac34cc644bae804ab /contrib/libs/cxxsupp/libcxxmsvc/src/random_shuffle.cpp
parent8ed995cdfb22a3dfa790b0a6ae7750d9dc85db7b (diff)
downloadydb-f5b051f5e09f00265229985ba5fd47aa5c8959ff.tar.gz
Split libcxx on msvc/other
Diffstat (limited to 'contrib/libs/cxxsupp/libcxxmsvc/src/random_shuffle.cpp')
-rw-r--r--contrib/libs/cxxsupp/libcxxmsvc/src/random_shuffle.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/contrib/libs/cxxsupp/libcxxmsvc/src/random_shuffle.cpp b/contrib/libs/cxxsupp/libcxxmsvc/src/random_shuffle.cpp
new file mode 100644
index 0000000000..a673035b48
--- /dev/null
+++ b/contrib/libs/cxxsupp/libcxxmsvc/src/random_shuffle.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+static _LIBCPP_CONSTINIT __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