From b53a24f56ef4173a1a17c78ee57fdc7a44c61697 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Thu, 21 May 2020 16:12:48 -0300 Subject: [PATCH] Move likely/unlikely macros from logging.h to macros.h Signed-off-by: Ivan Santiago Paunovic --- include/rcutils/logging.h | 26 +------------------------- include/rcutils/macros.h | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/rcutils/logging.h b/include/rcutils/logging.h index a0a462b4..023f3d5e 100644 --- a/include/rcutils/logging.h +++ b/include/rcutils/logging.h @@ -21,6 +21,7 @@ #include "rcutils/allocator.h" #include "rcutils/error_handling.h" +#include "rcutils/macros.h" #include "rcutils/time.h" #include "rcutils/types/rcutils_ret.h" #include "rcutils/visibility_control.h" @@ -508,31 +509,6 @@ void rcutils_logging_console_output_handler( int severity, const char * name, rcutils_time_point_value_t timestamp, const char * format, va_list * args); -// Provide the compiler with branch prediction information -#ifndef _WIN32 -/** - * \def RCUTILS_LIKELY - * Instruct the compiler to optimize for the case where the argument equals 1. - */ -# define RCUTILS_LIKELY(x) __builtin_expect((x), 1) -/** - * \def RCUTILS_UNLIKELY - * Instruct the compiler to optimize for the case where the argument equals 0. - */ -# define RCUTILS_UNLIKELY(x) __builtin_expect((x), 0) -#else -/** - * \def RCUTILS_LIKELY - * No op since Windows doesn't support providing branch prediction information. - */ -# define RCUTILS_LIKELY(x) (x) -/** - * \def RCUTILS_UNLIKELY - * No op since Windows doesn't support providing branch prediction information. - */ -# define RCUTILS_UNLIKELY(x) (x) -#endif // _WIN32 - /** * \def RCUTILS_LOGGING_AUTOINIT * \brief Initialize the rcl logging library. diff --git a/include/rcutils/macros.h b/include/rcutils/macros.h index 27736a58..6618119b 100644 --- a/include/rcutils/macros.h +++ b/include/rcutils/macros.h @@ -106,6 +106,31 @@ extern "C" # define RCUTILS_DEPRECATED_WITH_MSG(msg) __declspec(deprecated(msg)) #endif +// Provide the compiler with branch prediction information +#ifndef _WIN32 +/** + * \def RCUTILS_LIKELY + * Instruct the compiler to optimize for the case where the argument equals 1. + */ +# define RCUTILS_LIKELY(x) __builtin_expect((x), 1) +/** + * \def RCUTILS_UNLIKELY + * Instruct the compiler to optimize for the case where the argument equals 0. + */ +# define RCUTILS_UNLIKELY(x) __builtin_expect((x), 0) +#else +/** + * \def RCUTILS_LIKELY + * No op since Windows doesn't support providing branch prediction information. + */ +# define RCUTILS_LIKELY(x) (x) +/** + * \def RCUTILS_UNLIKELY + * No op since Windows doesn't support providing branch prediction information. + */ +# define RCUTILS_UNLIKELY(x) (x) +#endif // _WIN32 + #ifdef __cplusplus } #endif