diff --git a/apps/openmw/mwphysics/mtphysics.cpp b/apps/openmw/mwphysics/mtphysics.cpp index 529316adab..7497fd15f7 100644 --- a/apps/openmw/mwphysics/mtphysics.cpp +++ b/apps/openmw/mwphysics/mtphysics.cpp @@ -33,9 +33,8 @@ namespace { template - std::optional> makeExclusiveLock(Mutex& mutex, int threadCount) + std::optional> makeExclusiveLock(Mutex& mutex, unsigned threadCount) { - assert(threadCount >= 0); if (threadCount > 0) return std::unique_lock(mutex); return {}; @@ -48,7 +47,7 @@ namespace public: /// @param mutex a mutex /// @param threadCount decide wether the excluse lock will be taken - explicit MaybeExclusiveLock(Mutex& mutex, int threadCount) + explicit MaybeExclusiveLock(Mutex& mutex, unsigned threadCount) : mImpl(makeExclusiveLock(mutex, threadCount)) {} @@ -57,9 +56,8 @@ namespace }; template - std::optional> makeSharedLock(Mutex& mutex, int threadCount) + std::optional> makeSharedLock(Mutex& mutex, unsigned threadCount) { - assert(threadCount >= 0); if (threadCount > 0) return std::shared_lock(mutex); return {}; @@ -72,7 +70,7 @@ namespace public: /// @param mutex a shared mutex /// @param threadCount decide wether the shared lock will be taken - explicit MaybeSharedLock(Mutex& mutex, int threadCount) + explicit MaybeSharedLock(Mutex& mutex, unsigned threadCount) : mImpl(makeSharedLock(mutex, threadCount)) {} @@ -81,9 +79,8 @@ namespace }; template - std::variant, std::shared_lock> makeLock(Mutex& mutex, int threadCount) + std::variant, std::shared_lock> makeLock(Mutex& mutex, unsigned threadCount) { - assert(threadCount >= 0); if (threadCount > 1) return std::shared_lock(mutex); if (threadCount == 1) @@ -98,7 +95,7 @@ namespace public: /// @param mutex a shared mutex /// @param threadCount decide wether the lock will be shared, exclusive or inexistent - explicit MaybeLock(Mutex& mutex, int threadCount) + explicit MaybeLock(Mutex& mutex, unsigned threadCount) : mImpl(makeLock(mutex, threadCount)) {} private: @@ -132,7 +129,7 @@ namespace { const Impl& mImpl; std::shared_mutex& mCollisionWorldMutex; - const int mNumJobs; + const unsigned mNumThreads; template void operator()(MWPhysics::SimulationImpl& sim) const @@ -144,7 +141,7 @@ namespace // Locked shared_ptr has to be destructed after releasing mCollisionWorldMutex to avoid // possible deadlock. Ptr destructor also acquires mCollisionWorldMutex. const std::pair arg(std::move(ptr), frameData); - const Lock lock(mCollisionWorldMutex, mNumJobs); + const Lock lock(mCollisionWorldMutex, mNumThreads); mImpl(arg); } }; @@ -288,7 +285,7 @@ namespace namespace Config { /// @return either the number of thread as configured by the user, or 1 if Bullet doesn't support multithreading and user requested more than 1 background threads - int computeNumThreads() + unsigned computeNumThreads() { int wantedThread = Settings::Manager::getInt("async num threads", "Physics"); @@ -300,7 +297,7 @@ namespace Log(Debug::Warning) << "Bullet was not compiled with multithreading support, 1 async thread will be used"; return 1; } - return std::max(0, wantedThread); + return static_cast(std::max(0, wantedThread)); } } } @@ -335,7 +332,7 @@ namespace MWPhysics { if (mNumThreads >= 1) { - for (int i = 0; i < mNumThreads; ++i) + for (unsigned i = 0; i < mNumThreads; ++i) mThreads.emplace_back([&] { worker(); } ); } else diff --git a/apps/openmw/mwphysics/mtphysics.hpp b/apps/openmw/mwphysics/mtphysics.hpp index 685d4eefab..74556ccd81 100644 --- a/apps/openmw/mwphysics/mtphysics.hpp +++ b/apps/openmw/mwphysics/mtphysics.hpp @@ -92,7 +92,7 @@ namespace MWPhysics std::unique_ptr mPostStepBarrier; std::unique_ptr mPostSimBarrier; - int mNumThreads; + unsigned mNumThreads; int mNumJobs; int mRemainingSteps; int mLOSCacheExpiry; diff --git a/components/misc/barrier.hpp b/components/misc/barrier.hpp index 277e40814a..9738fbb7fa 100644 --- a/components/misc/barrier.hpp +++ b/components/misc/barrier.hpp @@ -1,7 +1,6 @@ #ifndef OPENMW_BARRIER_H #define OPENMW_BARRIER_H -#include #include #include @@ -12,9 +11,8 @@ namespace Misc { public: /// @param count number of threads to wait on - explicit Barrier(int count) : mThreadCount(count), mRendezvousCount(0), mGeneration(0) + explicit Barrier(unsigned count) : mThreadCount(count), mRendezvousCount(0), mGeneration(0) { - assert(count >= 0); } /// @brief stop execution of threads until count distinct threads reach this point