From 25674c1e6a66715286f7f9a5116fdf3baff1c738 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 30 Dec 2013 21:46:10 +0000 Subject: Comment and slightly tidy ExceptionStore. --- src/lib/encoder.cc | 4 +--- src/lib/exceptions.h | 25 +++++++++++++++++++------ src/lib/writer.cc | 4 +--- 3 files changed, 21 insertions(+), 12 deletions(-) (limited to 'src/lib') diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index eff38b6a5..ca75e4ca1 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -199,9 +199,7 @@ Encoder::process_video (shared_ptr image, Eyes eyes, ColourConversi return; } - if (_writer->thrown ()) { - _writer->rethrow (); - } + _writer->rethrow (); if (_writer->can_fake_write (_video_frames_out)) { _writer->fake_write (_video_frames_out, eyes); diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index f4631c09b..c1240538f 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -230,17 +230,30 @@ public: PixelFormatError (std::string o, AVPixelFormat f); }; +/** A parent class for classes which have a need to catch and + * re-throw exceptions. This is intended for classes + * which run their own thread; they should do something like + * + * void my_thread () + * try { + * // do things which might throw exceptions + * } catch (...) { + * store_current (); + * } + * + * and then in another thread call rethrow(). If any + * exception was thrown by my_thread it will be stored by + * store_current() and then rethrow() will re-throw it where + * it can be handled. + */ class ExceptionStore { public: - bool thrown () const { - boost::mutex::scoped_lock lm (_mutex); - return _exception; - } - void rethrow () { boost::mutex::scoped_lock lm (_mutex); - boost::rethrow_exception (_exception); + if (_exception) { + boost::rethrow_exception (_exception); + } } protected: diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 4129b7a82..414ea72eb 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -335,9 +335,7 @@ Writer::finish () lock.unlock (); _thread->join (); - if (thrown ()) { - rethrow (); - } + rethrow (); delete _thread; _thread = 0; -- cgit v1.2.3 From f87a0f16f8cee026ee33c3a46b93b43d4b3cf5ff Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 30 Dec 2013 23:01:54 +0000 Subject: Catch exceptions from Encoder threads. --- src/lib/encoder.cc | 11 ++++++++++- src/lib/encoder.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index ca75e4ca1..b78bcaeea 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -96,7 +96,6 @@ Encoder::process_begin () ServerFinder::instance()->connect (boost::bind (&Encoder::server_found, this, _1)); } - void Encoder::process_end () { @@ -200,6 +199,11 @@ Encoder::process_video (shared_ptr image, Eyes eyes, ColourConversi } _writer->rethrow (); + /* Re-throw any exception raised by one of our threads. If more + than one has thrown an exception, only one will be rethrown, I think; + but then, if that happens something has gone badly wrong. + */ + rethrow (); if (_writer->can_fake_write (_video_frames_out)) { _writer->fake_write (_video_frames_out, eyes); @@ -255,6 +259,7 @@ Encoder::terminate_threads () void Encoder::encoder_thread (optional server) +try { /* Number of seconds that we currently wait between attempts to connect to the server; not relevant for localhost @@ -336,6 +341,10 @@ Encoder::encoder_thread (optional server) _condition.notify_all (); } } +catch (...) +{ + store_current (); +} void Encoder::server_found (ServerDescription s) diff --git a/src/lib/encoder.h b/src/lib/encoder.h index d43e4e1d3..079174f89 100644 --- a/src/lib/encoder.h +++ b/src/lib/encoder.h @@ -56,7 +56,7 @@ class PlayerImage; * is supplied as uncompressed PCM in blocks of various sizes. */ -class Encoder : public boost::noncopyable +class Encoder : public boost::noncopyable, public ExceptionStore { public: Encoder (boost::shared_ptr f, boost::weak_ptr); -- cgit v1.2.3 From 6670f11c639e3515256f4f0eb3699e02155f67c9 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 30 Dec 2013 23:10:49 +0000 Subject: Handle exceptions thrown from ServerFinder. --- src/lib/server_finder.cc | 10 ++++++++++ src/lib/server_finder.h | 2 +- src/tools/dcpomatic.cc | 18 +++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index de90e0d5c..5b67d8048 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -47,6 +47,7 @@ ServerFinder::ServerFinder () void ServerFinder::broadcast_thread () +try { boost::system::error_code error; boost::asio::io_service io_service; @@ -88,9 +89,14 @@ ServerFinder::broadcast_thread () dcpomatic_sleep (10); } } +catch (...) +{ + store_current (); +} void ServerFinder::listen_thread () +try { while (1) { shared_ptr sock (new Socket (10)); @@ -117,6 +123,10 @@ ServerFinder::listen_thread () } } } +catch (...) +{ + store_current (); +} bool ServerFinder::server_found (string ip) const diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h index 01e26f7df..202bee8f9 100644 --- a/src/lib/server_finder.h +++ b/src/lib/server_finder.h @@ -20,7 +20,7 @@ #include #include "server.h" -class ServerFinder +class ServerFinder : public ExceptionStore { public: void connect (boost::function); diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 66f795ddf..891c4623c 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -54,6 +54,7 @@ #include "lib/cinema.h" #include "lib/kdm.h" #include "lib/send_kdm_email_job.h" +#include "lib/server_finder.h" using std::cout; using std::string; @@ -632,8 +633,12 @@ class App : public wxApp f->Show (); ui_signaller = new wxUISignaller (this); - this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this)); + Bind (wxEVT_IDLE, boost::bind (&App::idle, this)); + Bind (wxEVT_TIMER, boost::bind (&App::check, this)); + _timer.reset (new wxTimer (this)); + _timer->Start (1000); + return true; } catch (exception& e) @@ -670,6 +675,17 @@ class App : public wxApp { ui_signaller->ui_idle (); } + + void check () + { + try { + ServerFinder::instance()->rethrow (); + } catch (exception& e) { + error_dialog (0, std_to_wx (e.what ())); + } + } + + shared_ptr _timer; }; IMPLEMENT_APP (App) -- cgit v1.2.3 From 7478dcb6bac871d7839dad9923cdb2d06cd12790 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 30 Dec 2013 23:52:56 +0000 Subject: Don't flush audio if Player is not supposed to be playing it. --- src/lib/player.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/player.cc b/src/lib/player.cc index 09a437494..cacb42651 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -375,16 +375,16 @@ void Player::flush () { TimedAudioBuffers