From: dooglus Date: Wed, 10 Oct 2007 21:37:00 +0000 (+0000) Subject: Use a checkbox in the gui (Toolbox > File > Setup > Misc) for single_threaded, rather... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=1f59228ea073eb60029cddfb4ee1a70de7f40f3d;p=synfig.git Use a checkbox in the gui (Toolbox > File > Setup > Misc) for single_threaded, rather than a compile-time #define. git-svn-id: http://svn.voria.com/code@898 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-studio/trunk/src/gtkmm/app.cpp b/synfig-studio/trunk/src/gtkmm/app.cpp index 673bfc4..5b4b54b 100644 --- a/synfig-studio/trunk/src/gtkmm/app.cpp +++ b/synfig-studio/trunk/src/gtkmm/app.cpp @@ -253,6 +253,7 @@ studio::Dock_Curves* dock_curves; std::list< etl::handle< studio::Module > > module_list_; bool studio::App::use_colorspace_gamma=true; +bool studio::App::single_threaded=true; static int max_recent_files_=25; int studio::App::get_max_recent_files() { return max_recent_files_; } @@ -601,6 +602,11 @@ public: value=strprintf("%s",Distance::system_name(App::distance_system).c_str()); return true; } + if(key=="single_threaded") + { + value=strprintf("%i",(int)App::single_threaded); + return true; + } if(key=="auto_recover_backup_interval") { value=strprintf("%i",App::auto_recover->get_timeout()); @@ -656,6 +662,12 @@ public: App::distance_system=Distance::ident_system(value);; return true; } + if(key=="single_threaded") + { + int i(atoi(value.c_str())); + App::single_threaded=i; + return true; + } return synfigapp::Settings::set_value(key,value); } @@ -668,6 +680,7 @@ public: ret.push_back("distance_system"); ret.push_back("file_history.size"); ret.push_back("use_colorspace_gamma"); + ret.push_back("single_threaded"); ret.push_back("auto_recover_backup_interval"); return ret; } @@ -1546,6 +1559,7 @@ App::reset_initial_window_configuration() synfigapp::Main::settings().set_value("dock.dialog.2.size","1045 235"); synfigapp::Main::settings().set_value("pref.distance_system","pt"); synfigapp::Main::settings().set_value("pref.use_colorspace_gamma","1"); + synfigapp::Main::settings().set_value("pref.single_threaded","0"); synfigapp::Main::settings().set_value("window.toolbox.pos","4 4"); } diff --git a/synfig-studio/trunk/src/gtkmm/app.h b/synfig-studio/trunk/src/gtkmm/app.h index adeef35..8ed0931 100644 --- a/synfig-studio/trunk/src/gtkmm/app.h +++ b/synfig-studio/trunk/src/gtkmm/app.h @@ -184,6 +184,8 @@ public: static bool use_colorspace_gamma; + static bool single_threaded; + /* -- ** -- S I G N A L S ------------------------------------------------------- */ diff --git a/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp b/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp index 3651b75..66e78c5 100644 --- a/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp +++ b/synfig-studio/trunk/src/gtkmm/asyncrenderer.cpp @@ -88,9 +88,7 @@ public: } }; std::list tile_queue; -#ifndef SINGLE_THREADED Glib::Mutex mutex; -#endif // SINGLE_THREADED #ifndef GLIB_DISPATCHER_BROKEN Glib::Dispatcher tile_ready_signal; @@ -125,9 +123,8 @@ public: } void set_dead() { -#ifndef SINGLE_THREADED - Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED + Glib::Mutex::Lock lock(mutex, NotLock); + if (!single_threaded()) lock.acquire(); alive_flag=false; } @@ -163,9 +160,8 @@ public: assert(surface); if(!alive_flag) return false; -#ifndef SINGLE_THREADED - Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED + Glib::Mutex::Lock lock(mutex, NotLock); + if (!single_threaded()) lock.acquire(); tile_queue.push_back(tile_t(surface,gx,gy)); if(tile_queue.size()==1) { @@ -187,9 +183,8 @@ public: void tile_ready() { -#ifndef SINGLE_THREADED - Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED + Glib::Mutex::Lock lock(mutex, NotLock); + if (!single_threaded()) lock.acquire(); if(!alive_flag) { tile_queue.clear(); @@ -209,20 +204,22 @@ public: virtual void end_frame() { -#ifndef SINGLE_THREADED - while(alive_flag) + if (!single_threaded()) { - Glib::Mutex::Lock lock(mutex); - if(!tile_queue.empty() && alive_flag) + while(alive_flag) { - if(cond_tile_queue_empty.timed_wait(mutex,Glib::TimeVal(0,BOREDOM_TIMEOUT))) + Glib::Mutex::Lock lock(mutex); + if(!tile_queue.empty() && alive_flag) + { + if(cond_tile_queue_empty.timed_wait(mutex,Glib::TimeVal(0,BOREDOM_TIMEOUT))) + break; + } + else break; } - else - break; } - Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED + Glib::Mutex::Lock lock(mutex, NotLock); + if (!single_threaded()) lock.acquire(); if(!alive_flag) return; return warm_target->end_frame(); @@ -239,9 +236,7 @@ public: int scanline_; Surface surface; -#ifndef SINGLE_THREADED Glib::Mutex mutex; -#endif // SINGLE_THREADED #ifndef GLIB_DISPATCHER_BROKEN Glib::Dispatcher frame_ready_signal; @@ -284,9 +279,8 @@ public: void set_dead() { -#ifndef SINGLE_THREADED - Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED + Glib::Mutex::Lock lock(mutex, NotLock); + if (!single_threaded()) lock.acquire(); alive_flag=false; } @@ -298,9 +292,8 @@ public: virtual void end_frame() { { -#ifndef SINGLE_THREADED - Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED + Glib::Mutex::Lock lock(mutex, NotLock); + if (!single_threaded()) lock.acquire(); if(!alive_flag) return; @@ -317,24 +310,22 @@ public: #else frame_ready_signal(); #endif - } - -#ifndef SINGLE_THREADED - while(alive_flag && !ready_next) - { - Glib::Mutex::Lock lock(mutex); - if(cond_frame_queue_empty.timed_wait(mutex,Glib::TimeVal(0,BOREDOM_TIMEOUT))) - break; } -#endif // SINGLE_THREADED + + if (!single_threaded()) + while(alive_flag && !ready_next) + { + Glib::Mutex::Lock lock(mutex); + if(cond_frame_queue_empty.timed_wait(mutex,Glib::TimeVal(0,BOREDOM_TIMEOUT))) + break; + } } virtual Color * start_scanline(int scanline) { -#ifndef SINGLE_THREADED - Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED + Glib::Mutex::Lock lock(mutex, NotLock); + if (!single_threaded()) lock.acquire(); return surface[scanline]; } @@ -346,12 +337,11 @@ public: void frame_ready() { -#ifndef SINGLE_THREADED - Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED + Glib::Mutex::Lock lock(mutex, NotLock); + if (!single_threaded()) lock.acquire(); if(alive_flag) alive_flag=warm_target->add_frame(&surface); - cond_frame_queue_empty.signal(); + if (!single_threaded()) cond_frame_queue_empty.signal(); ready_next=true; } }; @@ -365,10 +355,8 @@ public: AsyncRenderer::AsyncRenderer(etl::handle target_,synfig::ProgressCallback *cb): error(false), success(false), - cb(cb) -#ifdef SINGLE_THREADED - , updating(false) -#endif // SINGLE_THREADED + cb(cb), + updating(false) { render_thread=0; if(etl::handle::cast_dynamic(target_)) @@ -405,19 +393,16 @@ AsyncRenderer::stop() { if(target) { -#ifndef SINGLE_THREADED - Glib::Mutex::Lock lock(mutex); -#endif // SINGLE_THREADED + Glib::Mutex::Lock lock(mutex, NotLock); + if (!single_threaded()) lock.acquire(); done_connection.disconnect(); if(render_thread) { signal_stop_(); -#ifndef SINGLE_THREADED #if REJOIN_ON_STOP - render_thread->join(); -#endif + if (!single_threaded()) render_thread->join(); #endif // Make sure all the dispatch crap is cleared out @@ -456,7 +441,6 @@ AsyncRenderer::start() ); } -#ifdef SINGLE_THREADED void AsyncRenderer::rendering_progress() { @@ -464,7 +448,6 @@ AsyncRenderer::rendering_progress() while(studio::App::events_pending()) studio::App::iteration(false); updating = false; } -#endif // SINGLE_THREADED void AsyncRenderer::start_() @@ -476,22 +459,25 @@ AsyncRenderer::start_() done_connection=signal_done_.connect(mem_fun(*this,&AsyncRenderer::stop)); #endif -#ifdef SINGLE_THREADED - synfig::info("%s:%d rendering in the same thread", __FILE__, __LINE__); - target->signal_progress().connect(sigc::mem_fun(this,&AsyncRenderer::rendering_progress)); - render_thread = (Glib::Thread*)1; - render_target(); -#else // SINGLE_THREADED - render_thread=Glib::Thread::create( - sigc::mem_fun(*this,&AsyncRenderer::render_target), + if (single_threaded()) + { + synfig::info("%s:%d rendering in the same thread", __FILE__, __LINE__); + target->signal_progress().connect(sigc::mem_fun(this,&AsyncRenderer::rendering_progress)); + render_thread = (Glib::Thread*)1; + render_target(); + } + else + { + render_thread=Glib::Thread::create( + sigc::mem_fun(*this,&AsyncRenderer::render_target), #if REJOIN_ON_STOP - true + true #else - false + false #endif - ); - assert(render_thread); -#endif // SINGLE_THREADED + ); + assert(render_thread); + } } else { @@ -516,9 +502,7 @@ AsyncRenderer::render_target() #endif } -#ifndef SINGLE_THREADED - if(mutex.trylock()) -#endif // SINGLE_THREADED + if (single_threaded() || mutex.trylock()) { #ifdef GLIB_DISPATCHER_BROKEN done_connection=Glib::signal_timeout().connect( @@ -531,8 +515,6 @@ AsyncRenderer::render_target() #else signal_done_.emit(); #endif -#ifndef SINGLE_THREADED - mutex.unlock(); -#endif // SINGLE_THREADED + if (!single_threaded()) mutex.unlock(); } } diff --git a/synfig-studio/trunk/src/gtkmm/asyncrenderer.h b/synfig-studio/trunk/src/gtkmm/asyncrenderer.h index c3a922e..04adab7 100644 --- a/synfig-studio/trunk/src/gtkmm/asyncrenderer.h +++ b/synfig-studio/trunk/src/gtkmm/asyncrenderer.h @@ -42,8 +42,8 @@ /* === M A C R O S ========================================================= */ -// uncomment to use a single thread, and hopefully get more stability -// #define SINGLE_THREADED +#define single_threaded() App::single_threaded +#define NotLock Glib::NOT_LOCK /* === T Y P E D E F S ===================================================== */ @@ -86,12 +86,12 @@ public: void stop(); void pause(); void resume(); + void rendering_progress(); bool has_error()const { return error; } bool has_success()const { return success; } -#ifdef SINGLE_THREADED + bool updating; -#endif // SINGLE_THREADED sigc::signal& signal_finished() { return signal_finished_; } sigc::signal& signal_success() { return signal_success_; } @@ -100,7 +100,6 @@ private: void render_target(); void start_(); - void rendering_progress(); /* -- ** -- C H I L D M E M B E R S ------------------------------------------- diff --git a/synfig-studio/trunk/src/gtkmm/dialog_setup.cpp b/synfig-studio/trunk/src/gtkmm/dialog_setup.cpp index fecf24d..88ca532 100644 --- a/synfig-studio/trunk/src/gtkmm/dialog_setup.cpp +++ b/synfig-studio/trunk/src/gtkmm/dialog_setup.cpp @@ -65,7 +65,8 @@ Dialog_Setup::Dialog_Setup(): adj_gamma_b(2.2,0.1,3.0,0.025,0.025,0.025), adj_recent_files(15,1,50,1,1,1), adj_undo_depth(100,10,5000,1,1,1), - toggle_use_colorspace_gamma(_("Visually Linear Color Selection")) + toggle_use_colorspace_gamma(_("Visually Linear Color Selection")), + toggle_single_threaded(_("Use Only a Single Thread")) { // Setup the buttons @@ -180,6 +181,9 @@ Dialog_Setup::Dialog_Setup(): // Misc - use_colorspace_gamma misc_table->attach(toggle_use_colorspace_gamma, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0); + // Misc - single_threaded + misc_table->attach(toggle_single_threaded, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0); + show_all_children(); } @@ -207,6 +211,9 @@ Dialog_Setup::on_apply_pressed() // Set the use_colorspace_gamma flag App::use_colorspace_gamma=toggle_use_colorspace_gamma.get_active(); + // Set the single_threaded flag + App::single_threaded=toggle_single_threaded.get_active(); + App::distance_system=Distance::System(widget_enum->get_value()); App::save_settings(); @@ -281,6 +288,9 @@ Dialog_Setup::refresh() // Refresh the status of the use_colorspace_gamma flag toggle_use_colorspace_gamma.set_active(App::use_colorspace_gamma); + + // Refresh the status of the single_threaded flag + toggle_single_threaded.set_active(App::single_threaded); } GammaPattern::GammaPattern(): diff --git a/synfig-studio/trunk/src/gtkmm/dialog_setup.h b/synfig-studio/trunk/src/gtkmm/dialog_setup.h index 133ab7b..d16aac6 100644 --- a/synfig-studio/trunk/src/gtkmm/dialog_setup.h +++ b/synfig-studio/trunk/src/gtkmm/dialog_setup.h @@ -162,6 +162,7 @@ class Dialog_Setup : public Gtk::Dialog Gtk::Adjustment adj_undo_depth; Gtk::CheckButton toggle_use_colorspace_gamma; + Gtk::CheckButton toggle_single_threaded; synfig::Time::Format time_format; diff --git a/synfig-studio/trunk/src/gtkmm/workarea.cpp b/synfig-studio/trunk/src/gtkmm/workarea.cpp index 64860e7..54216f3 100644 --- a/synfig-studio/trunk/src/gtkmm/workarea.cpp +++ b/synfig-studio/trunk/src/gtkmm/workarea.cpp @@ -2174,13 +2174,11 @@ public: bool studio::WorkArea::async_update_preview() { -#ifdef SINGLE_THREADED - if (async_renderer && async_renderer->updating == true) + if (single_threaded() && async_renderer && async_renderer->updating == true) { async_renderer->stop(); return false; } -#endif // SINGLE_THREADED async_renderer=0;