From: Angus Leeming Date: Tue, 25 Feb 2003 11:20:59 +0000 (+0000) Subject: Alfredo's setPriority patch to the graphics LoaderQueue. X-Git-Tag: 1.6.10~17453 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=ace7b30fb13d7fdd809633127175e3cef59cfd88;p=lyx.git Alfredo's setPriority patch to the graphics LoaderQueue. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6235 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 3a7e57061d..cbb3817807 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,7 @@ +2003-02-22 Alfredo Braunstein + + * lyx_gui.C (parse_init): added a call to LoaderQueue::setPriority + 2003-02-21 Angus Leeming * Timeout_pimpl.[Ch]: removed. diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index e78aa48fec..eecc425a57 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -24,6 +24,7 @@ #include "lyxrc.h" #include "lyxfont.h" #include "funcrequest.h" +#include "graphics/LoaderQueue.h" // FIXME: move this stuff out again #include "bufferlist.h" @@ -118,6 +119,8 @@ void lyx_gui::parse_init(int & argc, char * argv[]) lyxrc.dpi = getDPI(); initEncodings(); + + LoaderQueue::setPriority(10,100); } diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 3c4c399c4e..d3e96357fc 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2003-02-22 Alfredo Braunstein + + * lyx_gui.C (parse_init): added a call to LoaderQueue::setPriority + 2003-02-17 Rob Lahaye * FormBibTeX.C: add double click to choose from list. diff --git a/src/frontends/xforms/lyx_gui.C b/src/frontends/xforms/lyx_gui.C index 491534866f..0be4e51398 100644 --- a/src/frontends/xforms/lyx_gui.C +++ b/src/frontends/xforms/lyx_gui.C @@ -23,6 +23,7 @@ #include "lyx_main.h" #include "lyxrc.h" #include "lyxfont.h" +#include "graphics/LoaderQueue.h" // FIXME: move this stuff out again #include "bufferlist.h" @@ -171,6 +172,8 @@ void lyx_gui::parse_init(int & argc, char * argv[]) // must do this /before/ lyxrc gets read lyxrc.dpi = getDPI(); + + LoaderQueue::setPriority(10,100); } diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 788e5cf453..ff1909a8ef 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,10 @@ +2003-02-21 Alfredo Braunstein + + * LoaderQueue.[Ch] (setPriority): added + + * PreviewLoader.C (finishedGenerating): reversed the loading order so + first images get 'touched' last, and so load first. + 2003-02-20 Alfredo Braunstein * LoaderQueue.[Ch]: added. Implements a service queue that loads diff --git a/src/graphics/LoaderQueue.C b/src/graphics/LoaderQueue.C index 73062317b6..85f8311b51 100644 --- a/src/graphics/LoaderQueue.C +++ b/src/graphics/LoaderQueue.C @@ -20,6 +20,8 @@ using std::list; namespace grfx { +int LoaderQueue::s_numimages_ = 5; +int LoaderQueue::s_millisecs_ = 500; LoaderQueue & LoaderQueue::get() { @@ -34,7 +36,7 @@ void LoaderQueue::loadNext() lyxerr[Debug::GRAPHICS] << "LoaderQueue: " << cache_queue_.size() << " items in the queue" << endl; - int counter = 10; + int counter = s_numimages_; while (cache_queue_.size() && counter--) { if(cache_queue_.front()->status() == WaitingToLoad) cache_queue_.front()->startLoading(); @@ -49,7 +51,18 @@ void LoaderQueue::loadNext() } -LoaderQueue::LoaderQueue() : timer(100, Timeout::ONETIME), +void LoaderQueue::setPriority(int numimages , int millisecs) +{ + s_numimages_ = numimages; + s_millisecs_ = millisecs; + lyxerr[Debug::GRAPHICS] << "LoaderQueue: priority set to " + << s_numimages_ << " images at a time, " + << s_millisecs_ << " milliseconds between calls" + << endl; +} + + +LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME), running_(false) { timer.timeout.connect(boost::bind(&LoaderQueue::loadNext, this)); @@ -71,6 +84,7 @@ void LoaderQueue::startLoader() { lyxerr[Debug::GRAPHICS] << "LoaderQueue: waking up" << endl; running_ = true ; + timer.setTimeout(s_millisecs_); timer.start(); } diff --git a/src/graphics/LoaderQueue.h b/src/graphics/LoaderQueue.h index aec1c9d7d8..52db71313e 100644 --- a/src/graphics/LoaderQueue.h +++ b/src/graphics/LoaderQueue.h @@ -33,34 +33,48 @@ namespace grfx { class LoaderQueue { public: - //use this to request a loading + /// Use this to request that the item is loaded. void touch(Cache::ItemPtr const & item); - //query if the clock is ticking + /// Query whether the clock is ticking. bool running() const; - //get the and only instance of the class + ///get the and only instance of the class static LoaderQueue & get(); + /** Adjusts the queue priority: + * numimages is the number of images loaded in a particular call + * from the timer. + * millisecs is the time interval between calls. + * Higher numimages, lower millisecs means higher priority. + */ + static void setPriority(int numimages , int millisecs); private: - //this class is a singleton class... use LoaderQueue::get() instead + /// This class is a singleton class... use LoaderQueue::get() instead LoaderQueue(); - //in-progress loading queue (elements are unique here) + /// The in-progress loading queue (elements are unique here). std::list cache_queue_; - //makes faster the insertion of new elements + /// Used to make the insertion of new elements faster. std::set cache_set_; - //newly touched element go here, loadNext move them to cache_queue_ + /// Newly touched elements go here. loadNext moves them to cache_queue_ std::queue bucket_; - // + /// Timeout timer; - // + /// bool running_; - //moves bucket_ to cache_queue_ + /// + static int s_numimages_ ; + /// + static int s_millisecs_ ; + + /// Moves bucket_ to cache_queue_ void emptyBucket(); - //adds or reprioritizes one element in cache_queue_ + /// Adds or reprioritizes one element in cache_queue_ void addToQueue(Cache::ItemPtr const & item); - //this is the 'threaded' method, that does the loading in background + /** This is the 'threaded' method, that does the loading in the + * background. + */ void loadNext(); - // + /// void startLoader(); - // + /// void stopLoader(); }; diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index d2aef43d57..c5c4d4e9ab 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -543,8 +543,10 @@ void PreviewLoader::Impl::finishedGenerating(pid_t pid, int retval) in_progress_.erase(git); // Tell the outside world - std::list::const_iterator nit = newimages.begin(); - std::list::const_iterator nend = newimages.end(); + std::list::const_reverse_iterator + nit = newimages.rbegin(); + std::list::const_reverse_iterator + nend = newimages.rend(); for (; nit != nend; ++nit) { imageReady(*nit->get()); }