.. _program_listing_file_include_opentelemetry_context_propagation_global_propagator.h: Program Listing for File global_propagator.h ============================================ |exhale_lsh| :ref:`Return to documentation for file ` (``include/opentelemetry/context/propagation/global_propagator.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "opentelemetry/context/propagation/noop_propagator.h" #include "opentelemetry/context/propagation/text_map_propagator.h" #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace context { namespace propagation { /* Stores the singleton TextMapPropagator */ class GlobalTextMapPropagator { public: static nostd::shared_ptr GetGlobalPropagator() noexcept { std::lock_guard guard(GetLock()); return nostd::shared_ptr(GetPropagator()); } static void SetGlobalPropagator(nostd::shared_ptr prop) noexcept { std::lock_guard guard(GetLock()); GetPropagator() = prop; } private: static nostd::shared_ptr &GetPropagator() noexcept { static nostd::shared_ptr propagator(new NoOpPropagator()); return propagator; } static common::SpinLockMutex &GetLock() noexcept { static common::SpinLockMutex lock; return lock; } }; } // namespace propagation } // namespace context OPENTELEMETRY_END_NAMESPACE