| 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 // This file declares threading-related functions. | 10 // This file declares threading-related functions. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // MaxStaticSize, where the queue boundaries are denoted by the Front | 47 // MaxStaticSize, where the queue boundaries are denoted by the Front |
| 48 // and Back fields. Front==Back indicates an empty queue. | 48 // and Back fields. Front==Back indicates an empty queue. |
| 49 template <typename T, size_t MaxStaticSize = 128> | 49 template <typename T, size_t MaxStaticSize = 128> |
| 50 class BoundedProducerConsumerQueue { | 50 class BoundedProducerConsumerQueue { |
| 51 BoundedProducerConsumerQueue() = delete; | 51 BoundedProducerConsumerQueue() = delete; |
| 52 BoundedProducerConsumerQueue(const BoundedProducerConsumerQueue &) = delete; | 52 BoundedProducerConsumerQueue(const BoundedProducerConsumerQueue &) = delete; |
| 53 BoundedProducerConsumerQueue & | 53 BoundedProducerConsumerQueue & |
| 54 operator=(const BoundedProducerConsumerQueue &) = delete; | 54 operator=(const BoundedProducerConsumerQueue &) = delete; |
| 55 | 55 |
| 56 public: | 56 public: |
| 57 BoundedProducerConsumerQueue(bool Sequential, size_t MaxSize = MaxStaticSize) | 57 BoundedProducerConsumerQueue(bool MySequential, |
| 58 : MaxSize(std::min(MaxSize, MaxStaticSize)), Sequential(Sequential) {} | 58 size_t MyMaxSize = MaxStaticSize) |
| 59 : MaxSize(std::min(MyMaxSize, MaxStaticSize)), Sequential(MySequential) {} |
| 59 void blockingPush(T *Item) { | 60 void blockingPush(T *Item) { |
| 60 { | 61 { |
| 61 std::unique_lock<GlobalLockType> L(Lock); | 62 std::unique_lock<GlobalLockType> L(Lock); |
| 62 // If the work queue is already "full", wait for a consumer to | 63 // If the work queue is already "full", wait for a consumer to |
| 63 // grab an element and shrink the queue. | 64 // grab an element and shrink the queue. |
| 64 Shrunk.wait(L, [this] { return size() < MaxSize || Sequential; }); | 65 Shrunk.wait(L, [this] { return size() < MaxSize || Sequential; }); |
| 65 push(Item); | 66 push(Item); |
| 66 } | 67 } |
| 67 GrewOrEnded.notify_one(); | 68 GrewOrEnded.notify_one(); |
| 68 } | 69 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 const uint32_t Sequence; | 199 const uint32_t Sequence; |
| 199 const ItemKind Kind; | 200 const ItemKind Kind; |
| 200 std::unique_ptr<VariableDeclarationList> GlobalInits; | 201 std::unique_ptr<VariableDeclarationList> GlobalInits; |
| 201 std::unique_ptr<Assembler> Function; | 202 std::unique_ptr<Assembler> Function; |
| 202 std::unique_ptr<Cfg> RawFunc; | 203 std::unique_ptr<Cfg> RawFunc; |
| 203 }; | 204 }; |
| 204 | 205 |
| 205 } // end of namespace Ice | 206 } // end of namespace Ice |
| 206 | 207 |
| 207 #endif // SUBZERO_SRC_ICETHREADING_H | 208 #endif // SUBZERO_SRC_ICETHREADING_H |
| OLD | NEW |