assert (joinable) before joining threads.
[dcpomatic.git] / src / lib / server.cc
index 79840c25bb2701bebc57f010fe764ae6c08348b0..dd076a049cd01b62cc08c47d51ee90b62a8d2db6 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
  */
 
 #include "server.h"
+#include "util.h"
 #include "dcpomatic_socket.h"
 #include "image.h"
 #include "dcp_video.h"
 #include "data.h"
 #include "safe_stringstream.h"
 #include "raw_convert.h"
+#include "compose.hpp"
+#include "log.h"
 #include <libcxml/cxml.h>
+#include <libxml++/libxml++.h>
 #include <boost/algorithm/string.hpp>
 #include <boost/scoped_array.hpp>
 #include <string>
 #define LOG_ERROR_NC(...)   _log->log (__VA_ARGS__, Log::TYPE_ERROR);
 
 using std::string;
-using std::multimap;
 using std::vector;
 using std::list;
 using std::cout;
 using std::cerr;
-using std::setprecision;
 using std::fixed;
 using boost::shared_ptr;
-using boost::algorithm::is_any_of;
-using boost::algorithm::split;
 using boost::thread;
 using boost::bind;
 using boost::scoped_array;
@@ -78,17 +78,22 @@ Server::~Server ()
                boost::mutex::scoped_lock lm (_worker_mutex);
                _terminate = true;
                _empty_condition.notify_all ();
+               _full_condition.notify_all ();
        }
 
-       for (vector<boost::thread*>::iterator i = _worker_threads.begin(); i != _worker_threads.end(); ++i) {
-               (*i)->join ();
-               delete *i;
+       BOOST_FOREACH (boost::thread* i, _worker_threads) {
+               DCPOMATIC_ASSERT (i->joinable ());
+               i->join ();
+               delete i;
        }
 
        _io_service.stop ();
 
        _broadcast.io_service.stop ();
-       _broadcast.thread->join ();
+       if (_broadcast.thread) {
+               DCPOMATIC_ASSERT (_broadcast.thread->join ());
+               _broadcast.thread->join ();
+       }
 }
 
 /** @param after_read Filled in with gettimeofday() after reading the input from the network.
@@ -304,4 +309,3 @@ Server::handle_accept (shared_ptr<Socket> socket, boost::system::error_code cons
 
        start_accept ();
 }
-