aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/threadpool.cpp18
-rw-r--r--src/common/threadpool.h3
2 files changed, 20 insertions, 1 deletions
diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp
index 7fd16ceaf..51e071577 100644
--- a/src/common/threadpool.cpp
+++ b/src/common/threadpool.cpp
@@ -25,6 +25,7 @@
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include "misc_log_ex.h"
#include "common/threadpool.h"
#include <cassert>
@@ -81,6 +82,23 @@ int threadpool::get_max_concurrency() {
return max;
}
+threadpool::waiter::~waiter()
+{
+ {
+ boost::unique_lock<boost::mutex> lock(mt);
+ if (num)
+ MERROR("wait should have been called before waiter dtor - waiting now");
+ }
+ try
+ {
+ wait();
+ }
+ catch (const std::exception &e)
+ {
+ /* ignored */
+ }
+}
+
void threadpool::waiter::wait() {
boost::unique_lock<boost::mutex> lock(mt);
while(num) cv.wait(lock);
diff --git a/src/common/threadpool.h b/src/common/threadpool.h
index a0e53b011..34152541c 100644
--- a/src/common/threadpool.h
+++ b/src/common/threadpool.h
@@ -34,6 +34,7 @@
#include <functional>
#include <utility>
#include <vector>
+#include <stdexcept>
namespace tools
{
@@ -57,7 +58,7 @@ public:
void dec();
void wait(); //! Wait for a set of tasks to finish.
waiter() : num(0){}
- ~waiter() { wait(); }
+ ~waiter();
};
// Submit a task to the pool. The waiter pointer may be