Replace g_idle_add_full() with IdleRegister (#3767)

This commit is contained in:
Flössie 2017-03-30 21:40:09 +02:00
parent 91f8e46029
commit 6e1f7df2fb
6 changed files with 64 additions and 62 deletions

View File

@ -24,14 +24,6 @@
#include "soundman.h" #include "soundman.h"
#include "rtimage.h" #include "rtimage.h"
int processLoadedBatchQueueUIThread (void* data)
{
BatchQueue* bq = static_cast<BatchQueue*>(data);
bq->resizeLoadedQueue();
return 0;
}
static Glib::ustring makeFolderLabel(Glib::ustring path) static Glib::ustring makeFolderLabel(Glib::ustring path)
{ {
if (!Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) { if (!Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) {
@ -185,11 +177,22 @@ BatchQueuePanel::BatchQueuePanel (FileCatalog* aFileCatalog)
show_all (); show_all ();
if (batchQueue->loadBatchQueue ()) { if (batchQueue->loadBatchQueue()) {
g_idle_add_full (G_PRIORITY_LOW, processLoadedBatchQueueUIThread, batchQueue, nullptr); const auto func = [](gpointer data) -> gboolean {
static_cast<BatchQueue*>(data)->resizeLoadedQueue();
return FALSE;
};
idle_register.add(func, batchQueue, G_PRIORITY_LOW);
} }
} }
BatchQueuePanel::~BatchQueuePanel()
{
idle_register.destroy();
}
void BatchQueuePanel::init (RTWindow *parent) void BatchQueuePanel::init (RTWindow *parent)
{ {
this->parent = parent; this->parent = parent;

View File

@ -53,9 +53,11 @@ class BatchQueuePanel : public Gtk::VBox,
Gtk::HBox* bottomBox; Gtk::HBox* bottomBox;
Gtk::HBox* topBox; Gtk::HBox* topBox;
public: IdleRegister idle_register;
public:
explicit BatchQueuePanel (FileCatalog* aFileCatalog); explicit BatchQueuePanel (FileCatalog* aFileCatalog);
~BatchQueuePanel();
void init (RTWindow* parent); void init (RTWindow* parent);

View File

@ -67,6 +67,7 @@ FileBrowserEntry::FileBrowserEntry (Thumbnail* thm, const Glib::ustring& fname)
FileBrowserEntry::~FileBrowserEntry () FileBrowserEntry::~FileBrowserEntry ()
{ {
idle_register.destroy();
// so jobs arriving now do nothing // so jobs arriving now do nothing
if (feih->pending) { if (feih->pending) {
@ -176,18 +177,45 @@ void FileBrowserEntry::procParamsChanged (Thumbnail* thm, int whoChangedIt)
} }
} }
struct tiupdate { void FileBrowserEntry::updateImage (rtengine::IImage8* img, double scale, rtengine::procparams::CropParams cropParams)
{
{
GThreadLock lock;
if ( feih == nullptr ||
feih->destroyed ) {
img->free();
return;
}
redrawRequests++;
feih->pending++;
}
struct tiupdate {
FileBrowserEntryIdleHelper* feih; FileBrowserEntryIdleHelper* feih;
rtengine::IImage8* img; rtengine::IImage8* img;
double scale; double scale;
rtengine::procparams::CropParams cropParams; rtengine::procparams::CropParams cropParams;
}; };
int updateImageUI (void* data) tiupdate* param = new tiupdate{
{ feih,
img,
scale,
cropParams
};
tiupdate* params = static_cast<tiupdate*>(data); #if __GNUC__ == 4 && __GNUC_MINOR__ == 8 && defined( WIN32 ) && defined(__x86_64__)
FileBrowserEntryIdleHelper* feih = params->feih; const gint priority = G_PRIORITY_DEFAULT;
#else
const gint priority = G_PRIORITY_LOW;
#endif
const auto func = [](gpointer data) -> gboolean {
tiupdate* const params = static_cast<tiupdate*>(data);
FileBrowserEntryIdleHelper* const feih = params->feih;
if (feih->destroyed) { if (feih->destroyed) {
if (feih->pending == 1) { if (feih->pending == 1) {
@ -206,35 +234,10 @@ int updateImageUI (void* data)
delete params; delete params;
return 0; return FALSE;
} };
void FileBrowserEntry::updateImage (rtengine::IImage8* img, double scale, rtengine::procparams::CropParams cropParams) idle_register.add(func, param, priority);
{
{
GThreadLock lock;
if ( feih == nullptr ||
feih->destroyed ) {
img->free();
return;
}
redrawRequests++;
feih->pending++;
}
tiupdate* param = new tiupdate ();
param->feih = feih;
param->img = img;
param->scale = scale;
param->cropParams = cropParams;
#if __GNUC__ == 4 && __GNUC_MINOR__ == 8 && defined( WIN32 ) && defined(__x86_64__)
g_idle_add_full (G_PRIORITY_DEFAULT, updateImageUI, param, NULL);
#else
g_idle_add_full (G_PRIORITY_LOW, updateImageUI, param, nullptr);
#endif
} }
void FileBrowserEntry::_updateImage (rtengine::IImage8* img, double s, rtengine::procparams::CropParams cropParams) void FileBrowserEntry::_updateImage (rtengine::IImage8* img, double s, rtengine::procparams::CropParams cropParams)

View File

@ -57,6 +57,8 @@ class FileBrowserEntry : public ThumbBrowserEntryBase,
ImgEditState state; ImgEditState state;
IdleRegister idle_register;
bool onArea (CursorArea a, int x, int y); bool onArea (CursorArea a, int x, int y);
void updateCursor (int x, int y); void updateCursor (int x, int y);
void drawStraightenGuide (Cairo::RefPtr<Cairo::Context> c); void drawStraightenGuide (Cairo::RefPtr<Cairo::Context> c);

View File

@ -38,18 +38,12 @@ Glib::RefPtr<Gdk::Pixbuf> MyExpander::disabledPBuf;
Glib::RefPtr<Gdk::Pixbuf> MyExpander::openedPBuf; Glib::RefPtr<Gdk::Pixbuf> MyExpander::openedPBuf;
Glib::RefPtr<Gdk::Pixbuf> MyExpander::closedPBuf; Glib::RefPtr<Gdk::Pixbuf> MyExpander::closedPBuf;
guint add_idle (GSourceFunc function, gpointer data)
{
return gdk_threads_add_idle(function, data);
//gtk_main_iteration_do(false);
}
IdleRegister::~IdleRegister() IdleRegister::~IdleRegister()
{ {
destroy(); destroy();
} }
void IdleRegister::add(GSourceFunc function, gpointer data) void IdleRegister::add(GSourceFunc function, gpointer data, gint priority)
{ {
struct DataWrapper { struct DataWrapper {
IdleRegister* const self; IdleRegister* const self;
@ -79,7 +73,7 @@ void IdleRegister::add(GSourceFunc function, gpointer data)
}; };
mutex.lock(); mutex.lock();
ids[data_wrapper] = add_idle(dispatch, data_wrapper); ids[data_wrapper] = gdk_threads_add_idle_full(priority, dispatch, data_wrapper, nullptr);
mutex.unlock(); mutex.unlock();
} }

View File

@ -44,15 +44,13 @@ void drawCrop (Cairo::RefPtr<Cairo::Context> cr, int imx, int imy, int imw, int
gboolean acquireGUI(void* data); gboolean acquireGUI(void* data);
void setExpandAlignProperties(Gtk::Widget *widget, bool hExpand, bool vExpand, enum Gtk::Align hAlign, enum Gtk::Align vAlign); void setExpandAlignProperties(Gtk::Widget *widget, bool hExpand, bool vExpand, enum Gtk::Align hAlign, enum Gtk::Align vAlign);
guint add_idle (GSourceFunc function, gpointer data);
class IdleRegister final : class IdleRegister final :
public rtengine::NonCopyable public rtengine::NonCopyable
{ {
public: public:
~IdleRegister(); ~IdleRegister();
void add(GSourceFunc function, gpointer data); void add(GSourceFunc function, gpointer data, gint priority = G_PRIORITY_DEFAULT_IDLE);
void destroy(); void destroy();
private: private: