Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------- algorithm.cpp --------------------------------===// |
| 2 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "algorithm" |
Howard Hinnant | 578ac0f | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 10 | #include "random" |
Petr Hosek | 99575aa | 2019-05-30 01:34:41 +0000 | [diff] [blame] | 11 | #ifndef _LIBCPP_HAS_NO_THREADS |
Howard Hinnant | 578ac0f | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 12 | #include "mutex" |
Michał Górny | 8d676fb | 2019-12-02 11:49:20 +0100 | [diff] [blame] | 13 | #if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB) |
Petr Hosek | 99575aa | 2019-05-30 01:34:41 +0000 | [diff] [blame] | 14 | #pragma comment(lib, "pthread") |
| 15 | #endif |
| 16 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 17 | |
| 18 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 19 | |
| 20 | template void __sort<__less<char>&, char*>(char*, char*, __less<char>&); |
| 21 | template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&); |
| 22 | template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&); |
| 23 | template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&); |
| 24 | template void __sort<__less<short>&, short*>(short*, short*, __less<short>&); |
| 25 | template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&); |
| 26 | template void __sort<__less<int>&, int*>(int*, int*, __less<int>&); |
| 27 | template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&); |
| 28 | template void __sort<__less<long>&, long*>(long*, long*, __less<long>&); |
| 29 | template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&); |
| 30 | template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&); |
| 31 | template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&); |
| 32 | template void __sort<__less<float>&, float*>(float*, float*, __less<float>&); |
| 33 | template void __sort<__less<double>&, double*>(double*, double*, __less<double>&); |
| 34 | template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&); |
| 35 | |
| 36 | template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&); |
| 37 | template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&); |
| 38 | template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&); |
| 39 | template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&); |
| 40 | template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&); |
| 41 | template bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&); |
| 42 | template bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&); |
| 43 | template bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&); |
| 44 | template bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&); |
| 45 | template bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&); |
| 46 | template bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&); |
| 47 | template bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&); |
| 48 | template bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&); |
| 49 | template bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&); |
| 50 | template bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&); |
| 51 | |
| 52 | template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&); |
| 53 | |
Jonathan Roelofs | 39cb6bf | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 54 | #ifndef _LIBCPP_HAS_NO_THREADS |
Eric Fiselier | 637dd95 | 2016-09-28 22:08:13 +0000 | [diff] [blame] | 55 | _LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER; |
Jonathan Roelofs | 39cb6bf | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 56 | #endif |
Howard Hinnant | 578ac0f | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 57 | unsigned __rs_default::__c_ = 0; |
| 58 | |
| 59 | __rs_default::__rs_default() |
| 60 | { |
Jonathan Roelofs | 39cb6bf | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 61 | #ifndef _LIBCPP_HAS_NO_THREADS |
Asiri Rathnayake | fa2e203 | 2016-05-06 14:06:29 +0000 | [diff] [blame] | 62 | __libcpp_mutex_lock(&__rs_mut); |
Jonathan Roelofs | 39cb6bf | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 63 | #endif |
Howard Hinnant | 578ac0f | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 64 | __c_ = 1; |
| 65 | } |
| 66 | |
| 67 | __rs_default::__rs_default(const __rs_default&) |
| 68 | { |
| 69 | ++__c_; |
| 70 | } |
| 71 | |
| 72 | __rs_default::~__rs_default() |
| 73 | { |
Jonathan Roelofs | 39cb6bf | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 74 | #ifndef _LIBCPP_HAS_NO_THREADS |
Howard Hinnant | 578ac0f | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 75 | if (--__c_ == 0) |
Asiri Rathnayake | fa2e203 | 2016-05-06 14:06:29 +0000 | [diff] [blame] | 76 | __libcpp_mutex_unlock(&__rs_mut); |
Jonathan Roelofs | 39cb6bf | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 77 | #else |
| 78 | --__c_; |
| 79 | #endif |
Howard Hinnant | 578ac0f | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | __rs_default::result_type |
| 83 | __rs_default::operator()() |
| 84 | { |
| 85 | static mt19937 __rs_g; |
| 86 | return __rs_g(); |
| 87 | } |
| 88 | |
| 89 | __rs_default |
| 90 | __rs_get() |
| 91 | { |
| 92 | return __rs_default(); |
| 93 | } |
| 94 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 95 | _LIBCPP_END_NAMESPACE_STD |