mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 18:09:39 +00:00
Add number of thread jobs to update jobs stats
This commit is contained in:
parent
528fc5870a
commit
7502db1570
2 changed files with 15 additions and 4 deletions
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#include <osg/Stats>
|
#include <osg/Stats>
|
||||||
|
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using DetourNavigator::ChangeType;
|
using DetourNavigator::ChangeType;
|
||||||
|
@ -101,7 +103,7 @@ namespace DetourNavigator
|
||||||
void AsyncNavMeshUpdater::wait()
|
void AsyncNavMeshUpdater::wait()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mMutex);
|
std::unique_lock<std::mutex> lock(mMutex);
|
||||||
mDone.wait(lock, [&] { return mJobs.empty(); });
|
mDone.wait(lock, [&] { return mJobs.empty() && getTotalThreadJobsUnsafe() == 0; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncNavMeshUpdater::reportStats(unsigned int frameNumber, osg::Stats& stats) const
|
void AsyncNavMeshUpdater::reportStats(unsigned int frameNumber, osg::Stats& stats) const
|
||||||
|
@ -110,7 +112,7 @@ namespace DetourNavigator
|
||||||
|
|
||||||
{
|
{
|
||||||
const std::lock_guard<std::mutex> lock(mMutex);
|
const std::lock_guard<std::mutex> lock(mMutex);
|
||||||
jobs = mJobs.size();
|
jobs = mJobs.size() + getTotalThreadJobsUnsafe();
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.setAttribute(frameNumber, "NavMesh UpdateJobs", jobs);
|
stats.setAttribute(frameNumber, "NavMesh UpdateJobs", jobs);
|
||||||
|
@ -188,12 +190,13 @@ namespace DetourNavigator
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
const auto hasJob = [&] { return !mJobs.empty() || !threadQueue.mPushed.empty(); };
|
const auto hasJob = [&] { return !mJobs.empty() || !threadQueue.mJobs.empty(); };
|
||||||
|
|
||||||
if (!mHasJob.wait_for(lock, std::chrono::milliseconds(10), hasJob))
|
if (!mHasJob.wait_for(lock, std::chrono::milliseconds(10), hasJob))
|
||||||
{
|
{
|
||||||
mFirstStart.lock()->reset();
|
mFirstStart.lock()->reset();
|
||||||
mDone.notify_all();
|
if (getTotalThreadJobsUnsafe() == 0)
|
||||||
|
mDone.notify_all();
|
||||||
return boost::none;
|
return boost::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,4 +330,10 @@ namespace DetourNavigator
|
||||||
if (agent->second.empty())
|
if (agent->second.empty())
|
||||||
locked->erase(agent);
|
locked->erase(agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t AsyncNavMeshUpdater::getTotalThreadJobsUnsafe() const
|
||||||
|
{
|
||||||
|
return std::accumulate(mThreadsQueues.begin(), mThreadsQueues.end(), std::size_t(0),
|
||||||
|
[] (auto r, const auto& v) { return r + v.second.mJobs.size(); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,8 @@ namespace DetourNavigator
|
||||||
std::thread::id lockTile(const osg::Vec3f& agentHalfExtents, const TilePosition& changedTile);
|
std::thread::id lockTile(const osg::Vec3f& agentHalfExtents, const TilePosition& changedTile);
|
||||||
|
|
||||||
void unlockTile(const osg::Vec3f& agentHalfExtents, const TilePosition& changedTile);
|
void unlockTile(const osg::Vec3f& agentHalfExtents, const TilePosition& changedTile);
|
||||||
|
|
||||||
|
inline std::size_t getTotalThreadJobsUnsafe() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue