2 * \file LoaderQueue.cpp
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"
14 #include "GraphicsCacheItem.h"
18 #include <boost/bind.hpp>
26 int LoaderQueue::s_numimages_ = 5;
27 int LoaderQueue::s_millisecs_ = 500;
30 LoaderQueue & LoaderQueue::get()
32 static LoaderQueue singleton;
37 void LoaderQueue::loadNext()
39 LYXERR(Debug::GRAPHICS, "LoaderQueue: "
40 << cache_queue_.size() << " items in the queue");
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");
67 LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME),
70 timer.timeout.connect(boost::bind(&LoaderQueue::loadNext, this));
74 void LoaderQueue::startLoader()
76 LYXERR(Debug::GRAPHICS, "LoaderQueue: waking up");
78 timer.setTimeout(s_millisecs_);
83 void LoaderQueue::stopLoader()
87 LYXERR(Debug::GRAPHICS, "LoaderQueue: I'm going to sleep");
91 bool LoaderQueue::running() const
97 void LoaderQueue::touch(Cache::ItemPtr const & item)
99 if (! cache_set_.insert(item).second) {
100 list<Cache::ItemPtr>::iterator
101 it = cache_queue_.begin();
102 list<Cache::ItemPtr>::iterator
103 end = cache_queue_.end();
105 it = std::find(it, end, item);
107 cache_queue_.erase(it);
109 cache_queue_.push_front(item);
115 } // namespace graphics