1 | //===----------------------- algorithm.cpp --------------------------------===// |
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-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "algorithm" |
10 | #include "random" |
11 | #ifndef _LIBCPP_HAS_NO_THREADS |
12 | #include "mutex" |
13 | #if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB) |
14 | #pragma comment(lib, "pthread") |
15 | #endif |
16 | #endif |
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 | |
54 | #ifndef _LIBCPP_HAS_NO_THREADS |
55 | _LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER; |
56 | #endif |
57 | unsigned __rs_default::__c_ = 0; |
58 | |
59 | __rs_default::__rs_default() |
60 | { |
61 | #ifndef _LIBCPP_HAS_NO_THREADS |
62 | __libcpp_mutex_lock(&__rs_mut); |
63 | #endif |
64 | __c_ = 1; |
65 | } |
66 | |
67 | __rs_default::__rs_default(const __rs_default&) |
68 | { |
69 | ++__c_; |
70 | } |
71 | |
72 | __rs_default::~__rs_default() |
73 | { |
74 | #ifndef _LIBCPP_HAS_NO_THREADS |
75 | if (--__c_ == 0) |
76 | __libcpp_mutex_unlock(&__rs_mut); |
77 | #else |
78 | --__c_; |
79 | #endif |
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 | |
95 | _LIBCPP_END_NAMESPACE_STD |
96 | |