diff options
Diffstat (limited to 'src/common/thread_queue_list.h')
| -rw-r--r-- | src/common/thread_queue_list.h | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/common/thread_queue_list.h b/src/common/thread_queue_list.h index 12455d7c4..edd0e4a3f 100644 --- a/src/common/thread_queue_list.h +++ b/src/common/thread_queue_list.h | |||
| @@ -6,12 +6,11 @@ | |||
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <deque> | 8 | #include <deque> |
| 9 | |||
| 10 | #include <boost/range/algorithm_ext/erase.hpp> | 9 | #include <boost/range/algorithm_ext/erase.hpp> |
| 11 | 10 | ||
| 12 | namespace Common { | 11 | namespace Common { |
| 13 | 12 | ||
| 14 | template<class T, unsigned int N> | 13 | template <class T, unsigned int N> |
| 15 | struct ThreadQueueList { | 14 | struct ThreadQueueList { |
| 16 | // TODO(yuriks): If performance proves to be a problem, the std::deques can be replaced with | 15 | // TODO(yuriks): If performance proves to be a problem, the std::deques can be replaced with |
| 17 | // (dynamically resizable) circular buffers to remove their overhead when | 16 | // (dynamically resizable) circular buffers to remove their overhead when |
| @@ -39,7 +38,7 @@ struct ThreadQueueList { | |||
| 39 | } | 38 | } |
| 40 | 39 | ||
| 41 | T get_first() { | 40 | T get_first() { |
| 42 | Queue *cur = first; | 41 | Queue* cur = first; |
| 43 | while (cur != nullptr) { | 42 | while (cur != nullptr) { |
| 44 | if (!cur->data.empty()) { | 43 | if (!cur->data.empty()) { |
| 45 | return cur->data.front(); | 44 | return cur->data.front(); |
| @@ -51,7 +50,7 @@ struct ThreadQueueList { | |||
| 51 | } | 50 | } |
| 52 | 51 | ||
| 53 | T pop_first() { | 52 | T pop_first() { |
| 54 | Queue *cur = first; | 53 | Queue* cur = first; |
| 55 | while (cur != nullptr) { | 54 | while (cur != nullptr) { |
| 56 | if (!cur->data.empty()) { | 55 | if (!cur->data.empty()) { |
| 57 | auto tmp = std::move(cur->data.front()); | 56 | auto tmp = std::move(cur->data.front()); |
| @@ -65,8 +64,8 @@ struct ThreadQueueList { | |||
| 65 | } | 64 | } |
| 66 | 65 | ||
| 67 | T pop_first_better(Priority priority) { | 66 | T pop_first_better(Priority priority) { |
| 68 | Queue *cur = first; | 67 | Queue* cur = first; |
| 69 | Queue *stop = &queues[priority]; | 68 | Queue* stop = &queues[priority]; |
| 70 | while (cur < stop) { | 69 | while (cur < stop) { |
| 71 | if (!cur->data.empty()) { | 70 | if (!cur->data.empty()) { |
| 72 | auto tmp = std::move(cur->data.front()); | 71 | auto tmp = std::move(cur->data.front()); |
| @@ -80,12 +79,12 @@ struct ThreadQueueList { | |||
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | void push_front(Priority priority, const T& thread_id) { | 81 | void push_front(Priority priority, const T& thread_id) { |
| 83 | Queue *cur = &queues[priority]; | 82 | Queue* cur = &queues[priority]; |
| 84 | cur->data.push_front(thread_id); | 83 | cur->data.push_front(thread_id); |
| 85 | } | 84 | } |
| 86 | 85 | ||
| 87 | void push_back(Priority priority, const T& thread_id) { | 86 | void push_back(Priority priority, const T& thread_id) { |
| 88 | Queue *cur = &queues[priority]; | 87 | Queue* cur = &queues[priority]; |
| 89 | cur->data.push_back(thread_id); | 88 | cur->data.push_back(thread_id); |
| 90 | } | 89 | } |
| 91 | 90 | ||
| @@ -96,12 +95,12 @@ struct ThreadQueueList { | |||
| 96 | } | 95 | } |
| 97 | 96 | ||
| 98 | void remove(Priority priority, const T& thread_id) { | 97 | void remove(Priority priority, const T& thread_id) { |
| 99 | Queue *cur = &queues[priority]; | 98 | Queue* cur = &queues[priority]; |
| 100 | boost::remove_erase(cur->data, thread_id); | 99 | boost::remove_erase(cur->data, thread_id); |
| 101 | } | 100 | } |
| 102 | 101 | ||
| 103 | void rotate(Priority priority) { | 102 | void rotate(Priority priority) { |
| 104 | Queue *cur = &queues[priority]; | 103 | Queue* cur = &queues[priority]; |
| 105 | 104 | ||
| 106 | if (cur->data.size() > 1) { | 105 | if (cur->data.size() > 1) { |
| 107 | cur->data.push_back(std::move(cur->data.front())); | 106 | cur->data.push_back(std::move(cur->data.front())); |
| @@ -115,7 +114,7 @@ struct ThreadQueueList { | |||
| 115 | } | 114 | } |
| 116 | 115 | ||
| 117 | bool empty(Priority priority) const { | 116 | bool empty(Priority priority) const { |
| 118 | const Queue *cur = &queues[priority]; | 117 | const Queue* cur = &queues[priority]; |
| 119 | return cur->data.empty(); | 118 | return cur->data.empty(); |
| 120 | } | 119 | } |
| 121 | 120 | ||
| @@ -139,7 +138,7 @@ private: | |||
| 139 | } | 138 | } |
| 140 | 139 | ||
| 141 | void link(Priority priority) { | 140 | void link(Priority priority) { |
| 142 | Queue *cur = &queues[priority]; | 141 | Queue* cur = &queues[priority]; |
| 143 | 142 | ||
| 144 | for (int i = priority - 1; i >= 0; --i) { | 143 | for (int i = priority - 1; i >= 0; --i) { |
| 145 | if (queues[i].next_nonempty != UnlinkedTag()) { | 144 | if (queues[i].next_nonempty != UnlinkedTag()) { |