File tree Expand file tree Collapse file tree 3 files changed +9
-33
lines changed 
api/include/opentelemetry Expand file tree Collapse file tree 3 files changed +9
-33
lines changed Original file line number Diff line number Diff line change @@ -337,31 +337,6 @@ point.
337337
338338#endif 
339339
340- // 
341- //  Atomic wrappers based on compiler intrinsics for memory read/write.
342- //  The tailing number is read/write length in bits.
343- // 
344- //  N.B. Compiler intrinsic is used because the usage of C++ standard library is restricted in the
345- //  OpenTelemetry C++ API.
346- // 
347- #if  defined(__GNUC__)
348- 
349- #  define  OPENTELEMETRY_ATOMIC_READ_8 (ptr ) __atomic_load_n(ptr, __ATOMIC_SEQ_CST)
350- #  define  OPENTELEMETRY_ATOMIC_WRITE_8 (ptr, value ) __atomic_store_n(ptr, value, __ATOMIC_SEQ_CST)
351- 
352- #elif  defined(_MSC_VER)
353- 
354- #  include  < intrin.h> 
355- 
356- #  define  OPENTELEMETRY_ATOMIC_READ_8 (ptr ) \
357-     static_cast <uint8_t >(_InterlockedCompareExchange8(reinterpret_cast <char  *>(ptr), 0 , 0 ))
358- #  define  OPENTELEMETRY_ATOMIC_WRITE_8 (ptr, value ) \
359-     _InterlockedExchange8 (reinterpret_cast <char  *>(ptr), static_cast<char>(value))
360- 
361- #else 
362- #  error  port atomics read/write for the current platform
363- #endif 
364- 
365340/*  clang-format on */ 
366341// 
367342//  The if/elif order matters here. If both OPENTELEMETRY_BUILD_IMPORT_DLL and
Original file line number Diff line number Diff line change 33
44#pragma  once
55
6+ #include  < atomic> 
7+ 
68#include  " opentelemetry/version.h" 
79#include  " opentelemetry/logs/logger_type_traits.h" 
810#include  " opentelemetry/logs/severity.h" 
@@ -286,7 +288,7 @@ class Logger
286288
287289  inline  bool  Enabled (Severity severity) const  noexcept 
288290  {
289-     return  static_cast <uint8_t >(severity) >= OPENTELEMETRY_ATOMIC_READ_8 (& minimum_severity_) ;
291+     return  static_cast <uint8_t >(severity) >= minimum_severity_;
290292  }
291293
292294  /* *
@@ -473,7 +475,7 @@ class Logger
473475
474476  void  SetMinimumSeverity (uint8_t  severity_or_max) noexcept 
475477  {
476-     OPENTELEMETRY_ATOMIC_WRITE_8 (& minimum_severity_,  severity_or_max) ;
478+     minimum_severity_ =  severity_or_max;
477479  }
478480
479481private: 
@@ -486,7 +488,7 @@ class Logger
486488  //  read/write should be handled. And std::atomic can not be used here because it is not ABI
487489  //  compatible for OpenTelemetry C++ API.
488490  // 
489-   mutable  uint8_t  minimum_severity_{kMaxSeverity };
491+   mutable  std::atomic< uint8_t >  minimum_severity_{kMaxSeverity };
490492};
491493}  //  namespace logs
492494OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change 44#pragma  once
55
66#include  < chrono> 
7+ #include  < atomic> 
78
89#include  " opentelemetry/version.h" 
910#include  " opentelemetry/context/context.h" 
@@ -172,7 +173,7 @@ class Tracer
172173   * 
173174   * @since ABI_VERSION 2 
174175   */  
175-   bool  Enabled () const  noexcept  { return  OPENTELEMETRY_ATOMIC_READ_8 (& this -> enabled_ )  != 0 ; }
176+   bool  Enabled () const  noexcept  { return  enabled_ != 0 ; }
176177#endif 
177178
178179#if  OPENTELEMETRY_ABI_VERSION_NO == 1
@@ -227,17 +228,15 @@ class Tracer
227228   */  
228229  void  UpdateEnabled (const  bool  enabled) noexcept 
229230  {
230-     OPENTELEMETRY_ATOMIC_WRITE_8 (& this -> enabled_ ,  enabled) ;
231+     enabled_ =  enabled;
231232  }
232233#endif 
233234
234235private: 
235236#if  OPENTELEMETRY_ABI_VERSION_NO >= 2
236237  //  Variable to support implementation of Enabled method introduced in ABI V2.
237238  //  Mutable allows enabled_ to be used as 'bool *' (instead of 'const bool *'), with the
238-   //  OPENTELEMETRY_ATOMIC_READ_8 macro's internal casts when used from a const function.
239-   //  std::atomic can not be used here because it is not ABI compatible for OpenTelemetry C++ API.
240-   mutable  bool  enabled_ = true ;
239+   mutable  std::atomic<bool > enabled_ = true ;
241240#endif 
242241};
243242}  //  namespace trace
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments