3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
8 * Full author contact details are available in file CREDITS
11 #include "LoaderQueue.h"
15 #include <boost/bind.hpp>
23 int LoaderQueue::s_numimages_ = 5;
24 int LoaderQueue::s_millisecs_ = 500;
27 LoaderQueue & LoaderQueue::get()
29 static LoaderQueue singleton;
34 void LoaderQueue::loadNext()
36 lyxerr[Debug::GRAPHICS] << "LoaderQueue: "
37 << cache_queue_.size()
38 << " items in the queue" << endl;
39 int counter = s_numimages_;
40 while (cache_queue_.size() && counter--) {
41 Cache::ItemPtr ptr = cache_queue_.front();
42 cache_set_.erase(ptr);
43 cache_queue_.pop_front();
44 if (ptr->status() == WaitingToLoad)
47 if (cache_queue_.size()) {
55 void LoaderQueue::setPriority(int numimages , int millisecs)
57 s_numimages_ = numimages;
58 s_millisecs_ = millisecs;
59 lyxerr[Debug::GRAPHICS] << "LoaderQueue: priority set to "
60 << s_numimages_ << " images at a time, "
61 << s_millisecs_ << " milliseconds between calls"
66 LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME),
69 timer.timeout.connect(boost::bind(&LoaderQueue::loadNext, this));
73 void LoaderQueue::startLoader()
75 lyxerr[Debug::GRAPHICS] << "LoaderQueue: waking up" << endl;
77 timer.setTimeout(s_millisecs_);
82 void LoaderQueue::stopLoader()
86 lyxerr[Debug::GRAPHICS] << "LoaderQueue: I'm going to sleep" << endl;
90 bool LoaderQueue::running() const
96 void LoaderQueue::touch(Cache::ItemPtr const & item)
98 if (! cache_set_.insert(item).second) {
99 list<Cache::ItemPtr>::iterator
100 it = cache_queue_.begin();
101 list<Cache::ItemPtr>::iterator
102 end = cache_queue_.end();
104 it = std::find(it, end, item);
106 cache_queue_.erase(it);
108 cache_queue_.push_front(item);