Mercurial > hg > orthanc
comparison Core/MultiThreading/RunnableWorkersPool.cpp @ 1681:ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 Oct 2015 14:02:39 +0200 |
parents | 15acdb19d520 |
children | 559956d5ceb2 |
comparison
equal
deleted
inserted
replaced
1680:4113a9a668b1 | 1681:ee4367497d0d |
---|---|
117 pimpl_->workers_[i] = new PImpl::Worker(pimpl_->continue_, pimpl_->queue_); | 117 pimpl_->workers_[i] = new PImpl::Worker(pimpl_->continue_, pimpl_->queue_); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 RunnableWorkersPool::~RunnableWorkersPool() | 122 void RunnableWorkersPool::Stop() |
123 { | 123 { |
124 pimpl_->continue_ = false; | 124 if (pimpl_->continue_) |
125 { | |
126 pimpl_->continue_ = false; | |
125 | 127 |
126 for (size_t i = 0; i < pimpl_->workers_.size(); i++) | 128 for (size_t i = 0; i < pimpl_->workers_.size(); i++) |
127 { | 129 { |
128 PImpl::Worker* worker = pimpl_->workers_[i]; | 130 PImpl::Worker* worker = pimpl_->workers_[i]; |
129 | 131 |
130 if (worker != NULL) | 132 if (worker != NULL) |
131 { | 133 { |
132 worker->Join(); | 134 worker->Join(); |
133 delete worker; | 135 delete worker; |
136 } | |
134 } | 137 } |
135 } | 138 } |
136 } | 139 } |
137 | 140 |
138 | 141 |
139 void RunnableWorkersPool::Add(IRunnableBySteps* runnable) | 142 RunnableWorkersPool::~RunnableWorkersPool() |
140 { | 143 { |
141 pimpl_->queue_.Enqueue(runnable); | 144 Stop(); |
142 } | 145 } |
143 | 146 |
144 | 147 |
145 void RunnableWorkersPool::WaitDone() | 148 void RunnableWorkersPool::Add(IRunnableBySteps* runnable) |
146 { | 149 { |
147 pimpl_->queue_.WaitEmpty(0); | 150 if (!pimpl_->continue_) |
151 { | |
152 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
153 } | |
154 | |
155 pimpl_->queue_.Enqueue(runnable); | |
148 } | 156 } |
149 } | 157 } |