Skip to content

Commit

Permalink
Changed calculation for threadCount to prevent unsigned underflow. (#…
Browse files Browse the repository at this point in the history
…287)

* Changed calculation for `threadCount` to prevent unsigned underflow.

* Change several things to int32_t.
  • Loading branch information
Malkierian authored May 24, 2023
1 parent ce43d0b commit d49cc0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/resource/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ extern bool SFileCheckWildCard(const char* szString, const char* szWildCard);
namespace LUS {

ResourceManager::ResourceManager(const std::string& mainPath, const std::string& patchesPath,
const std::unordered_set<uint32_t>& validHashes, uint32_t reservedThreadCount) {
const std::unordered_set<uint32_t>& validHashes, int32_t reservedThreadCount) {
mResourceLoader = std::make_shared<ResourceLoader>();
mArchive = std::make_shared<Archive>(mainPath, patchesPath, validHashes, false);
#if defined(__SWITCH__) || defined(__WIIU__)
size_t threadCount = 1;
#else
// the extra `- 1` is because we reserve an extra thread for spdlog
size_t threadCount = std::max(1U, (std::thread::hardware_concurrency() - reservedThreadCount - 1));
size_t threadCount = std::max(1, (int32_t)(std::thread::hardware_concurrency() - reservedThreadCount - 1));
#endif
mThreadPool = std::make_shared<BS::thread_pool>(threadCount);

Expand All @@ -33,14 +33,14 @@ ResourceManager::ResourceManager(const std::string& mainPath, const std::string&
}

ResourceManager::ResourceManager(const std::vector<std::string>& otrFiles,
const std::unordered_set<uint32_t>& validHashes, uint32_t reservedThreadCount) {
const std::unordered_set<uint32_t>& validHashes, int32_t reservedThreadCount) {
mResourceLoader = std::make_shared<ResourceLoader>();
mArchive = std::make_shared<Archive>(otrFiles, validHashes, false);
#if defined(__SWITCH__) || defined(__WIIU__)
size_t threadCount = 1;
#else
// the extra `- 1` is because we reserve an extra thread for spdlog
size_t threadCount = std::max(1U, (std::thread::hardware_concurrency() - reservedThreadCount - 1));
size_t threadCount = std::max(1, (int32_t)(std::thread::hardware_concurrency() - reservedThreadCount - 1));
#endif
mThreadPool = std::make_shared<BS::thread_pool>(threadCount);

Expand Down
4 changes: 2 additions & 2 deletions src/resource/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class ResourceManager {

public:
ResourceManager(const std::string& mainPath, const std::string& patchesPath,
const std::unordered_set<uint32_t>& validHashes, uint32_t reservedThreadCount = 1);
const std::unordered_set<uint32_t>& validHashes, int32_t reservedThreadCount = 1);
ResourceManager(const std::vector<std::string>& otrFiles, const std::unordered_set<uint32_t>& validHashes,
uint32_t reservedThreadCount = 1);
int32_t reservedThreadCount = 1);
~ResourceManager();

bool DidLoadSuccessfully();
Expand Down

0 comments on commit d49cc0b

Please sign in to comment.