@@ -226,6 +226,7 @@ void Telemetry::schedule_tasks() {
226226}
227227
228228Telemetry::~Telemetry () {
229+ shutting_down_.store (true , std::memory_order_release);
229230 if (!tasks_.empty ()) {
230231 cancel_tasks (tasks_);
231232 capture_metrics ();
@@ -252,6 +253,7 @@ Telemetry::Telemetry(Telemetry&& rhs)
252253 seq_id_(rhs.seq_id_),
253254 config_seq_ids_(rhs.config_seq_ids_),
254255 host_info_(rhs.host_info_) {
256+ rhs.shutting_down_ .store (true , std::memory_order_release);
255257 cancel_tasks (rhs.tasks_ );
256258 schedule_tasks ();
257259}
@@ -740,6 +742,9 @@ void Telemetry::log(std::string message, telemetry::LogLevel level,
740742 clock_ ().wall .time_since_epoch ())
741743 .count ();
742744 std::lock_guard l{log_mutex_};
745+ if (shutting_down_.load (std::memory_order_acquire)) {
746+ return ;
747+ }
743748 logs_.emplace_back (
744749 telemetry::LogMessage{std::move (message), level, stacktrace, timestamp});
745750}
@@ -751,6 +756,9 @@ void Telemetry::increment_counter(const Counter& id) {
751756void Telemetry::increment_counter (const Counter& id,
752757 const std::vector<std::string>& tags) {
753758 std::lock_guard l{counter_mutex_};
759+ if (shutting_down_.load (std::memory_order_acquire)) {
760+ return ;
761+ }
754762 counters_[{id, tags}] += 1 ;
755763}
756764
@@ -761,6 +769,9 @@ void Telemetry::decrement_counter(const Counter& id) {
761769void Telemetry::decrement_counter (const Counter& id,
762770 const std::vector<std::string>& tags) {
763771 std::lock_guard l{counter_mutex_};
772+ if (shutting_down_.load (std::memory_order_acquire)) {
773+ return ;
774+ }
764775 auto & v = counters_[{id, tags}];
765776 if (v > 0 ) v -= 1 ;
766777}
@@ -773,6 +784,9 @@ void Telemetry::set_counter(const Counter& id,
773784 const std::vector<std::string>& tags,
774785 uint64_t value) {
775786 std::lock_guard l{counter_mutex_};
787+ if (shutting_down_.load (std::memory_order_acquire)) {
788+ return ;
789+ }
776790 counters_[{id, tags}] = value;
777791}
778792
@@ -783,6 +797,9 @@ void Telemetry::set_rate(const Rate& id, uint64_t value) {
783797void Telemetry::set_rate (const Rate& id, const std::vector<std::string>& tags,
784798 uint64_t value) {
785799 std::lock_guard l{rate_mutex_};
800+ if (shutting_down_.load (std::memory_order_acquire)) {
801+ return ;
802+ }
786803 rates_[{id, tags}] = value;
787804}
788805
@@ -794,6 +811,9 @@ void Telemetry::add_datapoint(const Distribution& id,
794811 const std::vector<std::string>& tags,
795812 uint64_t value) {
796813 std::lock_guard l{distributions_mutex_};
814+ if (shutting_down_.load (std::memory_order_acquire)) {
815+ return ;
816+ }
797817 distributions_[{id, tags}].emplace_back (value);
798818}
799819
0 commit comments