| 103 | } |
| 104 | |
| 105 | inline bool Add(IObjectInQueue* obj) { |
| 106 | if (ShouldTerminate.load()) { |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | if (Tharr.empty()) { |
| 111 | TTsr tsr(Parent_); |
| 112 | obj->Process(tsr); |
| 113 | |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | with_lock (QueueMutex) { |
| 118 | while (MaxQueueSize > 0 && Queue.Size() >= MaxQueueSize && !ShouldTerminate.load()) { |
| 119 | if (!Blocking) { |
| 120 | return false; |
| 121 | } |
| 122 | QueuePopCond.Wait(QueueMutex); |
| 123 | } |
| 124 | |
| 125 | if (ShouldTerminate.load()) { |
| 126 | return false; |
| 127 | } |
| 128 | |
| 129 | Queue.Push(obj); |
| 130 | } |
| 131 | |
| 132 | QueuePushCond.Signal(); |
| 133 | |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | inline size_t Size() const noexcept { |
| 138 | auto guard = Guard(QueueMutex); |