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 "rtimage.h"
int processLoadedBatchQueueUIThread (void* data)
{
BatchQueue* bq = static_cast<BatchQueue*>(data);
bq->resizeLoadedQueue();
return 0;
}
static Glib::ustring makeFolderLabel(Glib::ustring path)
{
if (!Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) {
@ -186,10 +178,21 @@ BatchQueuePanel::BatchQueuePanel (FileCatalog* aFileCatalog)
show_all ();
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)
{
this->parent = parent;

View File

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

View File

@ -67,6 +67,7 @@ FileBrowserEntry::FileBrowserEntry (Thumbnail* thm, const Glib::ustring& fname)
FileBrowserEntry::~FileBrowserEntry ()
{
idle_register.destroy();
// so jobs arriving now do nothing
if (feih->pending) {
@ -176,6 +177,22 @@ void FileBrowserEntry::procParamsChanged (Thumbnail* thm, int whoChangedIt)
}
}
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;
rtengine::IImage8* img;
@ -183,11 +200,22 @@ struct tiupdate {
rtengine::procparams::CropParams cropParams;
};
int updateImageUI (void* data)
{
tiupdate* param = new tiupdate{
feih,
img,
scale,
cropParams
};
tiupdate* params = static_cast<tiupdate*>(data);
FileBrowserEntryIdleHelper* feih = params->feih;
#if __GNUC__ == 4 && __GNUC_MINOR__ == 8 && defined( WIN32 ) && defined(__x86_64__)
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->pending == 1) {
@ -206,35 +234,10 @@ int updateImageUI (void* data)
delete params;
return 0;
}
return FALSE;
};
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++;
}
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
idle_register.add(func, param, priority);
}
void FileBrowserEntry::_updateImage (rtengine::IImage8* img, double s, rtengine::procparams::CropParams cropParams)

View File

@ -57,6 +57,8 @@ class FileBrowserEntry : public ThumbBrowserEntryBase,
ImgEditState state;
IdleRegister idle_register;
bool onArea (CursorArea a, int x, int y);
void updateCursor (int x, int y);
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::closedPBuf;
guint add_idle (GSourceFunc function, gpointer data)
{
return gdk_threads_add_idle(function, data);
//gtk_main_iteration_do(false);
}
IdleRegister::~IdleRegister()
{
destroy();
}
void IdleRegister::add(GSourceFunc function, gpointer data)
void IdleRegister::add(GSourceFunc function, gpointer data, gint priority)
{
struct DataWrapper {
IdleRegister* const self;
@ -79,7 +73,7 @@ void IdleRegister::add(GSourceFunc function, gpointer data)
};
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();
}

View File

@ -44,15 +44,13 @@ void drawCrop (Cairo::RefPtr<Cairo::Context> cr, int imx, int imy, int imw, int
gboolean acquireGUI(void* data);
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 :
public rtengine::NonCopyable
{
public:
~IdleRegister();
void add(GSourceFunc function, gpointer data);
void add(GSourceFunc function, gpointer data, gint priority = G_PRIORITY_DEFAULT_IDLE);
void destroy();
private: