Fix job pausing to actually work, and always add Pause buttons to JobManagerViews...
authorCarl Hetherington <cth@carlh.net>
Fri, 24 Oct 2014 22:26:18 +0000 (23:26 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 24 Oct 2014 22:26:18 +0000 (23:26 +0100)
src/lib/job.cc
src/lib/job.h
src/tools/dcpomatic.cc
src/tools/dcpomatic_batch.cc
src/wx/job_manager_view.cc
src/wx/job_manager_view.h

index 52ec1426c0bd0300a6658293471ef795e2e995ae..52276c0eab3d69ae834f08bd80d8522715c66cd7 100644 (file)
@@ -230,8 +230,9 @@ Job::set_progress (float p, bool force)
        _progress = p;
        boost::this_thread::interruption_point ();
 
-       if (paused ()) {
-               dcpomatic_sleep (1);
+       boost::mutex::scoped_lock lm2 (_state_mutex);
+       while (_state == PAUSED) {
+               _pause_changed.wait (lm2);
        }
 
        if (ui_signaller) {
@@ -348,6 +349,7 @@ Job::pause ()
 {
        if (running ()) {
                set_state (PAUSED);
+               _pause_changed.notify_all ();
        }
 }
 
@@ -356,5 +358,6 @@ Job::resume ()
 {
        if (paused ()) {
                set_state (RUNNING);
+               _pause_changed.notify_all ();
        }
 }
index 97e3fc29637d292597d943f4c9e70a77cdd8dfad..b7dfc589132669fcff375caa1e60231c20054bc8 100644 (file)
@@ -125,6 +125,11 @@ private:
        mutable boost::mutex _progress_mutex;
        boost::optional<float> _progress;
 
+       /** condition to signal changes to pause/resume so that we know when to wake;
+           this could be a general _state_change if it made more sense.
+       */
+       boost::condition_variable _pause_changed;
+
        int _ran_for;
 };
 
index fe3a43f71c4d06fabce4e2931eb26afa4ad588e5..c22253062c87e982bbc7ea8066c9de3e10295d4a 100644 (file)
@@ -201,7 +201,7 @@ public:
 
                _film_editor = new FilmEditor (overall_panel);
                _film_viewer = new FilmViewer (overall_panel);
-               JobManagerView* job_manager_view = new JobManagerView (overall_panel, static_cast<JobManagerView::Buttons> (0));
+               JobManagerView* job_manager_view = new JobManagerView (overall_panel);
 
                wxBoxSizer* right_sizer = new wxBoxSizer (wxVERTICAL);
                right_sizer->Add (_film_viewer, 2, wxEXPAND | wxALL, 6);
index de255e65edaeab43959800f8639232f87b5272ea..b92ca5d7100218a005e3576cd980a4aa711fd406 100644 (file)
@@ -77,7 +77,7 @@ public:
                s->Add (panel, 1, wxEXPAND);
                SetSizer (s);
 
-               JobManagerView* job_manager_view = new JobManagerView (panel, JobManagerView::PAUSE);
+               JobManagerView* job_manager_view = new JobManagerView (panel);
                _sizer->Add (job_manager_view, 1, wxALL | wxEXPAND, 6);
 
                wxSizer* buttons = new wxBoxSizer (wxHORIZONTAL);
index 5146243b412b0ede27ed94a132475d1a7fbcbbc4..b62d44d07c15fba1b22fad1e03aaa19a18eefa6c 100644 (file)
@@ -39,12 +39,11 @@ using boost::weak_ptr;
 class JobRecord
 {
 public:
-       JobRecord (shared_ptr<Job> job, wxScrolledWindow* window, wxPanel* panel, wxFlexGridSizer* table, bool pause)
+       JobRecord (shared_ptr<Job> job, wxScrolledWindow* window, wxPanel* panel, wxFlexGridSizer* table)
                : _job (job)
                , _window (window)
                , _panel (panel)
                , _table (table)
-               , _pause (0)
        {
                int n = 0;
                
@@ -69,12 +68,10 @@ public:
                table->Insert (n, _cancel, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
                ++n;
        
-               if (pause) {
-                       _pause = new wxButton (_panel, wxID_ANY, _("Pause"));
-                       _pause->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobRecord::pause_clicked, this);
-                       table->Insert (n, _pause, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
-                       ++n;
-               }
+               _pause = new wxButton (_panel, wxID_ANY, _("Pause"));
+               _pause->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobRecord::pause_clicked, this);
+               table->Insert (n, _pause, 1, wxALIGN_CENTER_VERTICAL | wxALL, 6);
+               ++n;
        
                _details = new wxButton (_panel, wxID_ANY, _("Details..."));
                _details->Bind (wxEVT_COMMAND_BUTTON_CLICKED, &JobRecord::details_clicked, this);
@@ -135,9 +132,7 @@ private:
                }
                
                _cancel->Enable (false);
-               if (_pause) {
-                       _pause->Enable (false);
-               }
+               _pause->Enable (false);
                if (!_job->error_details().empty ()) {
                        _details->Enable (true);
                }
@@ -183,21 +178,15 @@ private:
 };
 
 /** Must be called in the GUI thread */
-JobManagerView::JobManagerView (wxWindow* parent, Buttons buttons)
+JobManagerView::JobManagerView (wxWindow* parent)
        : wxScrolledWindow (parent)
-       , _buttons (buttons)
 {
        _panel = new wxPanel (this);
        wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
        sizer->Add (_panel, 1, wxEXPAND);
        SetSizer (sizer);
 
-       int N = 5;
-       if (buttons & PAUSE) {
-               ++N;
-       }
-       
-       _table = new wxFlexGridSizer (N, 6, 6);
+       _table = new wxFlexGridSizer (6, 6, 6);
        _table->AddGrowableCol (1, 1);
        _panel->SetSizer (_table);
 
@@ -225,7 +214,7 @@ JobManagerView::job_added (weak_ptr<Job> j)
 {
        shared_ptr<Job> job = j.lock ();
        if (job) {
-               _job_records.push_back (shared_ptr<JobRecord> (new JobRecord (job, this, _panel, _table, _buttons & PAUSE)));
+               _job_records.push_back (shared_ptr<JobRecord> (new JobRecord (job, this, _panel, _table)));
        }
 }
 
index 83ce4ee5abb9d837eee80cd90df3800bb9892c80..fde9199ffb80d5890e0397a08e006d719a07c414 100644 (file)
@@ -34,11 +34,7 @@ class JobRecord;
 class JobManagerView : public wxScrolledWindow
 {
 public:
-       enum Buttons {
-               PAUSE = 0x1,
-       };
-               
-       JobManagerView (wxWindow *, Buttons);
+       JobManagerView (wxWindow *);
 
 private:
        void job_added (boost::weak_ptr<Job>);
@@ -50,5 +46,4 @@ private:
        boost::shared_ptr<wxTimer> _timer;
                
        std::list<boost::shared_ptr<JobRecord> > _job_records;
-       Buttons _buttons;
 };