From 7c44f79252d451a07b7845f7fc337ba7d643adce Mon Sep 17 00:00:00 2001 From: Dan Melnic Date: Mon, 26 Jul 2021 11:30:13 -0700 Subject: [PATCH] Fix TSAN issue due to std::chrono non atomic access Summary: Fix TSAN issue due to std::chrono non atomic access Reviewed By: danobi Differential Revision: D29903190 fbshipit-source-id: 31c574741542cc6303d01b42a74ef5d30ebc7e04 --- Receiver.cpp | 6 +++--- Receiver.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Receiver.cpp b/Receiver.cpp index e75efc4b..21d652df 100644 --- a/Receiver.cpp +++ b/Receiver.cpp @@ -82,7 +82,7 @@ void Receiver::startNewGlobalSession(const std::string &peerIp) { // when the current session ends throttler_->startTransfer(); } - startTime_ = Clock::now(); + startTime_.store(Clock::now()); if (options_.enable_download_resumption) { transferLogManager_->startThread(); bool verifySuccessful = transferLogManager_->verifySenderIp(peerIp); @@ -325,7 +325,7 @@ std::unique_ptr Receiver::finish() { auto totalSenderBytes = summary.getTotalSenderBytes(); if (progressReporter_ && totalSenderBytes >= 0) { report->setTotalFileSize(totalSenderBytes); - report->setTotalTime(durationSeconds(Clock::now() - startTime_)); + report->setTotalTime(durationSeconds(Clock::now() - startTime_.load())); progressReporter_->end(report); } logPerfStats(); @@ -407,7 +407,7 @@ void Receiver::progressTracker() { break; } } - double totalTime = durationSeconds(Clock::now() - startTime_); + double totalTime = durationSeconds(Clock::now() - startTime_.load()); TransferStats globalStats; for (const auto &receiverThread : receiverThreads_) { globalStats += receiverThread->getTransferStats(); diff --git a/Receiver.h b/Receiver.h index bbbd8011..aeb779b3 100644 --- a/Receiver.h +++ b/Receiver.h @@ -203,7 +203,7 @@ class Receiver : public WdtBase { std::vector checkpoints_; /// Start time of the session - std::chrono::time_point startTime_; + std::atomic> startTime_; /// already transferred file chunks std::vector fileChunksInfo_;