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>
24 LoaderQueue & LoaderQueue::get()
26 static LoaderQueue singleton;
31 void LoaderQueue::loadNext()
34 lyxerr[Debug::GRAPHICS] << "LoaderQueue: "
35 << cache_queue_.size()
36 << " items in the queue" << endl;
38 while (cache_queue_.size() && counter--) {
39 if(cache_queue_.front()->status() == WaitingToLoad)
40 cache_queue_.front()->startLoading();
41 cache_set_.erase(cache_queue_.front());
42 cache_queue_.pop_front();
44 if (cache_queue_.size() || bucket_.size()) {
52 LoaderQueue::LoaderQueue() : timer(100, Timeout::ONETIME),
55 timer.timeout.connect(boost::bind(&LoaderQueue::loadNext, this));
59 void LoaderQueue::emptyBucket()
61 lyxerr[Debug::GRAPHICS] << "LoaderQueue: emptying bucket"
63 while (! bucket_.empty()) {
64 addToQueue(bucket_.front());
70 void LoaderQueue::startLoader()
72 lyxerr[Debug::GRAPHICS] << "LoaderQueue: waking up" << endl;
78 void LoaderQueue::stopLoader()
82 lyxerr[Debug::GRAPHICS] << "LoaderQueue: I'm going to sleep" << endl;
86 bool LoaderQueue::running() const
92 void LoaderQueue::touch(Cache::ItemPtr const & item)
100 void LoaderQueue::addToQueue(Cache::ItemPtr const & item)
102 if (! cache_set_.insert(item).second) {
103 list<Cache::ItemPtr>::iterator
104 it = cache_queue_.begin();
105 list<Cache::ItemPtr>::iterator
106 end = cache_queue_.end();
108 it = std::find(it, end, item);
110 cache_queue_.erase(it);
112 cache_queue_.push_front(item);