summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-12-30 21:46:10 +0000
committerCarl Hetherington <cth@carlh.net>2013-12-30 21:46:10 +0000
commit25674c1e6a66715286f7f9a5116fdf3baff1c738 (patch)
tree86d8ba45bebe787ab697ba7543d2fa97f272fab9 /src
parent7d66aefc8a38140f5ea5620432c24ed9b370b481 (diff)
Comment and slightly tidy ExceptionStore.
Diffstat (limited to 'src')
-rw-r--r--src/lib/encoder.cc4
-rw-r--r--src/lib/exceptions.h25
-rw-r--r--src/lib/writer.cc4
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<PlayerImage> 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;