MCPcopy Create free account
hub / github.com/KTStephano/StratusGFX / GetNextThreadIndexForTask_

Function GetNextThreadIndexForTask_

Source/Engine/StratusTaskSystem.h:93–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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) {

Callers 2

ScheduleTask_Function · 0.85
ScheduleVoidTask_Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected