Batch queue threading cleanup

(Hopefully a bit more stable, should only affect Windows so far)
This commit is contained in:
Oliver Duis 2011-11-04 16:45:39 +01:00
parent 400f5c75b8
commit 0438bf381b

View File

@ -16,10 +16,11 @@
* 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/>.
*/ */
#include <batchqueueentry.h> #include "batchqueueentry.h"
#include <thumbbrowserbase.h> #include "thumbbrowserbase.h"
#include <cstring> #include <cstring>
#include "guiutils.h"
BatchQueueEntry::BatchQueueEntry (rtengine::ProcessingJob* pjob, const rtengine::procparams::ProcParams& pparams, Glib::ustring fname, guint8* previmg, int prevw, int prevh, Thumbnail* thm) BatchQueueEntry::BatchQueueEntry (rtengine::ProcessingJob* pjob, const rtengine::procparams::ProcParams& pparams, Glib::ustring fname, guint8* previmg, int prevw, int prevh, Thumbnail* thm)
: ThumbBrowserEntryBase(fname), : ThumbBrowserEntryBase(fname),
@ -29,11 +30,13 @@ BatchQueueEntry::BatchQueueEntry (rtengine::ProcessingJob* pjob, const rtengine:
thumbnail=thm; thumbnail=thm;
params = pparams; params = pparams;
// The BatchQueueEntryIdleHelper tracks if #ifndef WIN32
// The BatchQueueEntryIdleHelper tracks if an entry has been deleted while it was sitting wating for "idle"
bqih = new BatchQueueEntryIdleHelper; bqih = new BatchQueueEntryIdleHelper;
bqih->bqentry = this; bqih->bqentry = this;
bqih->destroyed = false; bqih->destroyed = false;
bqih->pending = 0; bqih->pending = 0;
#endif
if (thumbnail) if (thumbnail)
thumbnail->increaseRef (); thumbnail->increaseRef ();
@ -42,14 +45,16 @@ BatchQueueEntry::BatchQueueEntry (rtengine::ProcessingJob* pjob, const rtengine:
BatchQueueEntry::~BatchQueueEntry () { BatchQueueEntry::~BatchQueueEntry () {
batchQueueEntryUpdater.removeJobs (this); batchQueueEntryUpdater.removeJobs (this);
delete [] opreview; delete [] opreview; opreview=NULL;
if (thumbnail) if (thumbnail)
thumbnail->decreaseRef (); thumbnail->decreaseRef ();
#ifndef WIN32
if (bqih->pending) if (bqih->pending)
bqih->destroyed = true; bqih->destroyed = true;
else else
delete bqih; delete bqih;
#endif
} }
void BatchQueueEntry::refreshThumbnailImage () { void BatchQueueEntry::refreshThumbnailImage () {
@ -57,7 +62,7 @@ void BatchQueueEntry::refreshThumbnailImage () {
if (!opreview) if (!opreview)
return; return;
batchQueueEntryUpdater.process (opreview, origpw, origph, preh, this); batchQueueEntryUpdater.process (opreview, origpw, origph, preh, this); // this will asynchronously land at this.updateImage
} }
void BatchQueueEntry::calcThumbnailSize () { void BatchQueueEntry::calcThumbnailSize () {
@ -102,6 +107,8 @@ void BatchQueueEntry::removeButtonSet () {
buttonSet = NULL; buttonSet = NULL;
} }
#ifndef WIN32
struct BQUpdateParam { struct BQUpdateParam {
BatchQueueEntryIdleHelper* bqih; BatchQueueEntryIdleHelper* bqih;
guint8* img; guint8* img;
@ -132,10 +139,20 @@ int updateImageUIThread (void* data) {
delete params; delete params;
return 0; return 0;
} }
#endif
// Starts a copy of img->preview via GTK thread // Starts a copy of img->preview via GTK thread
void BatchQueueEntry::updateImage (guint8* img, int w, int h) { void BatchQueueEntry::updateImage (guint8* img, int w, int h) {
// TODO: Check for Linux/Mac
#ifdef WIN32
// since the update itself is already called in an async thread and there are problem with accessing opreview in thumbbrowserbase,
// it's safer to do this synchrously
{
GThreadLock lock;
_updateImage(img,w,h);
}
#else
bqih->pending++; bqih->pending++;
BQUpdateParam* param = new BQUpdateParam (); BQUpdateParam* param = new BQUpdateParam ();
@ -144,6 +161,7 @@ void BatchQueueEntry::updateImage (guint8* img, int w, int h) {
param->w = w; param->w = w;
param->h = h; param->h = h;
g_idle_add (updateImageUIThread, param); g_idle_add (updateImageUIThread, param);
#endif
} }
void BatchQueueEntry::_updateImage (guint8* img, int w, int h) { void BatchQueueEntry::_updateImage (guint8* img, int w, int h) {