Timer#Start(): don't unnecessarily unlock/lock l_TimerMutex

via new Timer#InternalRescheduleUnlocked()
This commit is contained in:
Alexander A. Klimov 2023-04-03 17:57:53 +02:00
parent 13b9cfda41
commit 3933502739
2 changed files with 14 additions and 10 deletions

View File

@ -161,16 +161,14 @@ double Timer::GetInterval() const
*/
void Timer::Start()
{
{
std::unique_lock<std::mutex> lock(l_TimerMutex);
m_Started = true;
std::unique_lock<std::mutex> lock(l_TimerMutex);
m_Started = true;
if (++l_AliveTimers == 1) {
InitializeThread();
}
if (++l_AliveTimers == 1) {
InitializeThread();
}
InternalReschedule(false);
InternalRescheduleUnlocked(false);
}
/**
@ -202,6 +200,13 @@ void Timer::Reschedule(double next)
InternalReschedule(false, next);
}
void Timer::InternalReschedule(bool completed, double next)
{
std::unique_lock<std::mutex> lock (l_TimerMutex);
InternalRescheduleUnlocked(completed, next);
}
/**
* Reschedules this timer.
*
@ -209,10 +214,8 @@ void Timer::Reschedule(double next)
* @param next The time when this timer should be called again. Use -1 to let
* the timer figure out a suitable time based on the interval.
*/
void Timer::InternalReschedule(bool completed, double next)
void Timer::InternalRescheduleUnlocked(bool completed, double next)
{
std::unique_lock<std::mutex> lock(l_TimerMutex);
if (completed)
m_Running = false;

View File

@ -53,6 +53,7 @@ private:
Timer() = default;
void Call();
void InternalReschedule(bool completed, double next = -1);
void InternalRescheduleUnlocked(bool completed, double next = -1);
static void TimerThreadProc();