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
13 #include "LoaderQueue.h"
17 #include <boost/bind.hpp>
25 int LoaderQueue::s_numimages_ = 5;
26 int LoaderQueue::s_millisecs_ = 500;
29 LoaderQueue & LoaderQueue::get()
31 static LoaderQueue singleton;
36 void LoaderQueue::loadNext()
38 lyxerr[Debug::GRAPHICS] << "LoaderQueue: "
39 << cache_queue_.size()
40 << " items in the queue" << endl;
41 int counter = s_numimages_;
42 while (cache_queue_.size() && counter--) {
43 Cache::ItemPtr ptr = cache_queue_.front();
44 cache_set_.erase(ptr);
45 cache_queue_.pop_front();
46 if (ptr->status() == WaitingToLoad)
49 if (cache_queue_.size()) {
57 void LoaderQueue::setPriority(int numimages , int millisecs)
59 s_numimages_ = numimages;
60 s_millisecs_ = millisecs;
61 lyxerr[Debug::GRAPHICS] << "LoaderQueue: priority set to "
62 << s_numimages_ << " images at a time, "
63 << s_millisecs_ << " milliseconds between calls"
68 LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME),
71 timer.timeout.connect(boost::bind(&LoaderQueue::loadNext, this));
75 void LoaderQueue::startLoader()
77 lyxerr[Debug::GRAPHICS] << "LoaderQueue: waking up" << endl;
79 timer.setTimeout(s_millisecs_);
84 void LoaderQueue::stopLoader()
88 lyxerr[Debug::GRAPHICS] << "LoaderQueue: I'm going to sleep" << endl;
92 bool LoaderQueue::running() const
98 void LoaderQueue::touch(Cache::ItemPtr const & item)
100 if (! cache_set_.insert(item).second) {
101 list<Cache::ItemPtr>::iterator
102 it = cache_queue_.begin();
103 list<Cache::ItemPtr>::iterator
104 end = cache_queue_.end();
106 it = std::find(it, end, item);
108 cache_queue_.erase(it);
110 cache_queue_.push_front(item);
116 } // namespace graphics