diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-05-26 17:49:34 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-26 17:49:34 +0000 |
commit | f9d540b0624ff755e1903a9a8a708d5ea8190386 (patch) | |
tree | f1fcffffa7b8ad195a60ecc05843f36d7c762b1a /libcxx/src/algorithm.cpp | |
parent | a19838e1076f361c3fde481c515f60a13a64b19f (diff) | |
download | bcm5719-llvm-f9d540b0624ff755e1903a9a8a708d5ea8190386.tar.gz bcm5719-llvm-f9d540b0624ff755e1903a9a8a708d5ea8190386.zip |
Completed [alg.random.shuffle].
llvm-svn: 104708
Diffstat (limited to 'libcxx/src/algorithm.cpp')
-rw-r--r-- | libcxx/src/algorithm.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libcxx/src/algorithm.cpp b/libcxx/src/algorithm.cpp index fd81521494e..c688bae0c47 100644 --- a/libcxx/src/algorithm.cpp +++ b/libcxx/src/algorithm.cpp @@ -8,6 +8,8 @@ //===----------------------------------------------------------------------===// #include "algorithm" +#include "random" +#include "mutex" _LIBCPP_BEGIN_NAMESPACE_STD @@ -45,4 +47,37 @@ 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>&); +static pthread_mutex_t __rs_mut = PTHREAD_MUTEX_INITIALIZER; +unsigned __rs_default::__c_ = 0; + +__rs_default::__rs_default() +{ + pthread_mutex_lock(&__rs_mut); + __c_ = 1; +} + +__rs_default::__rs_default(const __rs_default&) +{ + ++__c_; +} + +__rs_default::~__rs_default() +{ + if (--__c_ == 0) + pthread_mutex_unlock(&__rs_mut); +} + +__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 |