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 <options.h>
#include <progressdialog.h>
#include <progressconnector.h>
#include <rtwindow.h>
#include <guiutils.h>
#include <procparamchangers.h>
@ -514,11 +514,9 @@ bool EditorPanel::idle_saveImage (ProgressConnector<rtengine::IImage16*> *pc, Gl
if( img )
saveImage( img, fname, sf, findNewNameIfNeeded);
else{
gdk_threads_enter ();
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);
msgd.run ();
gdk_threads_leave ();
saveimgas->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");
}
}else{
gdk_threads_enter ();
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);
msgd.run ();
gdk_threads_leave ();
}
saveimgas->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),
sigc::bind(sigc::mem_fun(*this,&EditorPanel::idle_sentToGimp), ld, img, fileName));
}else{
gdk_threads_enter();
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);
msgd.run ();
gdk_threads_leave ();
saveimgas->set_sensitive(true);
sendtogimp->set_sensitive(true);
}
@ -752,13 +746,11 @@ bool EditorPanel::idle_sentToGimp(ProgressConnector<int> *pc,rtengine::IImage16*
}
if (!success) {
gdk_threads_enter ();
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_title (M("MAIN_BUTTON_SENDTOEDITOR"));
msgd->run ();
delete msgd;
gdk_threads_leave ();
}
}

View File

@ -31,7 +31,7 @@
#include <batchqueueentry.h>
#include <thumbnaillistener.h>
#include <navigator.h>
#include <progressdialog.h>
#include <progressconnector.h>
class EditorPanel;
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()));
epanel->open(thm, pc->returnValue() );
}else {
gdk_threads_enter ();
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);
msgd.run ();
gdk_threads_leave ();
}
delete pc;

View File

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

View File

@ -16,8 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PROGRESSDIALOG_
#define _PROGRESSDIALOG_
#ifndef _PROGRESSCONNECTOR_
#define _PROGRESSCONNECTOR_
#include <sigc++/sigc++.h>
#include <gtkmm.h>
@ -76,17 +76,23 @@ class PLDBridge : public rtengine::ProgressListener {
template<class T>
class ProgressConnector {
sigc::slot0<T> slotStart;
sigc::slot0<bool> slotEnd;
sigc::signal0<T> opStart;
sigc::signal0<bool> opEnd;
T retval;
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 () {
sigc::signal0<T> op;
sigc::connection conn= op.connect(slotStart);
retval = op.emit ();
conn.disconnect();
Glib::signal_idle().connect(slotEnd);
retval = opStart.emit ();
g_idle_add (ProgressConnector<T>::emitEndSignal, new sigc::signal0<bool> (opEnd));
workThread = 0;
}
@ -96,8 +102,8 @@ class ProgressConnector {
void startFunc (const sigc::slot0<T>& startHandler, const sigc::slot0<bool>& endHandler ) {
if( !workThread ){
slotStart = startHandler;
slotEnd = endHandler;
opStart.connect (startHandler);
opEnd.connect (endHandler);
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 <batchqueuepanel.h>
#include <set>
#include <progressdialog.h>
#include <progressconnector.h>
class RTWindow : public Gtk::Window, public rtengine::ProgressListener{