mirror of https://github.com/OpenRCT2/OpenRCT2.git
Use std::list and fixed step size.
This commit is contained in:
parent
b9e0eede44
commit
7be1cd3e37
|
@ -20,6 +20,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "Console.hpp"
|
#include "Console.hpp"
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
|
@ -192,7 +193,7 @@ private:
|
||||||
|
|
||||||
if (_log_levels[DIAGNOSTIC_LEVEL_VERBOSE])
|
if (_log_levels[DIAGNOSTIC_LEVEL_VERBOSE])
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(printLock);
|
std::lock_guard<std::mutex> lock(printLock);
|
||||||
log_verbose("FileIndex:Indexing '%s'", filePath.c_str());
|
log_verbose("FileIndex:Indexing '%s'", filePath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,21 +218,17 @@ private:
|
||||||
JobPool jobPool;
|
JobPool jobPool;
|
||||||
std::mutex printLock; // For verbose prints.
|
std::mutex printLock; // For verbose prints.
|
||||||
|
|
||||||
std::vector<std::vector<TItem>> containers;
|
std::list<std::vector<TItem>> containers;
|
||||||
|
|
||||||
size_t stepSize = std::thread::hardware_concurrency();
|
size_t stepSize = 100; // Handpicked, seems to work well with 4/8 cores.
|
||||||
size_t numTasks = totalCount / stepSize;
|
|
||||||
size_t taskGroup = 0;
|
|
||||||
numTasks += (totalCount % stepSize == 0 ? 0 : 1);
|
|
||||||
|
|
||||||
containers.resize(numTasks);
|
for (size_t rangeStart = 0; rangeStart < totalCount; rangeStart += stepSize)
|
||||||
|
|
||||||
for (size_t rangeStart = 0; rangeStart < totalCount; rangeStart += stepSize, taskGroup++)
|
|
||||||
{
|
{
|
||||||
if (rangeStart + stepSize > totalCount)
|
if (rangeStart + stepSize > totalCount)
|
||||||
stepSize = totalCount - rangeStart;
|
stepSize = totalCount - rangeStart;
|
||||||
|
|
||||||
auto& items = containers[taskGroup];
|
containers.emplace_back();
|
||||||
|
auto& items = containers.back();
|
||||||
|
|
||||||
jobPool.addTask(std::bind(&FileIndex<TItem>::BuildRange,
|
jobPool.addTask(std::bind(&FileIndex<TItem>::BuildRange,
|
||||||
this,
|
this,
|
||||||
|
|
Loading…
Reference in New Issue