summaryrefslogtreecommitdiffstats
path: root/src/tracer.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:44:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:44:33 +0000
commitb196c6498d22e47bb9d0da0153068ec54eac7956 (patch)
tree1a994a492581e93224a7ee6455f5d4e9d2ec8e59 /src/tracer.cpp
parentInitial commit. (diff)
downloadopentracing-cpp-b196c6498d22e47bb9d0da0153068ec54eac7956.tar.xz
opentracing-cpp-b196c6498d22e47bb9d0da0153068ec54eac7956.zip
Adding upstream version 1.6.0.upstream/1.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/tracer.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/tracer.cpp b/src/tracer.cpp
new file mode 100644
index 0000000..52f2f46
--- /dev/null
+++ b/src/tracer.cpp
@@ -0,0 +1,60 @@
+#include <opentracing/noop.h>
+#include <opentracing/tracer.h>
+
+#include <mutex>
+
+namespace opentracing {
+BEGIN_OPENTRACING_ABI_NAMESPACE
+namespace {
+class TracerRegistry {
+ public:
+ static TracerRegistry& instance() noexcept {
+ static TracerRegistry result;
+ return result;
+ }
+
+ static std::shared_ptr<Tracer> RegisterTracer(
+ std::shared_ptr<Tracer>& tracer) noexcept {
+ std::lock_guard<std::mutex> lock_guard{mutex_};
+ is_registered_ = true;
+ tracer_.swap(tracer);
+ return tracer;
+ }
+
+ static std::shared_ptr<Tracer> tracer() noexcept {
+ std::lock_guard<std::mutex> lock_guard{mutex_};
+ return tracer_;
+ }
+
+ static bool is_registered() noexcept {
+ std::lock_guard<std::mutex> lock_guard{mutex_};
+ return is_registered_;
+ }
+
+ private:
+ static std::mutex mutex_;
+ static bool is_registered_;
+ static std::shared_ptr<Tracer> tracer_;
+};
+
+std::mutex TracerRegistry::mutex_;
+
+bool TracerRegistry::is_registered_{false};
+
+std::shared_ptr<Tracer> TracerRegistry::tracer_{MakeNoopTracer()};
+} // namespace
+
+std::shared_ptr<Tracer> Tracer::Global() noexcept {
+ return TracerRegistry::instance().tracer();
+}
+
+std::shared_ptr<Tracer> Tracer::InitGlobal(
+ std::shared_ptr<Tracer> tracer) noexcept {
+ return TracerRegistry::instance().RegisterTracer(tracer);
+}
+
+bool Tracer::IsGlobalTracerRegistered() noexcept {
+ return TracerRegistry::instance().is_registered();
+}
+END_OPENTRACING_ABI_NAMESPACE
+} // namespace opentracing