brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 4f2669a Raw
52 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include <algorithm>10#include <random>11 12#if _LIBCPP_HAS_THREADS13#  include <mutex>14#  if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)15#    pragma comment(lib, "pthread")16#  endif17#endif18 19_LIBCPP_BEGIN_NAMESPACE_STD20 21#if _LIBCPP_HAS_THREADS22static constinit __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;23#endif24unsigned __rs_default::__c_ = 0;25 26__rs_default::__rs_default() {27#if _LIBCPP_HAS_THREADS28  __libcpp_mutex_lock(&__rs_mut);29#endif30  __c_ = 1;31}32 33__rs_default::__rs_default(const __rs_default&) { ++__c_; }34 35__rs_default::~__rs_default() {36#if _LIBCPP_HAS_THREADS37  if (--__c_ == 0)38    __libcpp_mutex_unlock(&__rs_mut);39#else40  --__c_;41#endif42}43 44__rs_default::result_type __rs_default::operator()() {45  static mt19937 __rs_g;46  return __rs_g();47}48 49__rs_default __rs_get() { return __rs_default(); }50 51_LIBCPP_END_NAMESPACE_STD52