| 50 | typedef std::list<std::pair<unsigned, T> > ListPairs; |
| 51 | |
| 52 | struct SubQueue { |
| 53 | private: |
| 54 | typedef std::map<K, ListPairs> Classes; |
| 55 | Classes q; |
| 56 | unsigned tokens, max_tokens; |
| 57 | int64_t size; |
| 58 | typename Classes::iterator cur; |
| 59 | public: |
| 60 | SubQueue(const SubQueue &other) |
| 61 | : q(other.q), |
| 62 | tokens(other.tokens), |
| 63 | max_tokens(other.max_tokens), |
| 64 | size(other.size), |
| 65 | cur(q.begin()) {} |
| 66 | SubQueue() |
| 67 | : tokens(0), |
| 68 | max_tokens(0), |
| 69 | size(0), cur(q.begin()) {} |
| 70 | void set_max_tokens(unsigned mt) { |
| 71 | max_tokens = mt; |
| 72 | } |
| 73 | unsigned get_max_tokens() const { |
| 74 | return max_tokens; |
| 75 | } |
| 76 | unsigned num_tokens() const { |
| 77 | return tokens; |
| 78 | } |
| 79 | void put_tokens(unsigned t) { |
| 80 | tokens += t; |
| 81 | if (tokens > max_tokens) { |
| 82 | tokens = max_tokens; |
| 83 | } |
| 84 | } |
| 85 | void take_tokens(unsigned t) { |
| 86 | if (tokens > t) { |
| 87 | tokens -= t; |
| 88 | } else { |
| 89 | tokens = 0; |
| 90 | } |
| 91 | } |
| 92 | void enqueue(K cl, unsigned cost, T &&item) { |
| 93 | q[cl].push_back(std::make_pair(cost, std::move(item))); |
| 94 | if (cur == q.end()) |
| 95 | cur = q.begin(); |
| 96 | size++; |
| 97 | } |
| 98 | void enqueue_front(K cl, unsigned cost, T &&item) { |
| 99 | q[cl].push_front(std::make_pair(cost, std::move(item))); |
| 100 | if (cur == q.end()) |
| 101 | cur = q.begin(); |
| 102 | size++; |
| 103 | } |
| 104 | std::pair<unsigned, T> &front() const { |
| 105 | ceph_assert(!(q.empty())); |
| 106 | ceph_assert(cur != q.end()); |
| 107 | return cur->second.front(); |
| 108 | } |
| 109 | T pop_front() { |