Threading cleanups
This commit is contained in:
parent
0583d2bc39
commit
c1a8e6bbbd
@ -91,7 +91,8 @@ void Crop::update (int todo) {
|
|||||||
bool needstransform = parent->ipf.needsTransform();
|
bool needstransform = parent->ipf.needsTransform();
|
||||||
|
|
||||||
if (todo & M_INIT) {
|
if (todo & M_INIT) {
|
||||||
parent->minit.lock ();
|
Glib::Mutex::Lock lock(parent->minit); // Also used in inproccoord
|
||||||
|
|
||||||
int tr = TR_NONE;
|
int tr = TR_NONE;
|
||||||
if (params.coarse.rotate==90) tr |= TR_R90;
|
if (params.coarse.rotate==90) tr |= TR_R90;
|
||||||
if (params.coarse.rotate==180) tr |= TR_R180;
|
if (params.coarse.rotate==180) tr |= TR_R180;
|
||||||
@ -103,8 +104,6 @@ void Crop::update (int todo) {
|
|||||||
setCropSizes (rqcropx, rqcropy, rqcropw, rqcroph, skip, true);
|
setCropSizes (rqcropx, rqcropy, rqcropw, rqcroph, skip, true);
|
||||||
PreviewProps pp (trafx, trafy, trafw*skip, trafh*skip, skip);
|
PreviewProps pp (trafx, trafy, trafw*skip, trafh*skip, skip);
|
||||||
parent->imgsrc->getImage (parent->currWB, tr, origCrop, pp, params.hlrecovery, params.icm, params.raw );
|
parent->imgsrc->getImage (parent->currWB, tr, origCrop, pp, params.hlrecovery, params.icm, params.raw );
|
||||||
|
|
||||||
parent->minit.unlock ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// transform
|
// transform
|
||||||
@ -134,7 +133,7 @@ void Crop::update (int todo) {
|
|||||||
if (colortest && cropw>115 && croph>115)
|
if (colortest && cropw>115 && croph>115)
|
||||||
for(int j=1;j<5;j++){
|
for(int j=1;j<5;j++){
|
||||||
xref+=j*30;yref+=j*30;
|
xref+=j*30;yref+=j*30;
|
||||||
printf("before rgbProc RGB Xr%i Yr%i Skip=%d R=%f G=%f B=%f gamma=%f \n",xref,yref,skip, \
|
if (settings->verbose) printf("before rgbProc RGB Xr%i Yr%i Skip=%d R=%f G=%f B=%f gamma=%f \n",xref,yref,skip, \
|
||||||
baseCrop->r[(int)(xref/skip)][(int)(yref/skip)]/256,\
|
baseCrop->r[(int)(xref/skip)][(int)(yref/skip)]/256,\
|
||||||
baseCrop->g[(int)(xref/skip)][(int)(yref/skip)]/256, \
|
baseCrop->g[(int)(xref/skip)][(int)(yref/skip)]/256, \
|
||||||
baseCrop->b[(int)(xref/skip)][(int)(yref/skip)]/256,
|
baseCrop->b[(int)(xref/skip)][(int)(yref/skip)]/256,
|
||||||
@ -148,6 +147,7 @@ void Crop::update (int todo) {
|
|||||||
if (colortest && cropw>115 && croph>115)
|
if (colortest && cropw>115 && croph>115)
|
||||||
for(int j=1;j<5;j++){
|
for(int j=1;j<5;j++){
|
||||||
xref+=j*30;yref+=j*30;
|
xref+=j*30;yref+=j*30;
|
||||||
|
if (settings->verbose) {
|
||||||
printf("after rgbProc RGB Xr%i Yr%i Skip=%d R=%f G=%f B=%f \n",xref,yref,skip, \
|
printf("after rgbProc RGB Xr%i Yr%i Skip=%d R=%f G=%f B=%f \n",xref,yref,skip, \
|
||||||
baseCrop->r[(int)(xref/skip)][(int)(yref/skip)]/256,\
|
baseCrop->r[(int)(xref/skip)][(int)(yref/skip)]/256,\
|
||||||
baseCrop->g[(int)(xref/skip)][(int)(yref/skip)]/256, \
|
baseCrop->g[(int)(xref/skip)][(int)(yref/skip)]/256, \
|
||||||
@ -157,6 +157,7 @@ void Crop::update (int todo) {
|
|||||||
laboCrop->a[(int)(xref/skip)][(int)(yref/skip)]/327, \
|
laboCrop->a[(int)(xref/skip)][(int)(yref/skip)]/327, \
|
||||||
laboCrop->b[(int)(xref/skip)][(int)(yref/skip)]/327);
|
laboCrop->b[(int)(xref/skip)][(int)(yref/skip)]/327);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// apply luminance operations
|
// apply luminance operations
|
||||||
if (todo & (M_LUMINANCE+M_COLOR)) {
|
if (todo & (M_LUMINANCE+M_COLOR)) {
|
||||||
|
@ -122,7 +122,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (todo & M_INIT) {
|
if (todo & M_INIT) {
|
||||||
Glib::Mutex::Lock lock(minit);
|
Glib::Mutex::Lock lock(minit); // Also used in crop window
|
||||||
|
|
||||||
if (settings->verbose) printf ("Applying white balance, color correction & sRBG conversion...\n");
|
if (settings->verbose) printf ("Applying white balance, color correction & sRBG conversion...\n");
|
||||||
currWB = ColorTemp (params.wb.temperature, params.wb.green);
|
currWB = ColorTemp (params.wb.temperature, params.wb.green);
|
||||||
@ -150,7 +150,6 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) {
|
|||||||
setScale (scale);
|
setScale (scale);
|
||||||
imgsrc->getImage (currWB, tr, orig_prev, pp, params.hlrecovery, params.icm, params.raw);
|
imgsrc->getImage (currWB, tr, orig_prev, pp, params.hlrecovery, params.icm, params.raw);
|
||||||
ipf.firstAnalysis (orig_prev, ¶ms, vhist16, imgsrc->getGamma());
|
ipf.firstAnalysis (orig_prev, ¶ms, vhist16, imgsrc->getGamma());
|
||||||
|
|
||||||
}
|
}
|
||||||
readyphase++;
|
readyphase++;
|
||||||
|
|
||||||
@ -313,7 +312,6 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) {
|
|||||||
hListener->histogramChanged (histRed, histGreen, histBlue, histLuma, histToneCurve, histLCurve, histRedRaw, histGreenRaw, histBlueRaw);
|
hListener->histogramChanged (histRed, histGreen, histBlue, histLuma, histToneCurve, histLCurve, histRedRaw, histGreenRaw, histBlueRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
progress ("Ready",100*readyphase/numofphases);
|
|
||||||
mProcessing.unlock ();
|
mProcessing.unlock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,6 +477,7 @@ void ImProcCoordinator::getSpotWB (int x, int y, int rect, double& temp, double&
|
|||||||
ColorTemp ret = imgsrc->getSpotWB (red, green, blue, tr);
|
ColorTemp ret = imgsrc->getSpotWB (red, green, blue, tr);
|
||||||
currWB = ColorTemp (params.wb.temperature, params.wb.green);
|
currWB = ColorTemp (params.wb.temperature, params.wb.green);
|
||||||
mProcessing.unlock ();
|
mProcessing.unlock ();
|
||||||
|
|
||||||
if (ret.getTemp() > 0) {
|
if (ret.getTemp() > 0) {
|
||||||
temp = ret.getTemp ();
|
temp = ret.getTemp ();
|
||||||
tgreen = ret.getGreen ();
|
tgreen = ret.getGreen ();
|
||||||
|
@ -208,8 +208,7 @@ void RawImageSource::transformRect (PreviewProps pp, int tran, int &ssx1, int &s
|
|||||||
|
|
||||||
void RawImageSource::getImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp, HRecParams hrp, ColorManagementParams cmp, RAWParams raw )
|
void RawImageSource::getImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp, HRecParams hrp, ColorManagementParams cmp, RAWParams raw )
|
||||||
{
|
{
|
||||||
|
Glib::Mutex::Lock lock(getImageMutex);
|
||||||
isrcMutex.lock ();
|
|
||||||
|
|
||||||
tran = defTransform (tran);
|
tran = defTransform (tran);
|
||||||
|
|
||||||
@ -421,8 +420,6 @@ void RawImageSource::getImage (ColorTemp ctemp, int tran, Imagefloat* image, Pre
|
|||||||
|
|
||||||
// Applying postmul
|
// Applying postmul
|
||||||
colorSpaceConversion (image, cmp, embProfile, camProfile, xyz_cam, defGain);
|
colorSpaceConversion (image, cmp, embProfile, camProfile, xyz_cam, defGain);
|
||||||
|
|
||||||
isrcMutex.unlock ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
@ -55,7 +55,7 @@ template<class T> void freeArray2 (T** a, int H) {
|
|||||||
class RawImageSource : public ImageSource {
|
class RawImageSource : public ImageSource {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Glib::Mutex isrcMutex;
|
Glib::Mutex getImageMutex; // locks getImage
|
||||||
|
|
||||||
int W, H;
|
int W, H;
|
||||||
ColorTemp wb;
|
ColorTemp wb;
|
||||||
|
@ -122,7 +122,8 @@ bool BatchQueue::saveBatchQueue( )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BatchQueue::loadBatchQueue( )
|
void BatchQueue::loadBatchQueue( )
|
||||||
|
{
|
||||||
{
|
{
|
||||||
// TODO: Check for Linux
|
// TODO: Check for Linux
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -133,8 +134,7 @@ bool BatchQueue::loadBatchQueue( )
|
|||||||
savedQueueFile = options.rtdir+"/batch/queue";
|
savedQueueFile = options.rtdir+"/batch/queue";
|
||||||
FILE *f = safe_g_fopen (savedQueueFile, "rt");
|
FILE *f = safe_g_fopen (savedQueueFile, "rt");
|
||||||
|
|
||||||
if (f==NULL)
|
if (f!=NULL) {
|
||||||
return false;
|
|
||||||
char *buffer = new char[1024];
|
char *buffer = new char[1024];
|
||||||
unsigned numLoaded=0;
|
unsigned numLoaded=0;
|
||||||
while (fgets (buffer, 1024, f)){
|
while (fgets (buffer, 1024, f)){
|
||||||
@ -181,9 +181,13 @@ bool BatchQueue::loadBatchQueue( )
|
|||||||
}
|
}
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
arrangeFiles ();
|
arrangeFiles ();
|
||||||
queue_draw ();
|
queue_draw ();
|
||||||
return numLoaded > 0;
|
|
||||||
|
notifyListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring BatchQueue::getTempFilenameForParams( const Glib::ustring filename )
|
Glib::ustring BatchQueue::getTempFilenameForParams( const Glib::ustring filename )
|
||||||
@ -239,6 +243,7 @@ void BatchQueue::cancelItems (std::vector<ThumbBrowserEntryBase*>* items) {
|
|||||||
|
|
||||||
saveBatchQueue( );
|
saveBatchQueue( );
|
||||||
}
|
}
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
notifyListener ();
|
notifyListener ();
|
||||||
}
|
}
|
||||||
@ -266,6 +271,7 @@ void BatchQueue::headItems (std::vector<ThumbBrowserEntryBase*>* items) {
|
|||||||
}
|
}
|
||||||
saveBatchQueue( );
|
saveBatchQueue( );
|
||||||
}
|
}
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,11 +293,12 @@ void BatchQueue::tailItems (std::vector<ThumbBrowserEntryBase*>* items) {
|
|||||||
}
|
}
|
||||||
saveBatchQueue( );
|
saveBatchQueue( );
|
||||||
}
|
}
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueue::selectAll () {
|
void BatchQueue::selectAll () {
|
||||||
// TODO: Check for Linux
|
{// TODO: Check for Linux
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
Glib::Mutex::Lock lock(entryMutex);
|
Glib::Mutex::Lock lock(entryMutex);
|
||||||
#endif
|
#endif
|
||||||
@ -304,6 +311,7 @@ void BatchQueue::selectAll () {
|
|||||||
fd[i]->selected = true;
|
fd[i]->selected = true;
|
||||||
selected.push_back (fd[i]);
|
selected.push_back (fd[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
queue_draw ();
|
queue_draw ();
|
||||||
}
|
}
|
||||||
void BatchQueue::startProcessing () {
|
void BatchQueue::startProcessing () {
|
||||||
|
@ -56,6 +56,7 @@ class BatchQueue : public ThumbBrowserBase,
|
|||||||
Glib::ustring autoCompleteFileName (const Glib::ustring& fileName, const Glib::ustring& format);
|
Glib::ustring autoCompleteFileName (const Glib::ustring& fileName, const Glib::ustring& format);
|
||||||
Glib::ustring getTempFilenameForParams( const Glib::ustring filename );
|
Glib::ustring getTempFilenameForParams( const Glib::ustring filename );
|
||||||
bool saveBatchQueue( );
|
bool saveBatchQueue( );
|
||||||
|
void notifyListener ();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BatchQueue ();
|
BatchQueue ();
|
||||||
@ -78,8 +79,8 @@ class BatchQueue : public ThumbBrowserBase,
|
|||||||
void redrawNeeded (LWButton* button);
|
void redrawNeeded (LWButton* button);
|
||||||
|
|
||||||
void setBatchQueueListener (BatchQueueListener* l) { listener = l; }
|
void setBatchQueueListener (BatchQueueListener* l) { listener = l; }
|
||||||
void notifyListener ();
|
|
||||||
bool loadBatchQueue ();
|
void loadBatchQueue ();
|
||||||
|
|
||||||
static Glib::ustring calcAutoFileNameBase (const Glib::ustring& origFileName);
|
static Glib::ustring calcAutoFileNameBase (const Glib::ustring& origFileName);
|
||||||
};
|
};
|
||||||
|
@ -56,8 +56,7 @@ void BatchQueueEntry::refreshThumbnailImage () {
|
|||||||
if (!opreview)
|
if (!opreview)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
batchQueueEntryUpdater.add (opreview, origpw, origph, preh, this);
|
batchQueueEntryUpdater.process (opreview, origpw, origph, preh, this);
|
||||||
batchQueueEntryUpdater.process ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueueEntry::calcThumbnailSize () {
|
void BatchQueueEntry::calcThumbnailSize () {
|
||||||
|
@ -133,7 +133,6 @@ BatchQueuePanel::BatchQueuePanel () {
|
|||||||
|
|
||||||
show_all ();
|
show_all ();
|
||||||
batchQueue->loadBatchQueue ();
|
batchQueue->loadBatchQueue ();
|
||||||
batchQueue->notifyListener ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@ BatchQueueEntryUpdater::BatchQueueEntryUpdater ()
|
|||||||
: tostop(false), stopped(true), qMutex(NULL) {
|
: tostop(false), stopped(true), qMutex(NULL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueueEntryUpdater::add (guint8* oimg, int ow, int oh, int newh, BQEntryUpdateListener* listener) {
|
void BatchQueueEntryUpdater::process (guint8* oimg, int ow, int oh, int newh, BQEntryUpdateListener* listener) {
|
||||||
|
|
||||||
if (!qMutex)
|
if (!qMutex)
|
||||||
qMutex = new Glib::Mutex ();
|
qMutex = new Glib::Mutex ();
|
||||||
|
|
||||||
@ -42,6 +41,7 @@ void BatchQueueEntryUpdater::add (guint8* oimg, int ow, int oh, int newh, BQEntr
|
|||||||
i->listener = listener;
|
i->listener = listener;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not found, create and append new job
|
// not found, create and append new job
|
||||||
if (i==jqueue.end ()) {
|
if (i==jqueue.end ()) {
|
||||||
Job j;
|
Job j;
|
||||||
@ -53,21 +53,18 @@ void BatchQueueEntryUpdater::add (guint8* oimg, int ow, int oh, int newh, BQEntr
|
|||||||
jqueue.push_back (j);
|
jqueue.push_back (j);
|
||||||
}
|
}
|
||||||
qMutex->unlock ();
|
qMutex->unlock ();
|
||||||
}
|
|
||||||
|
|
||||||
void BatchQueueEntryUpdater::process () {
|
|
||||||
|
|
||||||
|
// Start thread if not running yet
|
||||||
if (stopped) {
|
if (stopped) {
|
||||||
#undef THREAD_PRIORITY_LOW
|
|
||||||
thread = Glib::Thread::create(sigc::mem_fun(*this, &BatchQueueEntryUpdater::process_), (unsigned long int)0, true, true, Glib::THREAD_PRIORITY_LOW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BatchQueueEntryUpdater::process_ () {
|
|
||||||
|
|
||||||
stopped = false;
|
stopped = false;
|
||||||
tostop = false;
|
tostop = false;
|
||||||
|
|
||||||
|
#undef THREAD_PRIORITY_LOW
|
||||||
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &BatchQueueEntryUpdater::processThread), (unsigned long int)0, true, true, Glib::THREAD_PRIORITY_LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatchQueueEntryUpdater::processThread () {
|
||||||
// TODO: process visible jobs first
|
// TODO: process visible jobs first
|
||||||
bool isEmpty=false;
|
bool isEmpty=false;
|
||||||
|
|
||||||
@ -89,38 +86,13 @@ void BatchQueueEntryUpdater::process_ () {
|
|||||||
current.listener->updateImage (img, neww, current.newh);
|
current.listener->updateImage (img, neww, current.newh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stopped = true;
|
stopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueueEntryUpdater::stop () {
|
|
||||||
|
|
||||||
if (stopped) {
|
|
||||||
tostop = true;
|
|
||||||
return; }
|
|
||||||
|
|
||||||
gdk_threads_leave();
|
|
||||||
tostop = true;
|
|
||||||
Glib::Thread::self()->yield();
|
|
||||||
if (!stopped)
|
|
||||||
thread->join ();
|
|
||||||
gdk_threads_enter();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BatchQueueEntryUpdater::removeJobs () {
|
|
||||||
|
|
||||||
if (!qMutex)
|
|
||||||
return;
|
|
||||||
|
|
||||||
qMutex->lock ();
|
|
||||||
while (!jqueue.empty())
|
|
||||||
jqueue.pop_front ();
|
|
||||||
qMutex->unlock ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BatchQueueEntryUpdater::removeJobs (BQEntryUpdateListener* listener) {
|
void BatchQueueEntryUpdater::removeJobs (BQEntryUpdateListener* listener) {
|
||||||
|
if (!qMutex) return;
|
||||||
if (!qMutex)
|
|
||||||
return;
|
|
||||||
|
|
||||||
qMutex->lock ();
|
qMutex->lock ();
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
@ -138,9 +110,22 @@ void BatchQueueEntryUpdater::removeJobs (BQEntryUpdateListener* listener) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueueEntryUpdater::terminate () {
|
void BatchQueueEntryUpdater::terminate () {
|
||||||
|
// never started or currently not running?
|
||||||
|
if (!qMutex || stopped) return;
|
||||||
|
|
||||||
stop ();
|
if (!stopped) {
|
||||||
removeJobs ();
|
// Yield to currenly running thread and wait till it's finished
|
||||||
|
gdk_threads_leave();
|
||||||
|
tostop = true;
|
||||||
|
Glib::Thread::self()->yield();
|
||||||
|
if (!stopped) thread->join ();
|
||||||
|
gdk_threads_enter();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove remaining jobs
|
||||||
|
qMutex->lock ();
|
||||||
|
while (!jqueue.empty()) jqueue.pop_front ();
|
||||||
|
qMutex->unlock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,14 +47,11 @@ class BatchQueueEntryUpdater {
|
|||||||
public:
|
public:
|
||||||
BatchQueueEntryUpdater ();
|
BatchQueueEntryUpdater ();
|
||||||
|
|
||||||
void add (guint8* oimg, int ow, int oh, int newh, BQEntryUpdateListener* listener);
|
void process (guint8* oimg, int ow, int oh, int newh, BQEntryUpdateListener* listener);
|
||||||
void process ();
|
|
||||||
void stop ();
|
|
||||||
void removeJobs ();
|
|
||||||
void removeJobs (BQEntryUpdateListener* listener);
|
void removeJobs (BQEntryUpdateListener* listener);
|
||||||
void terminate ();
|
void terminate ();
|
||||||
|
|
||||||
void process_ ();
|
void processThread ();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern BatchQueueEntryUpdater batchQueueEntryUpdater;
|
extern BatchQueueEntryUpdater batchQueueEntryUpdater;
|
||||||
|
@ -48,7 +48,7 @@ struct iaimgpar {
|
|||||||
CropParams cp;
|
CropParams cp;
|
||||||
};
|
};
|
||||||
|
|
||||||
int iasetimage (void* data) {
|
int setImageThread (void* data) {
|
||||||
|
|
||||||
gdk_threads_enter ();
|
gdk_threads_enter ();
|
||||||
|
|
||||||
@ -66,13 +66,14 @@ int iasetimage (void* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pih->phandler->image) {
|
if (pih->phandler->image) {
|
||||||
IImage8* temp = pih->phandler->image;
|
IImage8* oldImg = pih->phandler->image;
|
||||||
temp->getMutex().lock ();
|
oldImg->getMutex().lock ();
|
||||||
pih->phandler->image = iap->image;
|
pih->phandler->image = iap->image;
|
||||||
temp->getMutex().unlock ();
|
oldImg->getMutex().unlock ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pih->phandler->image = iap->image;
|
pih->phandler->image = iap->image;
|
||||||
|
|
||||||
pih->phandler->cropParams = iap->cp;
|
pih->phandler->cropParams = iap->cp;
|
||||||
pih->phandler->previewScale = iap->scale;
|
pih->phandler->previewScale = iap->scale;
|
||||||
pih->pending--;
|
pih->pending--;
|
||||||
@ -93,10 +94,11 @@ void PreviewHandler::setImage (rtengine::IImage8* i, double scale, rtengine::pro
|
|||||||
iap->scale = scale;
|
iap->scale = scale;
|
||||||
iap->cp = cp;
|
iap->cp = cp;
|
||||||
|
|
||||||
g_idle_add (iasetimage, iap);
|
g_idle_add (setImageThread, iap);
|
||||||
}
|
}
|
||||||
|
|
||||||
int iadelimage (void* data) {
|
|
||||||
|
int delImageThread (void* data) {
|
||||||
|
|
||||||
gdk_threads_enter ();
|
gdk_threads_enter ();
|
||||||
|
|
||||||
@ -114,10 +116,10 @@ int iadelimage (void* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pih->phandler->image) {
|
if (pih->phandler->image) {
|
||||||
IImage8* temp = pih->phandler->image;
|
IImage8* oldImg = pih->phandler->image;
|
||||||
temp->getMutex().lock ();
|
oldImg->getMutex().lock ();
|
||||||
pih->phandler->image = NULL;
|
pih->phandler->image = NULL;
|
||||||
temp->getMutex().unlock ();
|
oldImg->getMutex().unlock ();
|
||||||
}
|
}
|
||||||
iap->image->free ();
|
iap->image->free ();
|
||||||
pih->phandler->previewImgMutex.lock ();
|
pih->phandler->previewImgMutex.lock ();
|
||||||
@ -140,10 +142,10 @@ void PreviewHandler::delImage (IImage8* i) {
|
|||||||
iap->image = i;
|
iap->image = i;
|
||||||
iap->pih = pih;
|
iap->pih = pih;
|
||||||
|
|
||||||
g_idle_add (iadelimage, iap);
|
g_idle_add (delImageThread, iap);
|
||||||
}
|
}
|
||||||
|
|
||||||
int imready (void* data) {
|
int imageReadyThread (void* data) {
|
||||||
|
|
||||||
gdk_threads_enter ();
|
gdk_threads_enter ();
|
||||||
|
|
||||||
@ -179,7 +181,7 @@ void PreviewHandler::imageReady (CropParams cp) {
|
|||||||
iaimgpar* iap = new iaimgpar;
|
iaimgpar* iap = new iaimgpar;
|
||||||
iap->pih = pih;
|
iap->pih = pih;
|
||||||
iap->cp = cp;
|
iap->cp = cp;
|
||||||
g_idle_add (imready, iap);
|
g_idle_add (imageReadyThread, iap);
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf> PreviewHandler::getRoughImage (int x, int y, int w, int h, double zoom) {
|
Glib::RefPtr<Gdk::Pixbuf> PreviewHandler::getRoughImage (int x, int y, int w, int h, double zoom) {
|
||||||
|
@ -38,9 +38,9 @@ struct PreviewHandlerIdleHelper {
|
|||||||
|
|
||||||
class PreviewHandler : public rtengine::PreviewImageListener {
|
class PreviewHandler : public rtengine::PreviewImageListener {
|
||||||
|
|
||||||
friend int iasetimage (void* data);
|
friend int setImageThread (void* data);
|
||||||
friend int iadelimage (void* data);
|
friend int delImageThread (void* data);
|
||||||
friend int imready (void* data);
|
friend int imageReadyThread (void* data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
rtengine::IImage8* image;
|
rtengine::IImage8* image;
|
||||||
|
@ -75,15 +75,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Glib::ThreadPool* threadPool_;
|
Glib::ThreadPool* threadPool_;
|
||||||
|
|
||||||
Glib::Mutex mutex_;
|
Glib::Mutex mutex_;
|
||||||
|
|
||||||
JobSet jobs_;
|
JobSet jobs_;
|
||||||
|
|
||||||
gint nConcurrentThreads;
|
gint nConcurrentThreads;
|
||||||
|
|
||||||
void
|
void processNextJob()
|
||||||
processNextJob(void)
|
|
||||||
{
|
{
|
||||||
Job j;
|
Job j;
|
||||||
{
|
{
|
||||||
@ -102,7 +98,9 @@ public:
|
|||||||
DEBUG("processing %s",j.dir_entry_.c_str());
|
DEBUG("processing %s",j.dir_entry_.c_str());
|
||||||
DEBUG("%d job(s) remaining",jobs_.size());
|
DEBUG("%d job(s) remaining",jobs_.size());
|
||||||
}
|
}
|
||||||
g_atomic_int_inc (&nConcurrentThreads);
|
|
||||||
|
g_atomic_int_inc (&nConcurrentThreads); // to detect when last thread in pool has run out
|
||||||
|
|
||||||
// unlock and do processing; will relock on block exit, then call listener
|
// unlock and do processing; will relock on block exit, then call listener
|
||||||
// if something got
|
// if something got
|
||||||
try {
|
try {
|
||||||
@ -114,22 +112,17 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we got something so notify listener
|
// we got something, so notify listener
|
||||||
if ( tmb )
|
if ( tmb )
|
||||||
{
|
{
|
||||||
j.listener_->previewReady(j.dir_id_,new FileBrowserEntry(tmb,j.dir_entry_));
|
j.listener_->previewReady(j.dir_id_,new FileBrowserEntry(tmb,j.dir_entry_));
|
||||||
}
|
}
|
||||||
}catch(Glib::Error){
|
} catch (Glib::Error){} catch(...){}
|
||||||
|
|
||||||
}catch(...){}
|
|
||||||
bool last = g_atomic_int_dec_and_test (&nConcurrentThreads);
|
bool last = g_atomic_int_dec_and_test (&nConcurrentThreads);
|
||||||
|
|
||||||
// signal at end
|
// signal at end
|
||||||
if ( jobs_.empty() )
|
if (last && jobs_.empty()) j.listener_->previewsFinished(j.dir_id_);
|
||||||
{
|
|
||||||
if(last)
|
|
||||||
j.listener_->previewsFinished(j.dir_id_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -138,29 +131,33 @@ PreviewLoader::PreviewLoader():
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PreviewLoader*
|
PreviewLoader* PreviewLoader::getInstance(void)
|
||||||
PreviewLoader::getInstance(void)
|
|
||||||
{
|
{
|
||||||
// this will not be deleted...
|
// this will not be deleted...
|
||||||
static PreviewLoader* instance_ = 0;
|
static PreviewLoader* instance_ = NULL;
|
||||||
if ( instance_ == 0 )
|
if ( instance_ == NULL )
|
||||||
{
|
{
|
||||||
instance_ = new PreviewLoader();
|
static Glib::Mutex smutex_;
|
||||||
|
Glib::Mutex::Lock lock(smutex_);
|
||||||
|
|
||||||
|
if ( instance_ == NULL ) instance_ = new PreviewLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PreviewLoader::add(int dir_id, const Glib::ustring& dir_entry, PreviewLoaderListener* l)
|
||||||
PreviewLoader::add(int dir_id, const Glib::ustring& dir_entry, PreviewLoaderListener* l)
|
|
||||||
{
|
{
|
||||||
// somebody listening?
|
// somebody listening?
|
||||||
if ( l != 0 )
|
if ( l != 0 )
|
||||||
|
{
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(impl_->mutex_);
|
Glib::Mutex::Lock lock(impl_->mutex_);
|
||||||
|
|
||||||
// create a new job and append to queue
|
// create a new job and append to queue
|
||||||
DEBUG("saving job %s",dir_entry.c_str());
|
DEBUG("saving job %s",dir_entry.c_str());
|
||||||
impl_->jobs_.insert(Impl::Job(dir_id,dir_entry,l));
|
impl_->jobs_.insert(Impl::Job(dir_id,dir_entry,l));
|
||||||
|
}
|
||||||
|
|
||||||
// queue a run request
|
// queue a run request
|
||||||
DEBUG("adding run request %s",dir_entry.c_str());
|
DEBUG("adding run request %s",dir_entry.c_str());
|
||||||
@ -168,8 +165,7 @@ PreviewLoader::add(int dir_id, const Glib::ustring& dir_entry, PreviewLoaderList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PreviewLoader::removeAllJobs(void)
|
||||||
PreviewLoader::removeAllJobs(void)
|
|
||||||
{
|
{
|
||||||
DEBUG("stop %d",impl_->nConcurrentThreads);
|
DEBUG("stop %d",impl_->nConcurrentThreads);
|
||||||
Glib::Mutex::Lock lock(impl_->mutex_);
|
Glib::Mutex::Lock lock(impl_->mutex_);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user