From 20019ceef3f97830d83996464bbab6b3c239a721 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Tue, 10 Apr 2018 17:21:03 -0700 Subject: Add support for GPR_LIKELY and GPR_UNLIKELY --- include/grpc/impl/codegen/port_platform.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/grpc/impl/codegen/port_platform.h') 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 -- cgit v1.2.3