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;
26 LoaderQueue & LoaderQueue::get()
28 static LoaderQueue singleton;
33 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 if(cache_queue_.front()->status() == WaitingToLoad)
42 cache_queue_.front()->startLoading();
43 cache_set_.erase(cache_queue_.front());
44 cache_queue_.pop_front();
46 if (cache_queue_.size() || bucket_.size()) {
54 void LoaderQueue::setPriority(int numimages , int millisecs)
56 s_numimages_ = numimages;
57 s_millisecs_ = millisecs;
58 lyxerr[Debug::GRAPHICS] << "LoaderQueue: priority set to "
59 << s_numimages_ << " images at a time, "
60 << s_millisecs_ << " milliseconds between calls"
65 LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME),
68 timer.timeout.connect(boost::bind(&LoaderQueue::loadNext, this));
72 void LoaderQueue::emptyBucket()
74 lyxerr[Debug::GRAPHICS] << "LoaderQueue: emptying bucket"
76 while (! bucket_.empty()) {
77 addToQueue(bucket_.front());
83 void LoaderQueue::startLoader()
85 lyxerr[Debug::GRAPHICS] << "LoaderQueue: waking up" << endl;
87 timer.setTimeout(s_millisecs_);
92 void LoaderQueue::stopLoader()
96 lyxerr[Debug::GRAPHICS] << "LoaderQueue: I'm going to sleep" << endl;
100 bool LoaderQueue::running() const
106 void LoaderQueue::touch(Cache::ItemPtr const & item)
114 void LoaderQueue::addToQueue(Cache::ItemPtr const & item)
116 if (! cache_set_.insert(item).second) {
117 list<Cache::ItemPtr>::iterator
118 it = cache_queue_.begin();
119 list<Cache::ItemPtr>::iterator
120 end = cache_queue_.end();
122 it = std::find(it, end, item);
124 cache_queue_.erase(it);
126 cache_queue_.push_front(item);