3 * Copyright 2015 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #ifndef GRPC_IMPL_CODEGEN_PORT_PLATFORM_H
20 #define GRPC_IMPL_CODEGEN_PORT_PLATFORM_H
23 * Define GPR_BACKWARDS_COMPATIBILITY_MODE to try harder to be ABI
24 * compatible with older platforms (currently only on Linux)
26 * - some libc calls to be gotten via dlsym
27 * - some syscalls to be made directly
31 * Defines GRPC_USE_CPP_STD_LIB to use standard C++ library instead of
32 * in-house library if possible. (e.g. std::map)
34 #ifndef GRPC_USE_CPP_STD_LIB
35 #define GRPC_USE_CPP_STD_LIB 1
38 /* Get windows.h included everywhere (we need it) */
39 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
40 #ifndef WIN32_LEAN_AND_MEAN
41 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
42 #define WIN32_LEAN_AND_MEAN
43 #endif /* WIN32_LEAN_AND_MEAN */
46 #define GRPC_NOMINMX_WAS_NOT_DEFINED
52 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
53 #else /* !defined(_WIN32_WINNT) */
54 #if (_WIN32_WINNT < 0x0600)
56 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
57 #endif /* _WIN32_WINNT < 0x0600 */
58 #endif /* defined(_WIN32_WINNT) */
62 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
63 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
64 #undef WIN32_LEAN_AND_MEAN
65 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
67 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
68 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
70 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
71 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \
74 /* Override this file with one for your platform if you need to redefine
77 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
78 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
79 #if defined(_WIN64) || defined(WIN64)
84 #define GPR_PLATFORM_STRING "windows"
86 #define GPR_WINDOWS_SUBPROCESS 1
87 #define GPR_WINDOWS_ENV
89 #define GPR_GETPID_IN_UNISTD_H 1
90 #define GPR_MSYS_TMPFILE
92 #define GPR_POSIX_STRING
93 #define GPR_POSIX_TIME
95 #define GPR_GETPID_IN_PROCESS_H 1
96 #define GPR_WINDOWS_TMPFILE
97 #define GPR_WINDOWS_LOG
98 #define GPR_WINDOWS_CRASH_HANDLER 1
99 #define GPR_WINDOWS_STRING
100 #define GPR_WINDOWS_TIME
103 #define GPR_GCC_ATOMIC 1
104 #define GPR_GCC_TLS 1
106 #define GPR_WINDOWS_ATOMIC 1
107 #define GPR_MSVC_TLS 1
109 #elif defined(GPR_MANYLINUX1)
110 // TODO(atash): manylinux1 is just another __linux__ but with ancient
111 // libraries; it should be integrated with the `__linux__` definitions below.
112 #define GPR_PLATFORM_STRING "manylinux"
113 #define GPR_POSIX_CRASH_HANDLER 1
114 #define GPR_CPU_POSIX 1
115 #define GPR_GCC_ATOMIC 1
116 #define GPR_GCC_TLS 1
118 #define GPR_LINUX_LOG 1
119 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
120 #define GPR_LINUX_ENV 1
121 #define GPR_POSIX_TMPFILE 1
122 #define GPR_POSIX_STRING 1
123 #define GPR_POSIX_SUBPROCESS 1
124 #define GPR_POSIX_SYNC 1
125 #define GPR_POSIX_TIME 1
126 #define GPR_HAS_PTHREAD_H 1
127 #define GPR_GETPID_IN_UNISTD_H 1
129 #define GPR_ARCH_64 1
131 #define GPR_ARCH_32 1
133 #include <linux/version.h>
134 #elif defined(ANDROID) || defined(__ANDROID__)
135 #define GPR_PLATFORM_STRING "android"
136 #define GPR_ANDROID 1
137 // TODO(apolcyn): re-evaluate support for c-ares
138 // on android after upgrading our c-ares dependency.
139 // See https://github.com/grpc/grpc/issues/18038.
142 #define GPR_ARCH_64 1
144 #define GPR_ARCH_32 1
146 #define GPR_CPU_POSIX 1
147 #define GPR_GCC_SYNC 1
148 #define GPR_GCC_TLS 1
149 #define GPR_POSIX_ENV 1
150 #define GPR_POSIX_TMPFILE 1
151 #define GPR_ANDROID_LOG 1
152 #define GPR_POSIX_STRING 1
153 #define GPR_POSIX_SUBPROCESS 1
154 #define GPR_POSIX_SYNC 1
155 #define GPR_POSIX_TIME 1
156 #define GPR_HAS_PTHREAD_H 1
157 #define GPR_GETPID_IN_UNISTD_H 1
158 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
159 #elif defined(__linux__)
160 #define GPR_PLATFORM_STRING "linux"
164 #ifndef _DEFAULT_SOURCE
165 #define _DEFAULT_SOURCE
170 #include <features.h>
171 #define GPR_CPU_LINUX 1
172 #define GPR_GCC_ATOMIC 1
173 #define GPR_GCC_TLS 1
175 #define GPR_LINUX_LOG
176 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
177 #define GPR_LINUX_ENV 1
178 #define GPR_POSIX_TMPFILE 1
179 #define GPR_POSIX_STRING 1
180 #define GPR_POSIX_SUBPROCESS 1
181 #define GPR_POSIX_SYNC 1
182 #define GPR_POSIX_TIME 1
183 #define GPR_HAS_PTHREAD_H 1
184 #define GPR_GETPID_IN_UNISTD_H 1
186 #define GPR_ARCH_64 1
188 #define GPR_ARCH_32 1
191 #define GPR_POSIX_CRASH_HANDLER 1
192 #define GPR_LINUX_PTHREAD_NAME 1
193 #include <linux/version.h>
194 #else /* musl libc */
195 #define GPR_MUSL_LIBC_COMPAT 1
197 #elif defined(__APPLE__)
198 #include <Availability.h>
199 #include <TargetConditionals.h>
204 #define GPR_PLATFORM_STRING "ios"
205 #define GPR_CPU_IPHONE 1
206 #define GPR_PTHREAD_TLS 1
207 #define GRPC_CFSTREAM 1
208 /* the c-ares resolver isnt safe to enable on iOS */
210 #else /* TARGET_OS_IPHONE */
211 #define GPR_PLATFORM_STRING "osx"
212 #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
213 #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7
214 #define GPR_CPU_IPHONE 1
215 #define GPR_PTHREAD_TLS 1
216 #else /* __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7 */
217 #define GPR_CPU_POSIX 1
218 /* TODO(vjpai): there is a reported issue in bazel build for Mac where __thread
219 in a header is currently not working (bazelbuild/bazel#4341). Remove
220 the following conditional and use GPR_GCC_TLS when that is fixed */
221 #ifndef GRPC_BAZEL_BUILD
222 #define GPR_GCC_TLS 1
223 #else /* GRPC_BAZEL_BUILD */
224 #define GPR_PTHREAD_TLS 1
225 #endif /* GRPC_BAZEL_BUILD */
226 #define GPR_APPLE_PTHREAD_NAME 1
228 #else /* __MAC_OS_X_VERSION_MIN_REQUIRED */
229 #define GPR_CPU_POSIX 1
230 /* TODO(vjpai): Remove the following conditional and use only GPR_GCC_TLS
231 when bazelbuild/bazel#4341 is fixed */
232 #ifndef GRPC_BAZEL_BUILD
233 #define GPR_GCC_TLS 1
234 #else /* GRPC_BAZEL_BUILD */
235 #define GPR_PTHREAD_TLS 1
236 #endif /* GRPC_BAZEL_BUILD */
238 #define GPR_POSIX_CRASH_HANDLER 1
241 #define GPR_GCC_ATOMIC 1
242 #define GPR_POSIX_LOG 1
243 #define GPR_POSIX_ENV 1
244 #define GPR_POSIX_TMPFILE 1
245 #define GPR_POSIX_STRING 1
246 #define GPR_POSIX_SUBPROCESS 1
247 #define GPR_POSIX_SYNC 1
248 #define GPR_POSIX_TIME 1
249 #define GPR_HAS_PTHREAD_H 1
250 #define GPR_GETPID_IN_UNISTD_H 1
251 #ifndef GRPC_CFSTREAM
252 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
255 #define GPR_ARCH_64 1
257 #define GPR_ARCH_32 1
259 #elif defined(__FreeBSD__)
260 #define GPR_PLATFORM_STRING "freebsd"
264 #define GPR_FREEBSD 1
265 #define GPR_CPU_POSIX 1
266 #define GPR_GCC_ATOMIC 1
267 #define GPR_GCC_TLS 1
268 #define GPR_POSIX_LOG 1
269 #define GPR_POSIX_ENV 1
270 #define GPR_POSIX_TMPFILE 1
271 #define GPR_POSIX_STRING 1
272 #define GPR_POSIX_SUBPROCESS 1
273 #define GPR_POSIX_SYNC 1
274 #define GPR_POSIX_TIME 1
275 #define GPR_HAS_PTHREAD_H 1
276 #define GPR_GETPID_IN_UNISTD_H 1
277 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
279 #define GPR_ARCH_64 1
281 #define GPR_ARCH_32 1
283 #elif defined(__OpenBSD__)
284 #define GPR_PLATFORM_STRING "openbsd"
288 #define GPR_OPENBSD 1
289 #define GPR_CPU_POSIX 1
290 #define GPR_GCC_ATOMIC 1
291 #define GPR_GCC_TLS 1
292 #define GPR_POSIX_LOG 1
293 #define GPR_POSIX_ENV 1
294 #define GPR_POSIX_TMPFILE 1
295 #define GPR_POSIX_STRING 1
296 #define GPR_POSIX_SUBPROCESS 1
297 #define GPR_POSIX_SYNC 1
298 #define GPR_POSIX_TIME 1
299 #define GPR_HAS_PTHREAD_H 1
300 #define GPR_GETPID_IN_UNISTD_H 1
301 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
303 #define GPR_ARCH_64 1
305 #define GPR_ARCH_32 1
307 #elif defined(__sun) && defined(__SVR4)
308 #define GPR_PLATFORM_STRING "solaris"
309 #define GPR_SOLARIS 1
310 #define GPR_CPU_POSIX 1
311 #define GPR_GCC_ATOMIC 1
312 #define GPR_GCC_TLS 1
313 #define GPR_POSIX_LOG 1
314 #define GPR_POSIX_ENV 1
315 #define GPR_POSIX_TMPFILE 1
316 #define GPR_POSIX_STRING 1
317 #define GPR_POSIX_SUBPROCESS 1
318 #define GPR_POSIX_SYNC 1
319 #define GPR_POSIX_TIME 1
320 #define GPR_HAS_PTHREAD_H 1
321 #define GPR_GETPID_IN_UNISTD_H 1
323 #define GPR_ARCH_64 1
325 #define GPR_ARCH_32 1
328 #define GPR_PLATFORM_STRING "aix"
333 #define GPR_CPU_POSIX 1
334 #define GPR_GCC_ATOMIC 1
335 #define GPR_GCC_TLS 1
336 #define GPR_POSIX_LOG 1
337 #define GPR_POSIX_ENV 1
338 #define GPR_POSIX_TMPFILE 1
339 #define GPR_POSIX_STRING 1
340 #define GPR_POSIX_SUBPROCESS 1
341 #define GPR_POSIX_SYNC 1
342 #define GPR_POSIX_TIME 1
343 #define GPR_HAS_PTHREAD_H 1
344 #define GPR_GETPID_IN_UNISTD_H 1
346 #define GPR_ARCH_64 1
348 #define GPR_ARCH_32 1
350 #elif defined(__native_client__)
351 #define GPR_PLATFORM_STRING "nacl"
355 #ifndef _DEFAULT_SOURCE
356 #define _DEFAULT_SOURCE
362 #define GPR_CPU_POSIX 1
363 #define GPR_GCC_ATOMIC 1
364 #define GPR_GCC_TLS 1
365 #define GPR_POSIX_LOG 1
366 #define GPR_POSIX_ENV 1
367 #define GPR_POSIX_TMPFILE 1
368 #define GPR_POSIX_STRING 1
369 #define GPR_POSIX_SUBPROCESS 1
370 #define GPR_POSIX_SYNC 1
371 #define GPR_POSIX_TIME 1
372 #define GPR_HAS_PTHREAD_H 1
373 #define GPR_GETPID_IN_UNISTD_H 1
375 #define GPR_ARCH_64 1
377 #define GPR_ARCH_32 1
379 #elif defined(__Fuchsia__)
380 #define GPR_FUCHSIA 1
381 #define GPR_ARCH_64 1
382 #define GPR_PLATFORM_STRING "fuchsia"
383 #include <features.h>
384 // Specifying musl libc affects wrap_memcpy.c. It causes memmove() to be
386 #define GPR_MUSL_LIBC_COMPAT 1
387 #define GPR_CPU_POSIX 1
388 #define GPR_GCC_ATOMIC 1
389 #define GPR_PTHREAD_TLS 1
390 #define GPR_POSIX_LOG 1
391 #define GPR_POSIX_SYNC 1
392 #define GPR_POSIX_ENV 1
393 #define GPR_POSIX_TMPFILE 1
394 #define GPR_POSIX_SUBPROCESS 1
395 #define GPR_POSIX_SYNC 1
396 #define GPR_POSIX_STRING 1
397 #define GPR_POSIX_TIME 1
398 #define GPR_HAS_PTHREAD_H 1
399 #define GPR_GETPID_IN_UNISTD_H 1
401 #error "Could not auto-detect platform"
403 #endif /* GPR_NO_AUTODETECT_PLATFORM */
405 #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
407 * For backward compatibility mode, reset _FORTIFY_SOURCE to prevent
408 * a library from having non-standard symbols such as __asprintf_chk.
409 * This helps non-glibc systems such as alpine using musl to find symbols.
411 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
412 #undef _FORTIFY_SOURCE
413 #define _FORTIFY_SOURCE 0
418 * There are platforms for which TLS should not be used even though the
419 * compiler makes it seem like it's supported (Android NDK < r12b for example).
420 * This is primarily because of linker problems and toolchain misconfiguration:
421 * TLS isn't supported until NDK r12b per
422 * https://developer.android.com/ndk/downloads/revision_history.html
423 * TLS also does not work with Android NDK if GCC is being used as the compiler
425 * Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
426 * <android/ndk-version.h>. For NDK < r16, users should define these macros,
427 * e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11. */
428 #if defined(__ANDROID__) && defined(GPR_GCC_TLS)
429 #if __has_include(<android/ndk-version.h>)
430 #include <android/ndk-version.h>
431 #endif /* __has_include(<android/ndk-version.h>) */
432 #if (defined(__clang__) && defined(__NDK_MAJOR__) && defined(__NDK_MINOR__) && \
433 ((__NDK_MAJOR__ < 12) || \
434 ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))) || \
435 (defined(__GNUC__) && !defined(__clang__))
437 #define GPR_PTHREAD_TLS 1
439 #endif /*defined(__ANDROID__) && defined(GPR_GCC_TLS) */
441 #if defined(__has_include)
442 #if __has_include(<atomic>)
443 #define GRPC_HAS_CXX11_ATOMIC
444 #endif /* __has_include(<atomic>) */
445 #endif /* defined(__has_include) */
447 #ifndef GPR_PLATFORM_STRING
448 #warning "GPR_PLATFORM_STRING not auto-detected"
449 #define GPR_PLATFORM_STRING "unknown"
453 #undef GPR_FORBID_UNREACHABLE_CODE
454 #define GPR_FORBID_UNREACHABLE_CODE 1
459 typedef __int8 int8_t;
460 typedef __int16 int16_t;
461 typedef __int32 int32_t;
462 typedef __int64 int64_t;
463 typedef unsigned __int8 uint8_t;
464 typedef unsigned __int16 uint16_t;
465 typedef unsigned __int32 uint32_t;
466 typedef unsigned __int64 uint64_t;
469 #endif /* _MSC_VER < 1700 */
472 #endif /* _MSC_VER */
474 /* Type of cycle clock implementation */
476 /* Disable cycle clock by default.
477 TODO(soheil): enable when we support fallback for unstable cycle clocks.
478 #if defined(__i386__)
479 #define GPR_CYCLE_COUNTER_RDTSC_32 1
480 #elif defined(__x86_64__) || defined(__amd64__)
481 #define GPR_CYCLE_COUNTER_RDTSC_64 1
483 #define GPR_CYCLE_COUNTER_FALLBACK 1
486 #define GPR_CYCLE_COUNTER_FALLBACK 1
488 #define GPR_CYCLE_COUNTER_FALLBACK 1
489 #endif /* GPR_LINUX */
491 /* Cache line alignment */
492 #ifndef GPR_CACHELINE_SIZE_LOG
493 #if defined(__i386__) || defined(__x86_64__)
494 #define GPR_CACHELINE_SIZE_LOG 6
496 #ifndef GPR_CACHELINE_SIZE_LOG
497 /* A reasonable default guess. Note that overestimates tend to waste more
498 space, while underestimates tend to waste more time. */
499 #define GPR_CACHELINE_SIZE_LOG 6
500 #endif /* GPR_CACHELINE_SIZE_LOG */
501 #endif /* GPR_CACHELINE_SIZE_LOG */
503 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
505 /* scrub GCC_ATOMIC if it's not available on this compiler */
506 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
507 #undef GPR_GCC_ATOMIC
508 #define GPR_GCC_SYNC 1
511 /* Validate platform combinations */
512 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
513 defined(GPR_WINDOWS_ATOMIC) != \
515 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
518 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
519 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
522 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
523 defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \
525 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
528 #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \
529 defined(GPR_CUSTOM_TLS) != \
531 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS
534 /* maximum alignment needed for any type on this platform, rounded up to a
536 #define GPR_MAX_ALIGNMENT 16
542 #ifndef GRPC_IF_NAMETOINDEX
543 #define GRPC_IF_NAMETOINDEX 1
546 #ifndef GRPC_MUST_USE_RESULT
547 #if defined(__GNUC__) && !defined(__MINGW32__)
548 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
549 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n)))
551 #define GRPC_MUST_USE_RESULT
552 #define GPR_ALIGN_STRUCT(n)
557 #if defined(__GNUC__) && !defined(__MINGW32__)
558 #define GRPC_UNUSED __attribute__((unused))
564 #ifndef GPR_PRINT_FORMAT_CHECK
566 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
567 __attribute__((format(printf, FORMAT_STR, ARGS)))
569 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
571 #endif /* GPR_PRINT_FORMAT_CHECK */
573 #if GPR_FORBID_UNREACHABLE_CODE
574 #define GPR_UNREACHABLE_CODE(STATEMENT)
576 #define GPR_UNREACHABLE_CODE(STATEMENT) \
578 gpr_log(GPR_ERROR, "Should never reach here."); \
582 #endif /* GPR_FORBID_UNREACHABLE_CODE */
589 #define GRPCAPI GPRAPI
593 #define CENSUSAPI GRPCAPI
596 #ifndef GPR_HAS_ATTRIBUTE
597 #ifdef __has_attribute
598 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
600 #define GPR_HAS_ATTRIBUTE(a) 0
602 #endif /* GPR_HAS_ATTRIBUTE */
604 #ifndef GPR_HAS_FEATURE
606 #define GPR_HAS_FEATURE(a) __has_feature(a)
608 #define GPR_HAS_FEATURE(a) 0
610 #endif /* GPR_HAS_FEATURE */
612 #ifndef GPR_ATTRIBUTE_NOINLINE
613 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
614 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
615 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
617 #define GPR_ATTRIBUTE_NOINLINE
619 #endif /* GPR_ATTRIBUTE_NOINLINE */
621 #ifndef GPR_ATTRIBUTE_WEAK
622 /* Attribute weak is broken on LLVM/windows:
623 * https://bugs.llvm.org/show_bug.cgi?id=37598 */
624 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
625 !(defined(__llvm__) && defined(_WIN32))
626 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
627 #define GPR_HAS_ATTRIBUTE_WEAK 1
629 #define GPR_ATTRIBUTE_WEAK
631 #endif /* GPR_ATTRIBUTE_WEAK */
633 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
634 #if GPR_HAS_FEATURE(thread_sanitizer)
635 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
636 #endif /* GPR_HAS_FEATURE */
637 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
638 #define GPR_ATTRIBUTE_NO_TSAN
639 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
640 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
642 /* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */
643 #if defined(__SANITIZE_THREAD__)
644 #define GRPC_TSAN_ENABLED
645 #elif GPR_HAS_FEATURE(thread_sanitizer)
646 #define GRPC_TSAN_ENABLED
649 /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */
650 #if defined(__SANITIZE_ADDRESS__)
651 #define GRPC_ASAN_ENABLED
652 #elif GPR_HAS_FEATURE(address_sanitizer)
653 #define GRPC_ASAN_ENABLED
656 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
657 #ifndef GRPC_ALLOW_EXCEPTIONS
658 /* If not already set, set to 1 on Windows (style guide standard) but to
659 * 0 on non-Windows platforms unless the compiler defines __EXCEPTIONS */
661 #define GRPC_ALLOW_EXCEPTIONS 1
662 #else /* GPR_WINDOWS */
664 #define GRPC_ALLOW_EXCEPTIONS 1
665 #else /* __EXCEPTIONS */
666 #define GRPC_ALLOW_EXCEPTIONS 0
667 #endif /* __EXCEPTIONS */
668 #endif /* __GPR_WINDOWS */
669 #endif /* GRPC_ALLOW_EXCEPTIONS */
671 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
672 * most likely. Ideally, also collect performance numbers to justify the claim.
675 #define GPR_LIKELY(x) __builtin_expect((x), 1)
676 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
678 #define GPR_LIKELY(x) (x)
679 #define GPR_UNLIKELY(x) (x)
680 #endif /* __GNUC__ */
682 #ifndef __STDC_FORMAT_MACROS
683 #define __STDC_FORMAT_MACROS
686 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */