aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc/impl/codegen/port_platform.h
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2018-04-10 17:21:03 -0700
committerGravatar Yash Tibrewal <yashkt@google.com>2018-04-10 17:21:03 -0700
commit20019ceef3f97830d83996464bbab6b3c239a721 (patch)
treef14ca59a0037235dd9396c993b672c0c57adcfc6 /include/grpc/impl/codegen/port_platform.h
parentcc3ae1f0c423db229343886b5c67687089869f24 (diff)
Add support for GPR_LIKELY and GPR_UNLIKELY
Diffstat (limited to 'include/grpc/impl/codegen/port_platform.h')
-rw-r--r--include/grpc/impl/codegen/port_platform.h10
1 files changed, 10 insertions, 0 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