Skip to content

Commit

Permalink
Move likely/unlikely macros from logging.h to macros.h (#253)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno authored May 22, 2020
1 parent e5dd0bd commit 0b0fa4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
26 changes: 1 addition & 25 deletions include/rcutils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions include/rcutils/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b0fa4b

Please sign in to comment.