| 91 | } |
| 92 | |
| 93 | size_t GetNextThreadIndexForTask_() { |
| 94 | if (taskThreads_.size() == 0) throw std::runtime_error("Task threads size equal to 0"); |
| 95 | |
| 96 | // Enter the threads with their current number of work items in a list |
| 97 | bool found = false; |
| 98 | const auto currentId = Thread::Current().Id(); |
| 99 | std::vector<std::pair<ThreadHandle, size_t>> currentWorkLoads; |
| 100 | currentWorkLoads.reserve(threadToIndexMap_.size()); |
| 101 | for (const auto& entry : threadToIndexMap_) { |
| 102 | if (entry.first == currentId) continue; |
| 103 | currentWorkLoads.push_back(std::make_pair(entry.first, threadsWorking_[entry.second]->load())); |
| 104 | } |
| 105 | |
| 106 | const auto comparison = [](const std::pair<ThreadHandle, size_t>& a, const std::pair<ThreadHandle, size_t>& b) { |
| 107 | return a.second < b.second; |
| 108 | }; |
| 109 | |
| 110 | // Sort the threads based on how much work they currently have |
| 111 | std::sort(currentWorkLoads.begin(), currentWorkLoads.end(), comparison); |
| 112 | |
| 113 | // Choose the first which should have the least work items |
| 114 | return threadToIndexMap_.find(currentWorkLoads[0].first)->second; |
| 115 | } |
| 116 | |
| 117 | template<typename E, typename T> |
| 118 | Async<E> ScheduleTask_(const T& process) { |
no outgoing calls
no test coverage detected