Skip to content

Commit c428f0c

Browse files
authored
Updated periodic_exporting_metric_reader.cc
Improved scoping of the unique lock that is used in PeriodicExportingMetricReader::DoBackgroundWork Changed while loop logic from while(true)to be similar to original code (do-while)
1 parent 5ee3b9d commit c428f0c

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

sdk/src/metrics/export/periodic_exporting_metric_reader.cc

+3-8
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,9 @@ void PeriodicExportingMetricReader::DoBackgroundWork()
9090
worker_thread_instrumentation_->OnStart();
9191
}
9292
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
93-
std::unique_lock<std::mutex> lk(cv_m_);
94-
while (true)
93+
do
9594
{
9695
auto start = std::chrono::steady_clock::now();
97-
9896
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
9997
if (worker_thread_instrumentation_ != nullptr)
10098
{
@@ -126,6 +124,7 @@ void PeriodicExportingMetricReader::DoBackgroundWork()
126124
worker_thread_instrumentation_->BeforeWait();
127125
}
128126
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
127+
std::unique_lock<std::mutex> lk(cv_m_);
129128
cv_.wait_for(lk, remaining_wait_interval_ms, [this]() {
130129
if (is_force_wakeup_background_worker_.load(std::memory_order_acquire))
131130
{
@@ -141,11 +140,7 @@ void PeriodicExportingMetricReader::DoBackgroundWork()
141140
worker_thread_instrumentation_->AfterWait();
142141
}
143142
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
144-
if (IsShutdown())
145-
{
146-
break;
147-
}
148-
}
143+
} while (IsShutdown() != true);
149144

150145
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
151146
if (worker_thread_instrumentation_ != nullptr)

0 commit comments

Comments
 (0)