Destroy Job threads at the start of the subclass destructors,
authorCarl Hetherington <cth@carlh.net>
Fri, 6 Mar 2020 20:59:58 +0000 (20:59 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 6 Mar 2020 20:59:58 +0000 (20:59 +0000)
so that the thread is gone before the object is torn down.

21 files changed:
src/lib/analyse_audio_job.cc
src/lib/check_content_change_job.cc
src/lib/check_content_change_job.h
src/lib/examine_content_job.cc
src/lib/examine_content_job.h
src/lib/examine_ffmpeg_subtitles_job.cc
src/lib/examine_ffmpeg_subtitles_job.h
src/lib/job.cc
src/lib/job.h
src/lib/send_kdm_email_job.cc
src/lib/send_kdm_email_job.h
src/lib/send_notification_email_job.cc
src/lib/send_notification_email_job.h
src/lib/send_problem_report_job.cc
src/lib/send_problem_report_job.h
src/lib/transcode_job.cc
src/lib/transcode_job.h
src/lib/upload_job.cc
src/lib/upload_job.h
src/lib/verify_dcp_job.cc
src/lib/verify_dcp_job.h

index e4a100c..611a57f 100644 (file)
@@ -82,6 +82,7 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> film, shared_ptr<const
 
 AnalyseAudioJob::~AnalyseAudioJob ()
 {
+       destroy_thread ();
        BOOST_FOREACH (Filter const * i, _filters) {
                delete const_cast<Filter*> (i);
        }
index 3d5e4e9..fbeb695 100644 (file)
@@ -41,6 +41,11 @@ CheckContentChangeJob::CheckContentChangeJob (shared_ptr<const Film> film, share
 
 }
 
+CheckContentChangeJob::~CheckContentChangeJob()
+{
+       destroy_thread ();
+}
+
 string
 CheckContentChangeJob::name () const
 {
index da9c5cb..963d09b 100644 (file)
@@ -28,6 +28,7 @@ class CheckContentChangeJob : public Job
 {
 public:
        CheckContentChangeJob (boost::shared_ptr<const Film>, boost::shared_ptr<Job> following = boost::shared_ptr<Job>());
+       ~CheckContentChangeJob ();
 
        std::string name () const;
        std::string json_name () const;
index 86e0a10..5c854a9 100644 (file)
@@ -38,6 +38,11 @@ ExamineContentJob::ExamineContentJob (shared_ptr<const Film> film, shared_ptr<Co
 
 }
 
+ExamineContentJob::~ExamineContentJob ()
+{
+       destroy_thread ();
+}
+
 string
 ExamineContentJob::name () const
 {
index 4249637..0105035 100644 (file)
@@ -27,6 +27,7 @@ class ExamineContentJob : public Job
 {
 public:
        ExamineContentJob (boost::shared_ptr<const Film>, boost::shared_ptr<Content>);
+       ~ExamineContentJob ();
 
        std::string name () const;
        std::string json_name () const;
index b9d5f54..eb2cbcd 100644 (file)
@@ -43,6 +43,11 @@ ExamineFFmpegSubtitlesJob::ExamineFFmpegSubtitlesJob (shared_ptr<const Film> fil
 
 }
 
+ExamineFFmpegSubtitlesJob::~ExamineFFmpegSubtitlesJob ()
+{
+       destroy_thread ();
+}
+
 string
 ExamineFFmpegSubtitlesJob::name () const
 {
index 5960a9c..0a01011 100644 (file)
@@ -28,6 +28,7 @@ class ExamineFFmpegSubtitlesJob : public Job, public FFmpeg
 {
 public:
        ExamineFFmpegSubtitlesJob (boost::shared_ptr<const Film>, boost::shared_ptr<FFmpegContent>);
+       ~ExamineFFmpegSubtitlesJob ();
 
        std::string name () const;
        std::string json_name () const;
index 4517765..d402397 100644 (file)
@@ -61,6 +61,15 @@ Job::Job (shared_ptr<const Film> film)
 }
 
 Job::~Job ()
+{
+#ifdef DCPOMATIC_DEBUG
+       /* Any subclass should have called destroy_thread in its destructor */
+       assert (!_thread);
+#endif
+}
+
+void
+Job::destroy_thread ()
 {
        if (_thread) {
                _thread->interrupt ();
@@ -75,6 +84,7 @@ Job::~Job ()
        }
 
        delete _thread;
+       _thread = 0;
 }
 
 /** Start the job in a separate thread, returning immediately */
index 0e57021..7047a7b 100644 (file)
@@ -112,6 +112,7 @@ protected:
        void set_message (std::string m);
        int elapsed_sub_time () const;
        void check_for_interruption_or_pause ();
+       void destroy_thread ();
 
        boost::shared_ptr<const Film> _film;
 
index 38484b9..a4b4b29 100644 (file)
@@ -53,6 +53,11 @@ SendKDMEmailJob::SendKDMEmailJob (
 
 }
 
+SendKDMEmailJob::~SendKDMEmailJob ()
+{
+       destroy_thread ();
+}
+
 string
 SendKDMEmailJob::name () const
 {
index b4e007e..fcb9a0b 100644 (file)
@@ -38,6 +38,8 @@ public:
                std::string cpl_name
                );
 
+       ~SendKDMEmailJob ();
+
        std::string name () const;
        std::string json_name () const;
        void run ();
index abbb844..5986e5a 100644 (file)
@@ -40,6 +40,11 @@ SendNotificationEmailJob::SendNotificationEmailJob (string body)
 
 }
 
+SendNotificationEmailJob::~SendNotificationEmailJob ()
+{
+       destroy_thread ();
+}
+
 string
 SendNotificationEmailJob::name () const
 {
index 04f1d98..5c116f2 100644 (file)
@@ -24,6 +24,7 @@ class SendNotificationEmailJob : public Job
 {
 public:
        explicit SendNotificationEmailJob (std::string body);
+       ~SendNotificationEmailJob ();
 
        std::string name () const;
        std::string json_name () const;
index 11f700d..8309204 100644 (file)
@@ -52,6 +52,11 @@ SendProblemReportJob::SendProblemReportJob (
 
 }
 
+SendProblemReportJob::~SendProblemReportJob ()
+{
+       destroy_thread ();
+}
+
 string
 SendProblemReportJob::name () const
 {
index c4371a5..af1a4b2 100644 (file)
@@ -31,6 +31,8 @@ public:
                std::string summary
                );
 
+       ~SendProblemReportJob ();
+
        std::string name () const;
        std::string json_name () const;
        void run ();
index 1db37e3..f2711bf 100644 (file)
@@ -51,6 +51,11 @@ TranscodeJob::TranscodeJob (shared_ptr<const Film> film)
 
 }
 
+TranscodeJob::~TranscodeJob ()
+{
+       destroy_thread ();
+}
+
 string
 TranscodeJob::name () const
 {
index 9dd9e36..fccb1a4 100644 (file)
@@ -34,6 +34,7 @@ class TranscodeJob : public Job
 {
 public:
        explicit TranscodeJob (boost::shared_ptr<const Film> film);
+       ~TranscodeJob ();
 
        std::string name () const;
        std::string json_name () const;
index b229fdd..eca4683 100644 (file)
@@ -46,6 +46,11 @@ UploadJob::UploadJob (shared_ptr<const Film> film)
 
 }
 
+UploadJob::~UploadJob ()
+{
+       destroy_thread ();
+}
+
 string
 UploadJob::name () const
 {
index 407094a..3a613fd 100644 (file)
@@ -28,6 +28,7 @@ class UploadJob : public Job
 {
 public:
        explicit UploadJob (boost::shared_ptr<const Film>);
+       ~UploadJob ();
 
        std::string name () const;
        std::string json_name () const;
index 5fb2a59..03d9c4c 100644 (file)
@@ -35,6 +35,11 @@ VerifyDCPJob::VerifyDCPJob (vector<boost::filesystem::path> directories)
 
 }
 
+VerifyDCPJob::~VerifyDCPJob ()
+{
+       destroy_thread ();
+}
+
 string
 VerifyDCPJob::name () const
 {
index a93a7ad..2cff5ab 100644 (file)
@@ -28,6 +28,7 @@ class VerifyDCPJob : public Job
 {
 public:
        explicit VerifyDCPJob (std::vector<boost::filesystem::path> directories);
+       ~VerifyDCPJob ();
 
        std::string name () const;
        std::string json_name () const;