diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-04-20 21:58:30 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-04-21 00:52:07 +0200 |
| commit | 3b137ece1ab4bffe4c959047972c5d1317f8a79c (patch) | |
| tree | 3ed7f134b5754a75e66ed9ee0cfa1a7d6cefbe6f /src/lib | |
| parent | e4b693f2e7b7dc2afb4e9ec3e96e317fff851c5b (diff) | |
Make digest calculations interruptible.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/reel_writer.cc | 5 | ||||
| -rw-r--r-- | src/lib/writer.cc | 27 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index cd6a1a4b9..a3d499abe 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -745,6 +745,7 @@ ReelWriter::create_reel ( void ReelWriter::calculate_digests (boost::function<void (float)> set_progress) +try { if (_picture_asset) { _picture_asset->hash (set_progress); @@ -757,6 +758,10 @@ ReelWriter::calculate_digests (boost::function<void (float)> set_progress) if (_atmos_asset) { _atmos_asset->hash (set_progress); } +} catch (boost::thread_interrupted) { + /* set_progress contains an interruption_point, so any of these methods + * may throw thread_interrupted, at which point we just give up. + */ } Frame diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 8fa9fbbca..b749968a7 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -74,14 +74,6 @@ using dcp::ArrayData; using namespace dcpomatic; -static -void -ignore_progress (float) -{ - -} - - /** @param j Job to report progress to, or 0. * @param text_only true to enable only the text (subtitle/ccap) parts of the writer. */ @@ -558,7 +550,9 @@ Writer::calculate_digests () if (job) { set_progress = boost::bind (&Writer::set_digest_progress, this, job.get(), _1); } else { - set_progress = &ignore_progress; + set_progress = [](float) { + boost::this_thread::interruption_point(); + }; } for (auto& i: _reels) { @@ -568,7 +562,13 @@ Writer::calculate_digests () work.reset (); - { + try { + pool.join_all (); + } catch (boost::thread_interrupted) { + /* join_all was interrupted, so we need to interrupt the threads + * in our pool then try again to join them. + */ + pool.interrupt_all (); pool.join_all (); } @@ -941,12 +941,15 @@ Writer::set_digest_progress (Job* job, float progress) Waker waker; waker.nudge (); + + boost::this_thread::interruption_point(); } /** Calculate hashes for any referenced MXF assets which do not already have one */ void Writer::calculate_referenced_digests (boost::function<void (float)> set_progress) +try { for (auto const& i: _reel_assets) { auto file = dynamic_pointer_cast<dcp::ReelFileAsset>(i.asset); @@ -955,6 +958,10 @@ Writer::calculate_referenced_digests (boost::function<void (float)> set_progress file->set_hash (file->asset_ref().asset()->hash()); } } +} catch (boost::thread_interrupted) { + /* set_progress contains an interruption_point, so any of these methods + * may throw thread_interrupted, at which point we just give up. + */ } |
