From b196c6498d22e47bb9d0da0153068ec54eac7956 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 11:44:33 +0200 Subject: Adding upstream version 1.6.0. Signed-off-by: Daniel Baumann --- mocktracer/src/mock_span_context.cpp | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 mocktracer/src/mock_span_context.cpp (limited to 'mocktracer/src/mock_span_context.cpp') diff --git a/mocktracer/src/mock_span_context.cpp b/mocktracer/src/mock_span_context.cpp new file mode 100644 index 0000000..ac6eb2b --- /dev/null +++ b/mocktracer/src/mock_span_context.cpp @@ -0,0 +1,40 @@ +#include "mock_span_context.h" + +namespace opentracing { +BEGIN_OPENTRACING_ABI_NAMESPACE +namespace mocktracer { +MockSpanContext& MockSpanContext::operator=(MockSpanContext&& other) noexcept { + data_.trace_id = other.data_.trace_id; + data_.span_id = other.data_.span_id; + data_.baggage = std::move(other.data_.baggage); + return *this; +} + +void MockSpanContext::ForeachBaggageItem( + std::function f) + const { + std::lock_guard lock_guard{baggage_mutex_}; + for (const auto& baggage_item : data_.baggage) { + if (!f(baggage_item.first, baggage_item.second)) { + return; + } + } +} + +void MockSpanContext::CopyData(SpanContextData& data) const { + data.trace_id = data_.trace_id; + data.span_id = data_.span_id; + std::lock_guard lock_guard{baggage_mutex_}; + data.baggage = data_.baggage; +} + +std::unique_ptr MockSpanContext::Clone() const noexcept try { + auto result = std::unique_ptr{new MockSpanContext{}}; + CopyData(result->data_); + return std::unique_ptr{result.release()}; +} catch (const std::exception& /*e*/) { + return nullptr; +} +} // namespace mocktracer +END_OPENTRACING_ABI_NAMESPACE +} // namespace opentracing -- cgit v1.2.3