Skip to content

Commit 881addf

Browse files
khanayan123claude
andcommitted
simplify: use static local singleton pattern for root session ID
Match the codebase's existing singleton pattern (static local variable). No mutex or call_once needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e347fa6 commit 881addf

1 file changed

Lines changed: 1 addition & 15 deletions

File tree

src/datadog/root_session_id.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
11
#include "root_session_id.h"
22

3-
#include <mutex>
4-
53
namespace datadog {
64
namespace tracing {
75
namespace root_session_id {
86

97
namespace {
108

11-
std::mutex& mutex() {
12-
static std::mutex m;
13-
return m;
14-
}
15-
169
std::string& instance() {
1710
static std::string id;
1811
return id;
1912
}
2013

21-
bool& initialized() {
22-
static bool init = false;
23-
return init;
24-
}
25-
2614
} // namespace
2715

2816
void set(const std::string& id) {
29-
std::lock_guard<std::mutex> lock(mutex());
30-
if (!initialized()) {
17+
if (instance().empty()) {
3118
instance() = id;
32-
initialized() = true;
3319
}
3420
}
3521

0 commit comments

Comments
 (0)