llvm.org GIT mirror llvm / 9525cd9
Try again to fix the buildbots. TaskGroup and Latch need to be in llvm::parallel::detail, not in llvm::detail. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302751 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 3 years ago
2 changed file(s) with 40 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
2828
2929 namespace llvm {
3030
31 namespace detail {
32 class Latch {
33 uint32_t Count;
34 mutable std::mutex Mutex;
35 mutable std::condition_variable Cond;
36
37 public:
38 explicit Latch(uint32_t Count = 0) : Count(Count) {}
39 ~Latch() { sync(); }
40
41 void inc() {
42 std::unique_lock lock(Mutex);
43 ++Count;
44 }
45
46 void dec() {
47 std::unique_lock lock(Mutex);
48 if (--Count == 0)
49 Cond.notify_all();
50 }
51
52 void sync() const {
53 std::unique_lock lock(Mutex);
54 Cond.wait(lock, [&] { return Count == 0; });
55 }
56 };
57
58 class TaskGroup {
59 Latch L;
60
61 public:
62 void spawn(std::function f);
63
64 void sync() const { L.sync(); }
65 };
66 }
67
6831 namespace parallel {
6932 struct sequential_execution_policy {};
7033 struct parallel_execution_policy {};
8144 namespace detail {
8245
8346 #if LLVM_ENABLE_THREADS
47
48 class Latch {
49 uint32_t Count;
50 mutable std::mutex Mutex;
51 mutable std::condition_variable Cond;
52
53 public:
54 explicit Latch(uint32_t Count = 0) : Count(Count) {}
55 ~Latch() { sync(); }
56
57 void inc() {
58 std::unique_lock lock(Mutex);
59 ++Count;
60 }
61
62 void dec() {
63 std::unique_lock lock(Mutex);
64 if (--Count == 0)
65 Cond.notify_all();
66 }
67
68 void sync() const {
69 std::unique_lock lock(Mutex);
70 Cond.wait(lock, [&] { return Count == 0; });
71 }
72 };
73
74 class TaskGroup {
75 Latch L;
76
77 public:
78 void spawn(std::function f);
79
80 void sync() const { L.sync(); }
81 };
8482
8583 #if defined(_MSC_VER)
8684 template
116114
117115 template
118116 void parallel_quick_sort(RandomAccessIterator Start, RandomAccessIterator End,
119 const Comparator &Comp, detail::TaskGroup &TG,
120 size_t Depth) {
117 const Comparator &Comp, TaskGroup &TG, size_t Depth) {
121118 // Do a sequential sort for small inputs.
122119 if (std::distance(Start, End) < detail::MinParallelSize || Depth == 0) {
123120 std::sort(Start, End, Comp);
144141 template
145142 void parallel_sort(RandomAccessIterator Start, RandomAccessIterator End,
146143 const Comparator &Comp) {
147 detail::TaskGroup TG;
144 TaskGroup TG;
148145 parallel_quick_sort(Start, End, Comp, TG,
149146 llvm::Log2_64(std::distance(Start, End)) + 1);
150147 }
159156 if (TaskSize == 0)
160157 TaskSize = 1;
161158
162 detail::TaskGroup TG;
159 TaskGroup TG;
163160 while (TaskSize <= std::distance(Begin, End)) {
164161 TG.spawn([=, &Fn] { std::for_each(Begin, Begin + TaskSize, Fn); });
165162 Begin += TaskSize;
173170 if (TaskSize == 0)
174171 TaskSize = 1;
175172
176 detail::TaskGroup TG;
173 TaskGroup TG;
177174 IndexTy I = Begin;
178175 for (; I + TaskSize < End; I += TaskSize) {
179176 TG.spawn([=, &Fn] {
126126 #endif
127127 }
128128
129 void detail::TaskGroup::spawn(std::function F) {
129 void parallel::detail::TaskGroup::spawn(std::function F) {
130130 L.inc();
131131 Executor::getDefaultExecutor()->add([&, F] {
132132 F();