Fix conflict with the batch thread. Make sure batch thread yields to the thread opening a preview. This should eliminate (all?) crashes when something is being done while batch is running.

This commit is contained in:
Andrey Skvortsov
2010-09-18 22:56:59 -07:00
parent 1464eed466
commit ce13359d38
3 changed files with 50 additions and 3 deletions

View File

@@ -20,6 +20,7 @@
#include <curves.h>
#include <mytime.h>
#include <refreshmap.h>
#include <simpleprocess.h>
#define CLIPTO(a,b,c) ((a)>b?((a)<c?(a):c):b)
#define CLIP(a) ((a)<65535 ? (a) : (65535));
@@ -561,7 +562,7 @@ void ImProcCoordinator::stopProcessing () {
void ImProcCoordinator::startProcessing () {
#undef THREAD_PRIORITY_LOW
#undef THREAD_PRIORITY_NORMAL
if (!destroying) {
updaterThreadStart.lock ();
@@ -569,7 +570,11 @@ void ImProcCoordinator::startProcessing () {
thread = NULL;
updaterRunning = true;
updaterThreadStart.unlock ();
thread = Glib::Thread::create(sigc::mem_fun(*this, &ImProcCoordinator::process), 0, false, true, Glib::THREAD_PRIORITY_LOW);
batchThread->yield(); //the running batch should wait other threads to avoid conflict
thread = Glib::Thread::create(sigc::mem_fun(*this, &ImProcCoordinator::process), 0, true, true, Glib::THREAD_PRIORITY_NORMAL);
}
else
updaterThreadStart.unlock ();

View File

@@ -29,6 +29,9 @@
#undef THREAD_PRIORITY_NORMAL
Glib::Thread *batchThread = NULL;
Glib::Mutex* qMutex = NULL;
namespace rtengine {
IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* pl) {
@@ -210,6 +213,10 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
void batchProcessingThread (ProcessingJob* job, BatchProcessingListener* bpl) {
if (!qMutex)
qMutex = new Glib::Mutex ();
qMutex->lock();
ProcessingJob* currentJob = job;
while (currentJob) {
@@ -219,12 +226,22 @@ void batchProcessingThread (ProcessingJob* job, BatchProcessingListener* bpl) {
bpl->error ("Can not load input image.");
currentJob = bpl->imageReady (img);
}
qMutex->unlock();
}
void startBatchProcessing (ProcessingJob* job, BatchProcessingListener* bpl) {
if (bpl)
Glib::Thread::create(sigc::bind(sigc::ptr_fun(batchProcessingThread), job, bpl), 0, false, true, Glib::THREAD_PRIORITY_LOW);
batchThread = Glib::Thread::create(sigc::bind(sigc::ptr_fun(batchProcessingThread), job, bpl), 0, true, true, Glib::THREAD_PRIORITY_LOW);
if(qMutex)
{
delete qMutex;
qMutex = NULL;
}
}
}

25
rtengine/simpleprocess.h Normal file
View File

@@ -0,0 +1,25 @@
/*
* File: simpleprocess.h
* Author: askv
*
* Created on September 18, 2010, 8:31 PM
*/
#ifndef SIMPLEPROCESS_H
#define SIMPLEPROCESS_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
extern Glib::Thread *batchThread;
#endif /* SIMPLEPROCESS_H */