Add some missing locking to JobManager::decrease_priority.
+2018-08-16 Carl Hetherington <cth@carlh.net>
+
+ * Add pause/resume to the batch converter (#1248).
+
2018-08-15 Carl Hetherington <cth@carlh.net>
* Support download of Barco Alchemy, Christie and GDC certificates
_thread = 0;
}
-void
+/** @return true if the job was paused, false if it was not running */
+bool
Job::pause_by_user ()
{
- if (running ()) {
- set_state (PAUSED_BY_USER);
+ bool paused = false;
+ {
+ boost::mutex::scoped_lock lm (_state_mutex);
+ /* We can set _state here directly because we have a lock and we aren't
+ setting the job to FINISHED_*
+ */
+ if (_state == RUNNING) {
+ paused = true;
+ _state = PAUSED_BY_USER;
+ }
+ }
+
+ if (paused) {
_pause_changed.notify_all ();
}
+
+ return paused;
}
void
virtual void run () = 0;
void start ();
- void pause_by_user ();
+ bool pause_by_user ();
void pause_by_priority ();
void resume ();
void cancel ();
JobManager::JobManager ()
: _terminate (false)
+ , _paused (false)
, _scheduler (0)
{
return;
}
- BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+ if (!_paused) {
+ BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
- if (!i->finished ()) {
- active_job = i->json_name ();
- }
+ if (!i->finished ()) {
+ active_job = i->json_name ();
+ }
- if (i->running ()) {
- /* Something is already happening */
- break;
- }
+ if (i->running ()) {
+ /* Something is already happening */
+ break;
+ }
- if (i->is_new()) {
- i->start ();
- /* Only start one job at once */
- break;
+ if (i->is_new()) {
+ i->start ();
+ /* Only start one job at once */
+ break;
+ }
}
}
}
{
bool changed = false;
- for (list<shared_ptr<Job> >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) {
- list<shared_ptr<Job> >::iterator next = i;
- ++next;
- if (*i == job && next != _jobs.end()) {
- swap (*i, *next);
- changed = true;
- break;
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ for (list<shared_ptr<Job> >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) {
+ list<shared_ptr<Job> >::iterator next = i;
+ ++next;
+ if (*i == job && next != _jobs.end()) {
+ swap (*i, *next);
+ changed = true;
+ break;
+ }
}
}
priority_changed ();
}
}
+
+void
+JobManager::pause ()
+{
+ boost::mutex::scoped_lock lm (_mutex);
+
+ if (_paused) {
+ return;
+ }
+
+ BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+ if (i->pause_by_user()) {
+ _paused_job = i;
+ }
+ }
+
+ _paused = true;
+}
+
+void
+JobManager::resume ()
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ if (!_paused) {
+ return;
+ }
+
+ if (_paused_job) {
+ _paused_job->resume ();
+ }
+
+ _paused_job.reset ();
+ _paused = false;
+}
bool errors () const;
void increase_priority (boost::shared_ptr<Job>);
void decrease_priority (boost::shared_ptr<Job>);
+ void pause ();
+ void resume ();
+ bool paused () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _paused;
+ }
void analyse_audio (
boost::shared_ptr<const Film> film,
/** List of jobs in the order that they will be executed */
std::list<boost::shared_ptr<Job> > _jobs;
bool _terminate;
+ bool _paused;
+ boost::shared_ptr<Job> _paused_job;
boost::optional<std::string> _last_active_job;
boost::thread* _scheduler;
#include "lib/util.h"
#include "lib/film.h"
#include "lib/job_manager.h"
+#include "lib/job.h"
#include "lib/dcpomatic_socket.h"
#include <wx/aboutdlg.h>
#include <wx/stdpaths.h>
wxButton* add = new wxButton (panel, wxID_ANY, _("Add Film..."));
add->Bind (wxEVT_BUTTON, boost::bind (&DOMFrame::add_film, this));
buttons->Add (add, 1, wxALL, 6);
+ _pause = new wxButton (panel, wxID_ANY, _("Pause"));
+ _pause->Bind (wxEVT_BUTTON, boost::bind(&DOMFrame::pause, this));
+ buttons->Add (_pause, 1, wxALL, 6);
+ _resume = new wxButton (panel, wxID_ANY, _("Resume"));
+ _resume->Bind (wxEVT_BUTTON, boost::bind(&DOMFrame::resume, this));
+ buttons->Add (_resume, 1, wxALL, 6);
+
+ setup_sensitivity ();
_sizer->Add (buttons, 0, wxALL, 6);
Bind (wxEVT_SIZE, boost::bind (&DOMFrame::sized, this, _1));
}
+ void setup_sensitivity ()
+ {
+ _pause->Enable (!JobManager::instance()->paused());
+ _resume->Enable (JobManager::instance()->paused());
+ }
+
+ void pause ()
+ {
+ JobManager::instance()->pause ();
+ setup_sensitivity ();
+ }
+
+ void resume ()
+ {
+ JobManager::instance()->resume ();
+ setup_sensitivity ();
+ }
+
void start_job (boost::filesystem::path path)
{
try {
wxSizer* _sizer;
wxPreferencesEditor* _config_dialog;
ServersListDialog* _servers_list_dialog;
+ wxButton* _pause;
+ wxButton* _resume;
};
static const wxCmdLineEntryDesc command_line_description[] = {