Alfredo Braunstein wrote:

> A second option for LoaderQueue.
> I've left the previous interface untouched, but changed a little the
> implementation. Now touch() doesn't add directly the image pointer to the
> queue, but it adds it to an input bucket (implemented as a plain queue)
> without any checking and returns inmediately.
> Then on the 'threaded' method LoadNext we empty the input bucket into the
> queue, with all uniqueness and reprioritization checking.
> This implementation avoids completely having to lock the data, and so any
> posibility of losing time on the main thread.
> The startup time should be shorter also.
> 
> I have to solve at least one problem: the graphics insets have
> startLoading called in document order, from first to last. Then they are
> added to the queue in inversed order, and start loading from last to
> first. Maybe we have to bypass this reprioritizing mechanism on startup
> somehow? Any clue on how to solve this please?
> 
> (there are other remaining things if ever this gets incorporated: like to
> where the LoaderQueue class belongs (BufferView?).

It doesn't depend on BufferView. Why not make it a singleton class?

> Does it deserves its own file

Yes.

> PS: As before, please correct without mercy but being nice...

bucket1_ is filled with Cache::ItemPtrs to be dealt with by 
LoaderQueue::touch.

The timer calls LoaderQueue::loadNext every 100 ms.

LoaderQueue::loadNext calls
emptyBucket(), which:
        swap(bucket1_, bucket2_);
Why is bucket2_ a class member. It is used only in 
LoaderQueue::emptyBucket() and is guaranteed to be empty on entry and on 
exit to the method. In fact why not:
+void LoaderQueue::emptyBucket()
+{
+       cout << "emptying bucket" << endl;
+       while (! bucket1_.empty()) {
+               addToQueue(bucket1_.front());
+               bucket1_.pop();
+       }
+}

LoaderQueue::addToQueue takes this Cache::ItemPtr and adds it to the queue 
of items to be processed, cache_queue_, if not already there.

Why not:
        void LoaderQueue::addToQueue(Cache::ItemPtr & item)
(Ie, pass by reference). It isn't a simple pointer and so will add overhead 
passing by value as you do now.

Once cache_queue_ is initialised, loadNext instigates the actual loading of 
the Cache::ItemPtrs.

I'm a bit confused by cache_set_ and cache_queue_. Could you help me?

-- 
Angus

Reply via email to