| OLD | NEW |
| 1 //===- subzero/src/IceThreading.h - Threading functions ---------*- C++ -*-===// | 1 //===- subzero/src/IceThreading.h - Threading functions ---------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 void blockingPush(std::unique_ptr<T> Item) { | 60 void blockingPush(std::unique_ptr<T> Item) { |
| 61 { | 61 { |
| 62 std::unique_lock<GlobalLockType> L(Lock); | 62 std::unique_lock<GlobalLockType> L(Lock); |
| 63 // If the work queue is already "full", wait for a consumer to grab an | 63 // If the work queue is already "full", wait for a consumer to grab an |
| 64 // element and shrink the queue. | 64 // element and shrink the queue. |
| 65 Shrunk.wait(L, [this] { return size() < MaxSize || Sequential; }); | 65 Shrunk.wait(L, [this] { return size() < MaxSize || Sequential; }); |
| 66 push(std::move(Item)); | 66 push(std::move(Item)); |
| 67 } | 67 } |
| 68 GrewOrEnded.notify_one(); | 68 GrewOrEnded.notify_one(); |
| 69 } | 69 } |
| 70 std::unique_ptr<T> blockingPop() { | 70 std::unique_ptr<T> blockingPop(size_t NotifyWhenDownToSize = MaxStaticSize) { |
| 71 std::unique_ptr<T> Item; | 71 std::unique_ptr<T> Item; |
| 72 bool ShouldNotifyProducer = false; | 72 bool ShouldNotifyProducer = false; |
| 73 { | 73 { |
| 74 std::unique_lock<GlobalLockType> L(Lock); | 74 std::unique_lock<GlobalLockType> L(Lock); |
| 75 GrewOrEnded.wait(L, [this] { return IsEnded || !empty() || Sequential; }); | 75 GrewOrEnded.wait(L, [this] { return IsEnded || !empty() || Sequential; }); |
| 76 if (!empty()) { | 76 if (!empty()) { |
| 77 Item = pop(); | 77 Item = pop(); |
| 78 ShouldNotifyProducer = !IsEnded; | 78 ShouldNotifyProducer = (size() < NotifyWhenDownToSize) && !IsEnded; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 if (ShouldNotifyProducer) | 81 if (ShouldNotifyProducer) |
| 82 Shrunk.notify_one(); | 82 Shrunk.notify_one(); |
| 83 return Item; | 83 return Item; |
| 84 } | 84 } |
| 85 void notifyEnd() { | 85 void notifyEnd() { |
| 86 { | 86 { |
| 87 std::lock_guard<GlobalLockType> L(Lock); | 87 std::lock_guard<GlobalLockType> L(Lock); |
| 88 IsEnded = true; | 88 IsEnded = true; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 const uint32_t Sequence; | 192 const uint32_t Sequence; |
| 193 const ItemKind Kind; | 193 const ItemKind Kind; |
| 194 std::unique_ptr<VariableDeclarationList> GlobalInits; | 194 std::unique_ptr<VariableDeclarationList> GlobalInits; |
| 195 std::unique_ptr<Assembler> Function; | 195 std::unique_ptr<Assembler> Function; |
| 196 std::unique_ptr<Cfg> RawFunc; | 196 std::unique_ptr<Cfg> RawFunc; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 } // end of namespace Ice | 199 } // end of namespace Ice |
| 200 | 200 |
| 201 #endif // SUBZERO_SRC_ICETHREADING_H | 201 #endif // SUBZERO_SRC_ICETHREADING_H |
| OLD | NEW |