diff --git a/src/replica/ingest/IngestRequest.cc b/src/replica/ingest/IngestRequest.cc index e0496a1b2..725960b2e 100644 --- a/src/replica/ingest/IngestRequest.cc +++ b/src/replica/ingest/IngestRequest.cc @@ -347,11 +347,10 @@ void IngestRequest::_processStart() { string const context = ::context_ + string(__func__) + " "; replica::Lock const lock(_mtx, context); - if (_processing) { + if (_processing.exchange(true)) { throw logic_error(context + "the contribution request " + to_string(_contrib.id) + " is already being processed or has been processed."); } - _processing = true; bool const failed = true; auto const databaseServices = serviceProvider()->databaseServices(); diff --git a/src/replica/ingest/IngestRequest.h b/src/replica/ingest/IngestRequest.h index db457ee71..b2c42473c 100644 --- a/src/replica/ingest/IngestRequest.h +++ b/src/replica/ingest/IngestRequest.h @@ -242,7 +242,7 @@ class IngestRequest : public std::enable_shared_from_this, public /// parameters of the request. TransactionContribInfo _contrib; - // These variables are set after completing parameter validation + // These variables are set by the constructors after completing parameter validation. std::unique_ptr _resource; csv::Dialect _dialect; @@ -250,11 +250,11 @@ class IngestRequest : public std::enable_shared_from_this, public /// reset. The flag is used for coordinating state change with other methods /// of the class. In particular, setting this flag would prevent executing /// the request more than one time. - bool _processing = false; + std::atomic _processing{false}; - // Setting the flag will interrupt request processing (if the one is - // still going on). - std::atomic _cancelled{false}; ///< Set by calling the public method cancel() + /// Set by calling the public method cancel(). Setting the flag will interrupt + /// request processing (if the one is still going on). + std::atomic _cancelled{false}; }; } // namespace lsst::qserv::replica