Skip to content

Commit

Permalink
Update likely usage.
Browse files Browse the repository at this point in the history
Put a link to the spec here instead of copy the text.

Signed-off-by: owent <admin@owent.net>
  • Loading branch information
owent committed May 13, 2022
1 parent 1d4a860 commit 564e8b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
18 changes: 13 additions & 5 deletions api/include/opentelemetry/common/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@

#include "opentelemetry/version.h"

#ifndef likely
# ifdef __GNUC__
# define likely(x) __builtin_expect(!!(x), 1)
# else
# define likely(x) !!(x)
#ifndef OPENTELEMETRY_LIKELY_IF
# if defined(__has_cpp_attribute)
# if __has_cpp_attribute(likely)
# define OPENTELEMETRY_LIKELY_IF(...) if (__VA_ARGS__) [[likely]]
# endif
# endif
#endif
#if !defined(OPENTELEMETRY_LIKELY_IF) && (defined(__clang__) || defined(__GNUC__))
# define OPENTELEMETRY_LIKELY_IF(...) if (__builtin_expect(!!(__VA_ARGS__), true))
#else
# define OPENTELEMETRY_LIKELY_IF(...) if (__VA_ARGS__)
#endif
#ifndef OPENTELEMETRY_LIKELY_IF
# define OPENTELEMETRY_LIKELY_IF(...) if (__VA_ARGS__)
#endif

/// \brief Declare variable as maybe unused
/// usage:
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/src/otlp_log_recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void OtlpLogRecordable::SetResource(const opentelemetry::sdk::resource::Resource

const opentelemetry::sdk::resource::Resource &OtlpLogRecordable::GetResource() const noexcept
{
if (likely(nullptr != resource_))
OPENTELEMETRY_LIKELY_IF(nullptr != resource_)
{
return *resource_;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ void OtlpLogRecordable::SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &
OtlpLogRecordable::GetInstrumentationLibrary() const noexcept
{
if (likely(nullptr != instrumentation_library_))
OPENTELEMETRY_LIKELY_IF(nullptr != instrumentation_library_)
{
return *instrumentation_library_;
}
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/logs/logger_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ nostd::shared_ptr<opentelemetry::logs::Logger> LoggerProvider::GetLogger(
}
*/

// For log sources which define a logger name (e.g. Java Logger Name) the Logger Name SHOULD be
// recorded as the Instrumentation Scope name.
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-instrumentationscope
opentelemetry::nostd::unique_ptr<instrumentationlibrary::InstrumentationLibrary> lib;
if (library_name.empty())
{
Expand Down

0 comments on commit 564e8b8

Please sign in to comment.