Skip to content

Commit

Permalink
fix data race on MeterContext::meters_
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo committed Oct 9, 2022
1 parent 79a9471 commit 852808e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdk/include/opentelemetry/sdk/metrics/meter_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class MeterContext : public std::enable_shared_from_this<MeterContext>

std::atomic_flag shutdown_latch_ = ATOMIC_FLAG_INIT;
opentelemetry::common::SpinLockMutex forceflush_lock_;
opentelemetry::common::SpinLockMutex storage_lock_;
};

} // namespace metrics
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/metrics/meter_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ViewRegistry *MeterContext::GetViewRegistry() const noexcept

nostd::span<std::shared_ptr<Meter>> MeterContext::GetMeters() noexcept
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(storage_lock_);
return nostd::span<std::shared_ptr<Meter>>{meters_};
}

Expand Down Expand Up @@ -59,6 +60,7 @@ void MeterContext::AddView(std::unique_ptr<InstrumentSelector> instrument_select

void MeterContext::AddMeter(std::shared_ptr<Meter> meter)
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(storage_lock_);
meters_.push_back(meter);
}

Expand Down

0 comments on commit 852808e

Please sign in to comment.