Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move likely/unlikely macros from logging.h to macros.h #253

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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