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()
41 << " items in the queue" << endl
;
42 int counter
= s_numimages_
;
43 while (cache_queue_
.size() && counter
--) {
44 Cache::ItemPtr ptr
= cache_queue_
.front();
45 cache_set_
.erase(ptr
);
46 cache_queue_
.pop_front();
47 if (ptr
->status() == WaitingToLoad
)
50 if (cache_queue_
.size()) {
58 void LoaderQueue::setPriority(int numimages
, int millisecs
)
60 s_numimages_
= numimages
;
61 s_millisecs_
= millisecs
;
62 LYXERR(Debug::GRAPHICS
) << "LoaderQueue: priority set to "
63 << s_numimages_
<< " images at a time, "
64 << s_millisecs_
<< " milliseconds between calls"
69 LoaderQueue::LoaderQueue() : timer(s_millisecs_
, Timeout::ONETIME
),
72 timer
.timeout
.connect(boost::bind(&LoaderQueue::loadNext
, this));
76 void LoaderQueue::startLoader()
78 LYXERR(Debug::GRAPHICS
) << "LoaderQueue: waking up" << endl
;
80 timer
.setTimeout(s_millisecs_
);
85 void LoaderQueue::stopLoader()
89 LYXERR(Debug::GRAPHICS
) << "LoaderQueue: I'm going to sleep" << endl
;
93 bool LoaderQueue::running() const
99 void LoaderQueue::touch(Cache::ItemPtr
const & item
)
101 if (! cache_set_
.insert(item
).second
) {
102 list
<Cache::ItemPtr
>::iterator
103 it
= cache_queue_
.begin();
104 list
<Cache::ItemPtr
>::iterator
105 end
= cache_queue_
.end();
107 it
= std::find(it
, end
, item
);
109 cache_queue_
.erase(it
);
111 cache_queue_
.push_front(item
);
117 } // namespace graphics