Reduce memory allocations pinging the mainloop timeout

master
Ansariel 2024-09-24 02:59:48 +02:00 committed by Andrey Kleshchev
parent 4cccf8af43
commit d6b8628a4f
5 changed files with 39 additions and 39 deletions

View File

@ -68,7 +68,7 @@ public:
// Called from MAIN THREAD.
void pause();
void unpause();
bool isPaused() { return isStopped() || mPaused; }
bool isPaused() const { return isStopped() || mPaused; }
// Cause the thread to wake up and check its condition
void wake();

View File

@ -5676,9 +5676,9 @@ void LLAppViewer::forceErrorThreadCrash()
thread->start();
}
void LLAppViewer::initMainloopTimeout(const std::string& state, F32 secs)
void LLAppViewer::initMainloopTimeout(std::string_view state, F32 secs)
{
if(!mMainloopTimeout)
if (!mMainloopTimeout)
{
mMainloopTimeout = new LLWatchdogTimeout();
resumeMainloopTimeout(state, secs);
@ -5687,20 +5687,20 @@ void LLAppViewer::initMainloopTimeout(const std::string& state, F32 secs)
void LLAppViewer::destroyMainloopTimeout()
{
if(mMainloopTimeout)
if (mMainloopTimeout)
{
delete mMainloopTimeout;
mMainloopTimeout = NULL;
mMainloopTimeout = nullptr;
}
}
void LLAppViewer::resumeMainloopTimeout(const std::string& state, F32 secs)
void LLAppViewer::resumeMainloopTimeout(std::string_view state, F32 secs)
{
if(mMainloopTimeout)
if (mMainloopTimeout)
{
if(secs < 0.0f)
if (secs < 0.0f)
{
static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60);
static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60.f);
secs = mainloop_timeout;
}
@ -5711,19 +5711,19 @@ void LLAppViewer::resumeMainloopTimeout(const std::string& state, F32 secs)
void LLAppViewer::pauseMainloopTimeout()
{
if(mMainloopTimeout)
if (mMainloopTimeout)
{
mMainloopTimeout->stop();
}
}
void LLAppViewer::pingMainloopTimeout(const std::string& state, F32 secs)
void LLAppViewer::pingMainloopTimeout(std::string_view state, F32 secs)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_APP;
if(mMainloopTimeout)
if (mMainloopTimeout)
{
if(secs < 0.0f)
if (secs < 0.0f)
{
static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60);
secs = mainloop_timeout;

View File

@ -197,11 +197,11 @@ public:
// For thread debugging.
// llstartup needs to control init.
// llworld, send_agent_pause() also controls pause/resume.
void initMainloopTimeout(const std::string& state, F32 secs = -1.0f);
void initMainloopTimeout(std::string_view state, F32 secs = -1.0f);
void destroyMainloopTimeout();
void pauseMainloopTimeout();
void resumeMainloopTimeout(const std::string& state = "", F32 secs = -1.0f);
void pingMainloopTimeout(const std::string& state, F32 secs = -1.0f);
void resumeMainloopTimeout(std::string_view state = "", F32 secs = -1.0f);
void pingMainloopTimeout(std::string_view state, F32 secs = -1.0f);
// Handle the 'login completed' event.
// *NOTE:Mani Fix this for login abstraction!!

View File

@ -29,7 +29,7 @@
#include "llwatchdog.h"
#include "llthread.h"
const U32 WATCHDOG_SLEEP_TIME_USEC = 1000000;
constexpr U32 WATCHDOG_SLEEP_TIME_USEC = 1000000U;
// This class runs the watchdog timing thread.
class LLWatchdogTimerThread : public LLThread
@ -51,7 +51,7 @@ public:
mSleepMsecs = 1;
}
/* virtual */ void run()
void run() override
{
while(!mStopping)
{
@ -83,7 +83,7 @@ void LLWatchdogEntry::start()
void LLWatchdogEntry::stop()
{
// this can happen very late in the shutdown sequence
if (! LLWatchdog::wasDeleted())
if (!LLWatchdog::wasDeleted())
{
LLWatchdog::getInstance()->remove(this);
}
@ -117,7 +117,7 @@ void LLWatchdogTimeout::setTimeout(F32 d)
mTimeout = d;
}
void LLWatchdogTimeout::start(const std::string& state)
void LLWatchdogTimeout::start(std::string_view state)
{
if (mTimeout == 0)
{
@ -139,9 +139,9 @@ void LLWatchdogTimeout::stop()
mTimer.stop();
}
void LLWatchdogTimeout::ping(const std::string& state)
void LLWatchdogTimeout::ping(std::string_view state)
{
if(!state.empty())
if (!state.empty())
{
mPingState = state;
}
@ -151,7 +151,7 @@ void LLWatchdogTimeout::ping(const std::string& state)
// LLWatchdog
LLWatchdog::LLWatchdog()
:mSuspectsAccessMutex()
,mTimer(NULL)
,mTimer(nullptr)
,mLastClockCount(0)
{
}
@ -176,7 +176,7 @@ void LLWatchdog::remove(LLWatchdogEntry* e)
void LLWatchdog::init()
{
if(!mSuspectsAccessMutex && !mTimer)
if (!mSuspectsAccessMutex && !mTimer)
{
mSuspectsAccessMutex = new LLMutex();
mTimer = new LLWatchdogTimerThread();
@ -191,17 +191,17 @@ void LLWatchdog::init()
void LLWatchdog::cleanup()
{
if(mTimer)
if (mTimer)
{
mTimer->stop();
delete mTimer;
mTimer = NULL;
mTimer = nullptr;
}
if(mSuspectsAccessMutex)
if (mSuspectsAccessMutex)
{
delete mSuspectsAccessMutex;
mSuspectsAccessMutex = NULL;
mSuspectsAccessMutex = nullptr;
}
mLastClockCount = 0;
@ -214,12 +214,12 @@ void LLWatchdog::run()
// Check the time since the last call to run...
// If the time elapsed is two times greater than the regualr sleep time
// reset the active timeouts.
const U32 TIME_ELAPSED_MULTIPLIER = 2;
constexpr U32 TIME_ELAPSED_MULTIPLIER = 2;
U64 current_time = LLTimer::getTotalTime();
U64 current_run_delta = current_time - mLastClockCount;
mLastClockCount = current_time;
if(current_run_delta > (WATCHDOG_SLEEP_TIME_USEC * TIME_ELAPSED_MULTIPLIER))
if (current_run_delta > (WATCHDOG_SLEEP_TIME_USEC * TIME_ELAPSED_MULTIPLIER))
{
LL_INFOS() << "Watchdog thread delayed: resetting entries." << LL_ENDL;
for (const auto& suspect : mSuspects)
@ -233,7 +233,7 @@ void LLWatchdog::run()
std::find_if(mSuspects.begin(),
mSuspects.end(),
[](const LLWatchdogEntry* suspect){ return ! suspect->isAlive(); });
if(result != mSuspects.end())
if (result != mSuspects.end())
{
// error!!!
if(mTimer)
@ -251,7 +251,7 @@ void LLWatchdog::run()
void LLWatchdog::lockThread()
{
if(mSuspectsAccessMutex != NULL)
if (mSuspectsAccessMutex)
{
mSuspectsAccessMutex->lock();
}
@ -259,7 +259,7 @@ void LLWatchdog::lockThread()
void LLWatchdog::unlockThread()
{
if(mSuspectsAccessMutex != NULL)
if (mSuspectsAccessMutex)
{
mSuspectsAccessMutex->unlock();
}

View File

@ -56,14 +56,14 @@ public:
LLWatchdogTimeout();
virtual ~LLWatchdogTimeout();
/* virtual */ bool isAlive() const;
/* virtual */ void reset();
/* virtual */ void start() { start(""); }
/* virtual */ void stop();
bool isAlive() const override;
void reset() override;
void start() override { start(""); }
void stop() override;
void start(const std::string& state);
void start(std::string_view state);
void setTimeout(F32 d);
void ping(const std::string& state);
void ping(std::string_view state);
const std::string& getState() {return mPingState; }
private: