Path: blob/main/contrib/llvm-project/libcxx/src/random_shuffle.cpp
35154 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include <algorithm>9#include <random>1011#ifndef _LIBCPP_HAS_NO_THREADS12# include <mutex>13# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)14# pragma comment(lib, "pthread")15# endif16#endif1718_LIBCPP_BEGIN_NAMESPACE_STD1920#ifndef _LIBCPP_HAS_NO_THREADS21static constinit __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;22#endif23unsigned __rs_default::__c_ = 0;2425__rs_default::__rs_default() {26#ifndef _LIBCPP_HAS_NO_THREADS27__libcpp_mutex_lock(&__rs_mut);28#endif29__c_ = 1;30}3132__rs_default::__rs_default(const __rs_default&) { ++__c_; }3334__rs_default::~__rs_default() {35#ifndef _LIBCPP_HAS_NO_THREADS36if (--__c_ == 0)37__libcpp_mutex_unlock(&__rs_mut);38#else39--__c_;40#endif41}4243__rs_default::result_type __rs_default::operator()() {44static mt19937 __rs_g;45return __rs_g();46}4748__rs_default __rs_get() { return __rs_default(); }4950_LIBCPP_END_NAMESPACE_STD515253