diff options
Diffstat (limited to 'include/grpc')
-rw-r--r-- | include/grpc/impl/codegen/port_platform.h | 10 | ||||
-rw-r--r-- | include/grpc/support/log.h | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 819d17ce2a..66e7a13bb9 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -500,6 +500,16 @@ typedef unsigned __int64 uint64_t; #endif /* __GPR_WINDOWS */ #endif /* GRPC_ALLOW_EXCEPTIONS */ +/* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the + * most likely. Ideally, also collect performance numbers to justify the claim. + */ +#ifdef __GNUC__ +#define GPR_LIKELY(x) __builtin_expect((x), 1) +#define GPR_UNLIKELY(x) __builtin_expect((x), 0) +#else /* __GNUC__ */ +#define GPR_LIKELY(x) (x) +#endif /* __GNUC__ */ + #ifndef __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS #endif diff --git a/include/grpc/support/log.h b/include/grpc/support/log.h index 2236703db3..fdd963a481 100644 --- a/include/grpc/support/log.h +++ b/include/grpc/support/log.h @@ -91,7 +91,7 @@ GPRAPI void gpr_set_log_function(gpr_log_func func); an exception in a higher-level language, consider returning error code. */ #define GPR_ASSERT(x) \ do { \ - if (!(x)) { \ + if (GPR_UNLIKELY(!(x))) { \ gpr_log(GPR_ERROR, "assertion failed: %s", #x); \ abort(); \ } \ |