Skip to content

Commit 979aad9

Browse files
Removed Wait operations from Timer class
Use ManualResetEvent::Wait instead
1 parent f1ae635 commit 979aad9

File tree

3 files changed

+7
-42
lines changed

3 files changed

+7
-42
lines changed

src/lib/Timer.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -177,36 +177,3 @@ void Timer::Stop()
177177

178178
m_timerThread.reset();
179179
}
180-
181-
void Timer::Wait() const
182-
{
183-
try
184-
{
185-
if (m_running && m_timerThread != nullptr)
186-
{
187-
const ThreadPtr timerThread = m_timerThread;
188-
189-
if (timerThread != nullptr)
190-
timerThread->join();
191-
}
192-
}
193-
catch (...)
194-
{
195-
// ReSharper disable once CppRedundantControlFlowJump
196-
return;
197-
}
198-
}
199-
200-
void Timer::EmptyCallback(const TimerPtr&, void*)
201-
{
202-
}
203-
204-
TimerPtr Timer::WaitTimer(const int32_t interval, const bool autoStart)
205-
{
206-
TimerPtr waitTimer = NewSharedPtr<Timer>(interval, EmptyCallback);
207-
208-
if (autoStart)
209-
waitTimer->Start();
210-
211-
return waitTimer;
212-
}

src/lib/transport/SubscriberConnector.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ void DataClient::SetSubscriptionInfo(const SubscriptionInfo& info)
4747

4848
SubscriberConnector::SubscriberConnector() :
4949
m_port(0),
50-
m_timer(Timer::NullPtr),
5150
m_maxRetries(-1),
5251
m_retryInterval(2000),
5352
m_maxRetryInterval(120000),
@@ -127,8 +126,8 @@ void SubscriberConnector::AutoReconnect(DataClient* client)
127126
connector.m_clientErrorMessageCallback(client, errorMessageStream.str());
128127
}
129128

130-
connector.m_timer = Timer::WaitTimer(retryInterval);
131-
connector.m_timer->Wait();
129+
connector.m_waitHandle.Reset();
130+
connector.m_waitHandle.Wait(retryInterval);
132131

133132
if (connector.m_cancel || client->m_disposing)
134133
return;
@@ -279,8 +278,8 @@ int SubscriberConnector::Connect(DataClient& client, bool autoReconnecting)
279278

280279
if (retryInterval > 0)
281280
{
282-
m_timer = Timer::WaitTimer(retryInterval);
283-
m_timer->Wait();
281+
m_waitHandle.Reset();
282+
m_waitHandle.Wait(retryInterval);
284283

285284
if (m_cancel)
286285
return ConnectCanceled;
@@ -297,8 +296,7 @@ void SubscriberConnector::Cancel()
297296
m_cancel = true;
298297

299298
// Cancel any waiting timer operations by setting immediate timer expiration
300-
if (m_timer != nullptr)
301-
m_timer->Stop();
299+
m_waitHandle.Set();
302300

303301
m_autoReconnectThread.join();
304302
}

src/lib/transport/SubscriberConnector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#pragma once
2525

26-
#include "../Timer.h"
26+
#include "../ManualResetEvent.h"
2727
#include "SubscriptionInfo.h"
2828

2929
namespace sttp::transport
@@ -73,7 +73,7 @@ namespace sttp::transport
7373

7474
std::string m_hostname;
7575
uint16_t m_port;
76-
TimerPtr m_timer;
76+
ManualResetEvent m_waitHandle;
7777

7878
int32_t m_maxRetries;
7979
int32_t m_retryInterval;

0 commit comments

Comments
 (0)