From 25674c1e6a66715286f7f9a5116fdf3baff1c738 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 30 Dec 2013 21:46:10 +0000 Subject: [PATCH] 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(-) 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; -- 2.30.2