Skip to content

Commit 79342fe

Browse files
bmehta001Copilot
andcommitted
Make m_scheduledUploadTime atomic for explicit thread safety
Declare m_scheduledUploadTime as std::atomic<uint64_t> and move its update back outside the LOCKGUARD, consistent with m_runningLatency. All accesses were already under LOCKGUARD(m_scheduledUploadMutex), but atomic makes the thread-safe intent self-documenting and guards against future accesses that might omit the lock. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 710a531 commit 79342fe

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎lib/tpm/TransmissionPolicyManager.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ namespace MAT_NS_BEGIN {
147147
m_runningLatency = latency;
148148
}
149149
auto now = PAL::getMonotonicTimeMs();
150-
auto delta = Abs64(m_scheduledUploadTime, now);
150+
auto delta = Abs64(m_scheduledUploadTime.load(), now);
151151
if (delta <= static_cast<uint64_t>(delay.count()))
152152
{
153153
// Don't need to cancel and reschedule if it's about to happen now anyways.
@@ -185,9 +185,9 @@ namespace MAT_NS_BEGIN {
185185
return;
186186
}
187187
m_runningLatency = latency;
188+
m_scheduledUploadTime = std::numeric_limits<uint64_t>::max();
188189
{
189190
LOCKGUARD(m_scheduledUploadMutex);
190-
m_scheduledUploadTime = std::numeric_limits<uint64_t>::max();
191191
m_isUploadScheduled = false; // Allow to schedule another uploadAsync
192192
if ((m_isPaused) || (m_scheduledUploadAborted))
193193
{

‎lib/tpm/TransmissionPolicyManager.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ constexpr const char* const DefaultBackoffConfig = "E,3000,300000,2,1";
9191

9292
std::atomic<bool> m_isPaused { true };
9393
std::atomic<bool> m_isUploadScheduled { false };
94-
uint64_t m_scheduledUploadTime { std::numeric_limits<uint64_t>::max() };
94+
std::atomic<uint64_t> m_scheduledUploadTime { std::numeric_limits<uint64_t>::max() };
9595
std::mutex m_scheduledUploadMutex;
9696
PAL::DeferredCallbackHandle m_scheduledUpload;
9797
bool m_scheduledUploadAborted { false };

0 commit comments

Comments
 (0)