Make ProgressConnector thread-safe

This commit is contained in:
gabor 2010-05-20 16:00:43 +02:00
parent 81cba00bc4
commit c5a72d2d84
7 changed files with 21 additions and 81 deletions

View File

@ -18,7 +18,7 @@
*/ */
#include <editorpanel.h> #include <editorpanel.h>
#include <options.h> #include <options.h>
#include <progressdialog.h> #include <progressconnector.h>
#include <rtwindow.h> #include <rtwindow.h>
#include <guiutils.h> #include <guiutils.h>
#include <procparamchangers.h> #include <procparamchangers.h>
@ -514,11 +514,9 @@ bool EditorPanel::idle_saveImage (ProgressConnector<rtengine::IImage16*> *pc, Gl
if( img ) if( img )
saveImage( img, fname, sf, findNewNameIfNeeded); saveImage( img, fname, sf, findNewNameIfNeeded);
else{ else{
gdk_threads_enter ();
Glib::ustring msg_ = Glib::ustring("<b>") + fname + ": Error during image processing\n</b>"; Glib::ustring msg_ = Glib::ustring("<b>") + fname + ": Error during image processing\n</b>";
Gtk::MessageDialog msgd (*parent, msg_, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); Gtk::MessageDialog msgd (*parent, msg_, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run (); msgd.run ();
gdk_threads_leave ();
saveimgas->set_sensitive(true); saveimgas->set_sensitive(true);
sendtogimp->set_sensitive(true); sendtogimp->set_sensitive(true);
@ -575,11 +573,9 @@ bool EditorPanel::idle_imageSaved(ProgressConnector<int> *pc,rtengine::IImage16*
pparams.save (removeExtension (fname) + ".out.pp2"); pparams.save (removeExtension (fname) + ".out.pp2");
} }
}else{ }else{
gdk_threads_enter ();
Glib::ustring msg_ = Glib::ustring("<b>") + fname + ": Error during image saving\n</b>"; Glib::ustring msg_ = Glib::ustring("<b>") + fname + ": Error during image saving\n</b>";
Gtk::MessageDialog msgd (*parent, msg_, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); Gtk::MessageDialog msgd (*parent, msg_, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run (); msgd.run ();
gdk_threads_leave ();
} }
saveimgas->set_sensitive(true); saveimgas->set_sensitive(true);
sendtogimp->set_sensitive(true); sendtogimp->set_sensitive(true);
@ -687,11 +683,9 @@ bool EditorPanel::idle_sendToGimp( ProgressConnector<rtengine::IImage16*> *pc){
ld->startFunc (sigc::bind(sigc::mem_fun(img, &rtengine::IImage16::saveAsTIFF), fileName, sf.tiffBits, sf.tiffUncompressed), ld->startFunc (sigc::bind(sigc::mem_fun(img, &rtengine::IImage16::saveAsTIFF), fileName, sf.tiffBits, sf.tiffUncompressed),
sigc::bind(sigc::mem_fun(*this,&EditorPanel::idle_sentToGimp), ld, img, fileName)); sigc::bind(sigc::mem_fun(*this,&EditorPanel::idle_sentToGimp), ld, img, fileName));
}else{ }else{
gdk_threads_enter();
Glib::ustring msg_ = Glib::ustring("<b> Error during image processing\n</b>"); Glib::ustring msg_ = Glib::ustring("<b> Error during image processing\n</b>");
Gtk::MessageDialog msgd (*parent, msg_, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); Gtk::MessageDialog msgd (*parent, msg_, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run (); msgd.run ();
gdk_threads_leave ();
saveimgas->set_sensitive(true); saveimgas->set_sensitive(true);
sendtogimp->set_sensitive(true); sendtogimp->set_sensitive(true);
} }
@ -752,13 +746,11 @@ bool EditorPanel::idle_sentToGimp(ProgressConnector<int> *pc,rtengine::IImage16*
} }
if (!success) { if (!success) {
gdk_threads_enter ();
Gtk::MessageDialog* msgd = new Gtk::MessageDialog (*parent, M("MAIN_MSG_CANNOTSTARTEDITOR"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); Gtk::MessageDialog* msgd = new Gtk::MessageDialog (*parent, M("MAIN_MSG_CANNOTSTARTEDITOR"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd->set_secondary_text (M("MAIN_MSG_CANNOTSTARTEDITOR_SECONDARY")); msgd->set_secondary_text (M("MAIN_MSG_CANNOTSTARTEDITOR_SECONDARY"));
msgd->set_title (M("MAIN_BUTTON_SENDTOEDITOR")); msgd->set_title (M("MAIN_BUTTON_SENDTOEDITOR"));
msgd->run (); msgd->run ();
delete msgd; delete msgd;
gdk_threads_leave ();
} }
} }

View File

@ -31,7 +31,7 @@
#include <batchqueueentry.h> #include <batchqueueentry.h>
#include <thumbnaillistener.h> #include <thumbnaillistener.h>
#include <navigator.h> #include <navigator.h>
#include <progressdialog.h> #include <progressconnector.h>
class EditorPanel; class EditorPanel;
struct EditorPanelIdleHelper { struct EditorPanelIdleHelper {

View File

@ -151,11 +151,9 @@ bool FilePanel::imageLoaded( Thumbnail* thm, ProgressConnector<rtengine::Initial
parent->addEditorPanel (epanel,Glib::path_get_basename (thm->getFileName())); parent->addEditorPanel (epanel,Glib::path_get_basename (thm->getFileName()));
epanel->open(thm, pc->returnValue() ); epanel->open(thm, pc->returnValue() );
}else { }else {
gdk_threads_enter ();
Glib::ustring msg_ = Glib::ustring("<b>") + M("MAIN_MSG_CANNOTLOAD") + " \"" + thm->getFileName() + "\" .\n</b>"; Glib::ustring msg_ = Glib::ustring("<b>") + M("MAIN_MSG_CANNOTLOAD") + " \"" + thm->getFileName() + "\" .\n</b>";
Gtk::MessageDialog msgd (msg_, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); Gtk::MessageDialog msgd (msg_, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run (); msgd.run ();
gdk_threads_leave ();
} }
delete pc; delete pc;

View File

@ -29,7 +29,7 @@
#include <pparamschangelistener.h> #include <pparamschangelistener.h>
#include <history.h> #include <history.h>
#include <filterpanel.h> #include <filterpanel.h>
#include <progressdialog.h> #include <progressconnector.h>
class RTWindow; class RTWindow;
class FilePanel : public Gtk::HPaned, class FilePanel : public Gtk::HPaned,

View File

@ -16,8 +16,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>. * along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _PROGRESSDIALOG_ #ifndef _PROGRESSCONNECTOR_
#define _PROGRESSDIALOG_ #define _PROGRESSCONNECTOR_
#include <sigc++/sigc++.h> #include <sigc++/sigc++.h>
#include <gtkmm.h> #include <gtkmm.h>
@ -76,17 +76,23 @@ class PLDBridge : public rtengine::ProgressListener {
template<class T> template<class T>
class ProgressConnector { class ProgressConnector {
sigc::slot0<T> slotStart; sigc::signal0<T> opStart;
sigc::slot0<bool> slotEnd; sigc::signal0<bool> opEnd;
T retval; T retval;
Glib::Thread *workThread; Glib::Thread *workThread;
static int emitEndSignal (void* data) {
gdk_threads_enter ();
sigc::signal0<bool>* opEnd = (sigc::signal0<bool>*) data;
int r = opEnd->emit ();
delete opEnd;
gdk_threads_leave ();
return r;
}
void workingThread () { void workingThread () {
sigc::signal0<T> op; retval = opStart.emit ();
sigc::connection conn= op.connect(slotStart); g_idle_add (ProgressConnector<T>::emitEndSignal, new sigc::signal0<bool> (opEnd));
retval = op.emit ();
conn.disconnect();
Glib::signal_idle().connect(slotEnd);
workThread = 0; workThread = 0;
} }
@ -96,8 +102,8 @@ class ProgressConnector {
void startFunc (const sigc::slot0<T>& startHandler, const sigc::slot0<bool>& endHandler ) { void startFunc (const sigc::slot0<T>& startHandler, const sigc::slot0<bool>& endHandler ) {
if( !workThread ){ if( !workThread ){
slotStart = startHandler; opStart.connect (startHandler);
slotEnd = endHandler; opEnd.connect (endHandler);
workThread = Glib::Thread::create(sigc::mem_fun(*this, &ProgressConnector<T>::workingThread), 0, true, true, Glib::THREAD_PRIORITY_NORMAL); workThread = Glib::Thread::create(sigc::mem_fun(*this, &ProgressConnector<T>::workingThread), 0, true, true, Glib::THREAD_PRIORITY_NORMAL);
} }
} }

View File

@ -1,56 +0,0 @@
/*
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#include <progressdialog.h>
template<class T>
ProgressDialog::ProgressDialog (const sigc::slot0<T>& slot) {
set_deletable (false);
operation.connect (slot);
}
template<class T>
void ProgressDialog::start () {
T ret = operation.emit ();
}
template<class T>
void ProgressDialog::finish () {
gtk_threads_enter ();
hide ();
gtk_threads_leave ();
}
template<class T>
void ProgressDialog::setProgress (double p) {
}
template<class T>
void ProgressDialog::setProgressStr (Glib::ustring str) {
}
template<class T>
void ProgressDialog::setProgressState (int state) {
}
template<class T>
void ProgressDialog::error (Glib::ustring descr) {
}

View File

@ -24,7 +24,7 @@
#include <editorpanel.h> #include <editorpanel.h>
#include <batchqueuepanel.h> #include <batchqueuepanel.h>
#include <set> #include <set>
#include <progressdialog.h> #include <progressconnector.h>
class RTWindow : public Gtk::Window, public rtengine::ProgressListener{ class RTWindow : public Gtk::Window, public rtengine::ProgressListener{