Made background loader thread count dynamic, based on processor count. If there are >=4 processors, one processor is spared for snappy parallel image editing.

This commit is contained in:
Oliver Duis
2010-10-29 09:19:18 +02:00
parent bb1a7ce4bc
commit 93385fddfa
2 changed files with 48 additions and 19 deletions

View File

@@ -27,6 +27,10 @@
#include <thumbimageupdater.h> #include <thumbimageupdater.h>
#include <safegtk.h> #include <safegtk.h>
#ifdef _OPENMP
#include <omp.h>
#endif
#define CHECKTIME 2000 #define CHECKTIME 2000
extern Glib::ustring argv0; extern Glib::ustring argv0;
@@ -970,25 +974,50 @@ bool FileCatalog::handleShortcutKey (GdkEventKey* event) {
return false; return false;
} }
void PreviewMultiLoader::setPreviewLoaderListener (PreviewLoaderListener* p) { PreviewMultiLoader::PreviewMultiLoader () {
loadA.setPreviewLoaderListener(p); loadB.setPreviewLoaderListener(p); next=0;
loaderCount=1;
#ifdef _OPENMP
loaderCount=omp_get_num_procs();
// If there are pleny of processor, spare one for snappy image editing
if (loaderCount>3) loaderCount--;
#endif
loaders=new PreviewLoader[loaderCount];
}
void PreviewMultiLoader::setPreviewLoaderListener (PreviewLoaderListener* p) {
for (int i=0;i<loaderCount;i++) loaders[i].setPreviewLoaderListener(p);
} }
// Simple round robin // Simple round robin
void PreviewMultiLoader::add(DirEntry de) { void PreviewMultiLoader::add(DirEntry de) {
if (next==0) { loaders[next].add(de);
loadA.add(de); next++;
next=1; if (next>=loaderCount) next=0;
} else {
loadB.add(de);
next=0;
}
} }
void PreviewMultiLoader::start () { loadA.start(); loadB.start(); } void PreviewMultiLoader::start () {
void PreviewMultiLoader::process () { loadA.process (); loadB.process(); } for (int i=0;i<loaderCount;i++) loaders[i].start();
void PreviewMultiLoader::remove (Glib::ustring fname) { loadA.remove(fname); loadB.remove(fname); } }
void PreviewMultiLoader::end () { loadA.end(); loadB.end(); } void PreviewMultiLoader::process () {
bool PreviewMultiLoader::runs () { return loadA.runs() || loadB.runs(); } for (int i=0;i<loaderCount;i++) loaders[i].process ();
void PreviewMultiLoader::terminate () { loadA.terminate(); loadB.terminate(); } }
void PreviewMultiLoader::stop () { loadA.stop(); loadB.stop(); } void PreviewMultiLoader::remove (Glib::ustring fname) {
for (int i=0;i<loaderCount;i++) loaders[i].remove(fname);
}
void PreviewMultiLoader::end () {
for (int i=0;i<loaderCount;i++) loaders[i].end();
}
bool PreviewMultiLoader::runs () {
for (int i=0;i<loaderCount;i++) if (loaders[i].runs()) return true;
return false;
}
void PreviewMultiLoader::terminate () {
for (int i=0;i<loaderCount;i++) loaders[i].terminate();
}
void PreviewMultiLoader::stop () {
for (int i=0;i<loaderCount;i++) loaders[i].stop();
}

View File

@@ -71,11 +71,11 @@ class PreviewLoader : public ProcessingThread<DirEntry> {
// Same interface as a normal PreviewLoader to minimize effects on code // Same interface as a normal PreviewLoader to minimize effects on code
class PreviewMultiLoader { class PreviewMultiLoader {
protected: protected:
PreviewLoader loadA,loadB; PreviewLoader *loaders;
int next; int next,loaderCount;
public: public:
PreviewMultiLoader () { next=0; } PreviewMultiLoader ();
void setPreviewLoaderListener (PreviewLoaderListener* p); void setPreviewLoaderListener (PreviewLoaderListener* p);