paul@6 | 1 | #pragma once |
paul@6 | 2 | |
paul@6 | 3 | #include <condition_variable> |
paul@6 | 4 | #include <list> |
paul@6 | 5 | #include <map> |
paul@6 | 6 | #include <mutex> |
paul@6 | 7 | |
paul@6 | 8 | #include "flexpage.h" |
paul@6 | 9 | #include "page_owner.h" |
paul@6 | 10 | |
paul@6 | 11 | |
paul@6 | 12 | |
paul@6 | 13 | /* Collection types. */ |
paul@6 | 14 | |
paul@6 | 15 | typedef struct { Flexpage *flexpage; PageOwner *owner; } QueueEntry; |
paul@6 | 16 | typedef std::list<QueueEntry> Queue; |
paul@6 | 17 | |
paul@6 | 18 | typedef std::pair<Flexpage *, Queue::iterator> Position; |
paul@6 | 19 | typedef std::map<Flexpage *, Queue::iterator> Positions; |
paul@6 | 20 | |
paul@6 | 21 | |
paul@6 | 22 | |
paul@6 | 23 | /* A queue of issued pages. */ |
paul@6 | 24 | |
paul@6 | 25 | class PageQueue |
paul@6 | 26 | { |
paul@6 | 27 | protected: |
paul@6 | 28 | Queue _queue; |
paul@6 | 29 | Positions _positions; |
paul@6 | 30 | |
paul@6 | 31 | std::mutex _lock; |
paul@6 | 32 | std::condition_variable _counter; |
paul@6 | 33 | |
paul@6 | 34 | bool _pop(QueueEntry *entry); |
paul@6 | 35 | |
paul@6 | 36 | public: |
paul@6 | 37 | void pop(PageOwner **owner, Flexpage **flexpage); |
paul@6 | 38 | |
paul@6 | 39 | void push(PageOwner *owner, Flexpage *flexpage); |
paul@6 | 40 | |
paul@6 | 41 | void push_front(PageOwner *owner, Flexpage *flexpage); |
paul@6 | 42 | |
paul@6 | 43 | bool remove(PageOwner *owner, Flexpage *flexpage); |
paul@6 | 44 | }; |
paul@6 | 45 | |
paul@6 | 46 | // vim: tabstop=4 expandtab shiftwidth=4 |