@@ -45,23 +45,26 @@ class test_span : public couchbase::tracing::request_span
4545
4646 void add_tag (const std::string& name, std::uint64_t value) override
4747 {
48+ const std::scoped_lock lock (mutex_);
4849 int_tags_[name] = value;
4950 }
5051
5152 void add_tag (const std::string& name, const std::string& value) override
5253 {
54+ const std::scoped_lock lock (mutex_);
5355 string_tags_[name] = value;
5456 }
5557
5658 void end () override
5759 {
60+ const std::scoped_lock lock (mutex_);
5861 duration_ = std::chrono::duration_cast<std::chrono::nanoseconds>(
5962 std::chrono::steady_clock::now () - start_);
6063 }
6164
6265 void add_child_span (const std::shared_ptr<test_span>& child)
6366 {
64- const std::scoped_lock lock (child_spans_lock_ );
67+ const std::scoped_lock lock (mutex_ );
6568
6669 const auto child_span_name = child->name ();
6770 if (child_spans_.count (child_span_name) == 0 ) {
@@ -70,38 +73,42 @@ class test_span : public couchbase::tracing::request_span
7073 child_spans_[child_span_name].emplace_back (child);
7174 }
7275
73- auto child_spans () -> std::map<std::string, std::vector<std::weak_ptr<test_span>>>
76+ [[nodiscard]] auto child_spans () -> std::map<std::string, std::vector<std::weak_ptr<test_span>>>
7477 {
75- const std::shared_lock lock (child_spans_lock_ );
78+ const std::scoped_lock lock (mutex_ );
7679 return child_spans_;
7780 }
7881
79- auto child_spans (const std::string& name) -> std::vector<std::weak_ptr<test_span>>
82+ [[nodiscard]] auto child_spans (const std::string& name) -> std::vector<std::weak_ptr<test_span>>
8083 {
81- const std::shared_lock lock (child_spans_lock_ );
84+ const std::scoped_lock lock (mutex_ );
8285 if (child_spans_.count (name) == 0 ) {
8386 return {};
8487 }
8588 return child_spans_.at (name);
8689 }
8790
88- auto string_tags () -> std::map<std::string, std::string>
91+ [[nodiscard]] auto string_tags () -> std::map<std::string, std::string>
8992 {
93+ const std::scoped_lock lock (mutex_);
9094 return string_tags_;
9195 }
9296
93- auto int_tags () -> std::map<std::string, std::uint64_t>
97+ [[nodiscard]] auto int_tags () -> std::map<std::string, std::uint64_t>
9498 {
99+ const std::scoped_lock lock (mutex_);
95100 return int_tags_;
96101 }
97102
98- auto duration () const -> std::chrono::nanoseconds
103+ [[nodiscard]] auto duration () const -> std::chrono::nanoseconds
99104 {
105+ const std::scoped_lock lock (mutex_);
100106 return duration_;
101107 }
102108
103- auto start () const -> std::chrono::time_point<std::chrono::steady_clock>
109+ [[nodiscard]] auto start () const -> std::chrono::time_point<std::chrono::steady_clock>
104110 {
111+ const std::scoped_lock lock (mutex_);
105112 return start_;
106113 }
107114
@@ -117,7 +124,7 @@ class test_span : public couchbase::tracing::request_span
117124 std::map<std::string, std::string> string_tags_;
118125 std::map<std::string, std::uint64_t > int_tags_;
119126 std::map<std::string, std::vector<std::weak_ptr<test_span>>> child_spans_{};
120- std::shared_mutex child_spans_lock_ {};
127+ std::mutex mutex_ {};
121128};
122129
123130class test_tracer : public couchbase ::tracing::request_tracer
0 commit comments