improve stability for Cache Manager and thumbnails and avoid race conditions.
preparation step 3 for making dcraw multithread safe.
This commit is contained in:
@@ -194,7 +194,7 @@ void CacheManager::renameEntry (const std::string& oldfilename, const std::strin
|
||||
t->setFileName (newfilename);
|
||||
openEntries[newfilename] = t;
|
||||
t->updateCache ();
|
||||
t->reSaveThumbnail ();
|
||||
t->saveThumbnail ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -36,10 +36,9 @@ Thumbnail::Thumbnail (CacheManager* cm, const Glib::ustring& fname, CacheImageDa
|
||||
: fname(fname), cfs(*cf), cachemgr(cm), ref(1), enqueueNumber(0), tpp(NULL),
|
||||
pparamsValid(false), needsReProcessing(true), lastImg(NULL) {
|
||||
|
||||
mutex = new Glib::Mutex ();
|
||||
cfs.load (getCacheFileName ("data")+".txt");
|
||||
loadProcParams ();
|
||||
loadThumbnail ();
|
||||
_loadThumbnail ();
|
||||
generateExifDateTimeStrings ();
|
||||
}
|
||||
|
||||
@@ -47,18 +46,14 @@ Thumbnail::Thumbnail (CacheManager* cm, const Glib::ustring& fname, const std::s
|
||||
: fname(fname), cachemgr(cm), ref(1), enqueueNumber(0), tpp(NULL), pparamsValid(false),
|
||||
needsReProcessing(true), lastImg(NULL) {
|
||||
|
||||
mutex = new Glib::Mutex ();
|
||||
|
||||
cfs.md5 = md5;
|
||||
generateThumbnailImage ();
|
||||
_generateThumbnailImage ();
|
||||
loadProcParams ();
|
||||
cfs.recentlySaved = false;
|
||||
}
|
||||
|
||||
void Thumbnail::generateThumbnailImage (bool internal) {
|
||||
|
||||
if (!internal)
|
||||
mutex->lock ();
|
||||
void Thumbnail::_generateThumbnailImage () {
|
||||
|
||||
// delete everything loaded into memory
|
||||
delete tpp;
|
||||
@@ -103,7 +98,7 @@ void Thumbnail::generateThumbnailImage (bool internal) {
|
||||
}
|
||||
if (tpp) {
|
||||
// save thumbnail image to cache
|
||||
saveThumbnail ();
|
||||
_saveThumbnail ();
|
||||
cfs.supported = true;
|
||||
}
|
||||
needsReProcessing = true;
|
||||
@@ -111,9 +106,11 @@ void Thumbnail::generateThumbnailImage (bool internal) {
|
||||
cfs.save (getCacheFileName ("data")+".txt");
|
||||
|
||||
generateExifDateTimeStrings ();
|
||||
|
||||
if (!internal)
|
||||
mutex->unlock ();
|
||||
}
|
||||
|
||||
void Thumbnail::generateThumbnailImage () {
|
||||
Glib::Mutex::Lock lock(mutex);
|
||||
_generateThumbnailImage();
|
||||
}
|
||||
|
||||
bool Thumbnail::isSupported () {
|
||||
@@ -231,8 +228,24 @@ bool Thumbnail::isEnqueued () {
|
||||
return enqueueNumber > 0;
|
||||
}
|
||||
|
||||
void Thumbnail::increaseRef () { ref++; }
|
||||
void Thumbnail::decreaseRef () { ref--; if (!ref) cachemgr->closeThumbnail (this); }
|
||||
void Thumbnail::increaseRef ()
|
||||
{
|
||||
Glib::Mutex::Lock lock(mutex);
|
||||
++ref;
|
||||
}
|
||||
|
||||
void Thumbnail::decreaseRef ()
|
||||
{
|
||||
Glib::Mutex::Lock lock(mutex);
|
||||
if ( ref != 0 )
|
||||
{
|
||||
--ref;
|
||||
if ( ref == 0 )
|
||||
{
|
||||
cachemgr->closeThumbnail (this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Thumbnail::getThumbnailSize (int &w, int &h) {
|
||||
|
||||
@@ -244,14 +257,13 @@ void Thumbnail::getThumbnailSize (int &w, int &h) {
|
||||
|
||||
rtengine::IImage8* Thumbnail::processThumbImage (const rtengine::procparams::ProcParams& pparams, int h, double& scale) {
|
||||
|
||||
mutex->lock ();
|
||||
Glib::Mutex::Lock lock(mutex);
|
||||
|
||||
if (!tpp)
|
||||
return NULL;
|
||||
|
||||
rtengine::IImage8* res = tpp->processImage (pparams, h, rtengine::TI_Bilinear, scale);
|
||||
|
||||
mutex->unlock ();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -340,10 +352,7 @@ void Thumbnail::infoFromImage (const Glib::ustring& fname, rtengine::RawMetaData
|
||||
delete idata;
|
||||
}
|
||||
|
||||
void Thumbnail::loadThumbnail (bool internal, bool firstTrial) {
|
||||
|
||||
if (!internal)
|
||||
mutex->lock ();
|
||||
void Thumbnail::_loadThumbnail(bool firstTrial) {
|
||||
|
||||
needsReProcessing = true;
|
||||
delete tpp;
|
||||
@@ -357,9 +366,9 @@ void Thumbnail::loadThumbnail (bool internal, bool firstTrial) {
|
||||
succ = succ && tpp->readImage (getCacheFileName ("images"));
|
||||
|
||||
if (!succ && firstTrial) {
|
||||
generateThumbnailImage (true);
|
||||
_generateThumbnailImage ();
|
||||
if (cfs.supported && firstTrial)
|
||||
loadThumbnail (true, false);
|
||||
_loadThumbnail (false);
|
||||
}
|
||||
else if (!succ) {
|
||||
delete tpp;
|
||||
@@ -375,11 +384,14 @@ void Thumbnail::loadThumbnail (bool internal, bool firstTrial) {
|
||||
tpp->init ();
|
||||
|
||||
}
|
||||
if (!internal)
|
||||
mutex->unlock ();
|
||||
}
|
||||
|
||||
void Thumbnail::saveThumbnail () {
|
||||
void Thumbnail::loadThumbnail (bool firstTrial) {
|
||||
Glib::Mutex::Lock lock(mutex);
|
||||
_loadThumbnail(firstTrial);
|
||||
}
|
||||
|
||||
void Thumbnail::_saveThumbnail () {
|
||||
|
||||
if (!tpp)
|
||||
return;
|
||||
@@ -406,6 +418,12 @@ void Thumbnail::saveThumbnail () {
|
||||
tpp->writeData (getCacheFileName ("data")+".txt");
|
||||
}
|
||||
|
||||
void Thumbnail::saveThumbnail ()
|
||||
{
|
||||
Glib::Mutex::Lock lock(mutex);
|
||||
_saveThumbnail();
|
||||
}
|
||||
|
||||
void Thumbnail::updateCache () {
|
||||
|
||||
if (pparamsValid) {
|
||||
|
@@ -31,7 +31,7 @@
|
||||
class CacheManager;
|
||||
class Thumbnail {
|
||||
|
||||
Glib::Mutex* mutex;
|
||||
Glib::Mutex mutex;
|
||||
|
||||
Glib::ustring fname; // file name corresponding to the thumbnail
|
||||
CacheImageData cfs; // cache entry corresponding to the thumbnail
|
||||
@@ -61,9 +61,11 @@ class Thumbnail {
|
||||
// vector of listeners
|
||||
std::vector<ThumbnailListener*> listeners;
|
||||
|
||||
void _loadThumbnail (bool firstTrial=true);
|
||||
void _saveThumbnail ();
|
||||
void _generateThumbnailImage ();
|
||||
void infoFromImage (const Glib::ustring& fname, rtengine::RawMetaDataLocation* rml=NULL);
|
||||
void loadThumbnail (bool internal=false, bool firstTrial=true);
|
||||
void saveThumbnail ();
|
||||
void loadThumbnail (bool firstTrial=true);
|
||||
void generateExifDateTimeStrings ();
|
||||
|
||||
Glib::ustring getCacheFileName (Glib::ustring subdir);
|
||||
@@ -91,7 +93,7 @@ class Thumbnail {
|
||||
void getThumbnailSize (int &w, int &h);
|
||||
void getFinalSize (const rtengine::procparams::ProcParams& pparams, int& w, int& h) { if (tpp) tpp->getFinalSize (pparams, w, h); }
|
||||
|
||||
void generateThumbnailImage (bool internal=false);
|
||||
void generateThumbnailImage ();
|
||||
|
||||
const Glib::ustring& getExifString ();
|
||||
const Glib::ustring& getDateTimeString ();
|
||||
@@ -122,7 +124,7 @@ class Thumbnail {
|
||||
void decreaseRef ();
|
||||
|
||||
void updateCache ();
|
||||
void reSaveThumbnail () { mutex->lock (); saveThumbnail(); mutex->unlock(); }
|
||||
void saveThumbnail ();
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user