Skip to content

Commit d6b8628

Browse files
Ansarielakleshchev
authored andcommitted
Reduce memory allocations pinging the mainloop timeout
1 parent 4cccf8a commit d6b8628

File tree

5 files changed

+39
-39
lines changed

5 files changed

+39
-39
lines changed

indra/llcommon/llthread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class LL_COMMON_API LLThread
6868
// Called from MAIN THREAD.
6969
void pause();
7070
void unpause();
71-
bool isPaused() { return isStopped() || mPaused; }
71+
bool isPaused() const { return isStopped() || mPaused; }
7272

7373
// Cause the thread to wake up and check its condition
7474
void wake();

indra/newview/llappviewer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5676,9 +5676,9 @@ void LLAppViewer::forceErrorThreadCrash()
56765676
thread->start();
56775677
}
56785678

5679-
void LLAppViewer::initMainloopTimeout(const std::string& state, F32 secs)
5679+
void LLAppViewer::initMainloopTimeout(std::string_view state, F32 secs)
56805680
{
5681-
if(!mMainloopTimeout)
5681+
if (!mMainloopTimeout)
56825682
{
56835683
mMainloopTimeout = new LLWatchdogTimeout();
56845684
resumeMainloopTimeout(state, secs);
@@ -5687,20 +5687,20 @@ void LLAppViewer::initMainloopTimeout(const std::string& state, F32 secs)
56875687

56885688
void LLAppViewer::destroyMainloopTimeout()
56895689
{
5690-
if(mMainloopTimeout)
5690+
if (mMainloopTimeout)
56915691
{
56925692
delete mMainloopTimeout;
5693-
mMainloopTimeout = NULL;
5693+
mMainloopTimeout = nullptr;
56945694
}
56955695
}
56965696

5697-
void LLAppViewer::resumeMainloopTimeout(const std::string& state, F32 secs)
5697+
void LLAppViewer::resumeMainloopTimeout(std::string_view state, F32 secs)
56985698
{
5699-
if(mMainloopTimeout)
5699+
if (mMainloopTimeout)
57005700
{
5701-
if(secs < 0.0f)
5701+
if (secs < 0.0f)
57025702
{
5703-
static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60);
5703+
static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60.f);
57045704
secs = mainloop_timeout;
57055705
}
57065706

@@ -5711,19 +5711,19 @@ void LLAppViewer::resumeMainloopTimeout(const std::string& state, F32 secs)
57115711

57125712
void LLAppViewer::pauseMainloopTimeout()
57135713
{
5714-
if(mMainloopTimeout)
5714+
if (mMainloopTimeout)
57155715
{
57165716
mMainloopTimeout->stop();
57175717
}
57185718
}
57195719

5720-
void LLAppViewer::pingMainloopTimeout(const std::string& state, F32 secs)
5720+
void LLAppViewer::pingMainloopTimeout(std::string_view state, F32 secs)
57215721
{
57225722
LL_PROFILE_ZONE_SCOPED_CATEGORY_APP;
57235723

5724-
if(mMainloopTimeout)
5724+
if (mMainloopTimeout)
57255725
{
5726-
if(secs < 0.0f)
5726+
if (secs < 0.0f)
57275727
{
57285728
static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60);
57295729
secs = mainloop_timeout;

indra/newview/llappviewer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ class LLAppViewer : public LLApp
197197
// For thread debugging.
198198
// llstartup needs to control init.
199199
// llworld, send_agent_pause() also controls pause/resume.
200-
void initMainloopTimeout(const std::string& state, F32 secs = -1.0f);
200+
void initMainloopTimeout(std::string_view state, F32 secs = -1.0f);
201201
void destroyMainloopTimeout();
202202
void pauseMainloopTimeout();
203-
void resumeMainloopTimeout(const std::string& state = "", F32 secs = -1.0f);
204-
void pingMainloopTimeout(const std::string& state, F32 secs = -1.0f);
203+
void resumeMainloopTimeout(std::string_view state = "", F32 secs = -1.0f);
204+
void pingMainloopTimeout(std::string_view state, F32 secs = -1.0f);
205205

206206
// Handle the 'login completed' event.
207207
// *NOTE:Mani Fix this for login abstraction!!

indra/newview/llwatchdog.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "llwatchdog.h"
3030
#include "llthread.h"
3131

32-
const U32 WATCHDOG_SLEEP_TIME_USEC = 1000000;
32+
constexpr U32 WATCHDOG_SLEEP_TIME_USEC = 1000000U;
3333

3434
// This class runs the watchdog timing thread.
3535
class LLWatchdogTimerThread : public LLThread
@@ -51,7 +51,7 @@ class LLWatchdogTimerThread : public LLThread
5151
mSleepMsecs = 1;
5252
}
5353

54-
/* virtual */ void run()
54+
void run() override
5555
{
5656
while(!mStopping)
5757
{
@@ -83,7 +83,7 @@ void LLWatchdogEntry::start()
8383
void LLWatchdogEntry::stop()
8484
{
8585
// this can happen very late in the shutdown sequence
86-
if (! LLWatchdog::wasDeleted())
86+
if (!LLWatchdog::wasDeleted())
8787
{
8888
LLWatchdog::getInstance()->remove(this);
8989
}
@@ -117,7 +117,7 @@ void LLWatchdogTimeout::setTimeout(F32 d)
117117
mTimeout = d;
118118
}
119119

120-
void LLWatchdogTimeout::start(const std::string& state)
120+
void LLWatchdogTimeout::start(std::string_view state)
121121
{
122122
if (mTimeout == 0)
123123
{
@@ -139,9 +139,9 @@ void LLWatchdogTimeout::stop()
139139
mTimer.stop();
140140
}
141141

142-
void LLWatchdogTimeout::ping(const std::string& state)
142+
void LLWatchdogTimeout::ping(std::string_view state)
143143
{
144-
if(!state.empty())
144+
if (!state.empty())
145145
{
146146
mPingState = state;
147147
}
@@ -151,7 +151,7 @@ void LLWatchdogTimeout::ping(const std::string& state)
151151
// LLWatchdog
152152
LLWatchdog::LLWatchdog()
153153
:mSuspectsAccessMutex()
154-
,mTimer(NULL)
154+
,mTimer(nullptr)
155155
,mLastClockCount(0)
156156
{
157157
}
@@ -176,7 +176,7 @@ void LLWatchdog::remove(LLWatchdogEntry* e)
176176

177177
void LLWatchdog::init()
178178
{
179-
if(!mSuspectsAccessMutex && !mTimer)
179+
if (!mSuspectsAccessMutex && !mTimer)
180180
{
181181
mSuspectsAccessMutex = new LLMutex();
182182
mTimer = new LLWatchdogTimerThread();
@@ -191,17 +191,17 @@ void LLWatchdog::init()
191191

192192
void LLWatchdog::cleanup()
193193
{
194-
if(mTimer)
194+
if (mTimer)
195195
{
196196
mTimer->stop();
197197
delete mTimer;
198-
mTimer = NULL;
198+
mTimer = nullptr;
199199
}
200200

201-
if(mSuspectsAccessMutex)
201+
if (mSuspectsAccessMutex)
202202
{
203203
delete mSuspectsAccessMutex;
204-
mSuspectsAccessMutex = NULL;
204+
mSuspectsAccessMutex = nullptr;
205205
}
206206

207207
mLastClockCount = 0;
@@ -214,12 +214,12 @@ void LLWatchdog::run()
214214
// Check the time since the last call to run...
215215
// If the time elapsed is two times greater than the regualr sleep time
216216
// reset the active timeouts.
217-
const U32 TIME_ELAPSED_MULTIPLIER = 2;
217+
constexpr U32 TIME_ELAPSED_MULTIPLIER = 2;
218218
U64 current_time = LLTimer::getTotalTime();
219219
U64 current_run_delta = current_time - mLastClockCount;
220220
mLastClockCount = current_time;
221221

222-
if(current_run_delta > (WATCHDOG_SLEEP_TIME_USEC * TIME_ELAPSED_MULTIPLIER))
222+
if (current_run_delta > (WATCHDOG_SLEEP_TIME_USEC * TIME_ELAPSED_MULTIPLIER))
223223
{
224224
LL_INFOS() << "Watchdog thread delayed: resetting entries." << LL_ENDL;
225225
for (const auto& suspect : mSuspects)
@@ -233,7 +233,7 @@ void LLWatchdog::run()
233233
std::find_if(mSuspects.begin(),
234234
mSuspects.end(),
235235
[](const LLWatchdogEntry* suspect){ return ! suspect->isAlive(); });
236-
if(result != mSuspects.end())
236+
if (result != mSuspects.end())
237237
{
238238
// error!!!
239239
if(mTimer)
@@ -251,15 +251,15 @@ void LLWatchdog::run()
251251

252252
void LLWatchdog::lockThread()
253253
{
254-
if(mSuspectsAccessMutex != NULL)
254+
if (mSuspectsAccessMutex)
255255
{
256256
mSuspectsAccessMutex->lock();
257257
}
258258
}
259259

260260
void LLWatchdog::unlockThread()
261261
{
262-
if(mSuspectsAccessMutex != NULL)
262+
if (mSuspectsAccessMutex)
263263
{
264264
mSuspectsAccessMutex->unlock();
265265
}

indra/newview/llwatchdog.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ class LLWatchdogTimeout : public LLWatchdogEntry
5656
LLWatchdogTimeout();
5757
virtual ~LLWatchdogTimeout();
5858

59-
/* virtual */ bool isAlive() const;
60-
/* virtual */ void reset();
61-
/* virtual */ void start() { start(""); }
62-
/* virtual */ void stop();
59+
bool isAlive() const override;
60+
void reset() override;
61+
void start() override { start(""); }
62+
void stop() override;
6363

64-
void start(const std::string& state);
64+
void start(std::string_view state);
6565
void setTimeout(F32 d);
66-
void ping(const std::string& state);
66+
void ping(std::string_view state);
6767
const std::string& getState() {return mPingState; }
6868

6969
private:

0 commit comments

Comments
 (0)