1 /* 2 * 3 * Copyright 2015 gRPC authors. 4 * 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 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 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. 16 * 17 */ 18 19 #ifndef GRPC_IMPL_CODEGEN_PORT_PLATFORM_H 20 #define GRPC_IMPL_CODEGEN_PORT_PLATFORM_H 21 22 /* 23 * Define GPR_BACKWARDS_COMPATIBILITY_MODE to try harder to be ABI 24 * compatible with older platforms (currently only on Linux) 25 * Causes: 26 * - some libc calls to be gotten via dlsym 27 * - some syscalls to be made directly 28 */ 29 30 /* Get windows.h included everywhere (we need it) */ 31 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) 32 #ifndef WIN32_LEAN_AND_MEAN 33 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED 34 #define WIN32_LEAN_AND_MEAN 35 #endif /* WIN32_LEAN_AND_MEAN */ 36 37 #ifndef NOMINMAX 38 #define GRPC_NOMINMX_WAS_NOT_DEFINED 39 #define NOMINMAX 40 #endif /* NOMINMAX */ 41 42 #ifndef _WIN32_WINNT 43 #error \ 44 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)" 45 #else /* !defined(_WIN32_WINNT) */ 46 #if (_WIN32_WINNT < 0x0600) 47 #error \ 48 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)" 49 #endif /* _WIN32_WINNT < 0x0600 */ 50 #endif /* defined(_WIN32_WINNT) */ 51 52 #include <windows.h> 53 54 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED 55 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED 56 #undef WIN32_LEAN_AND_MEAN 57 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ 58 59 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED 60 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED 61 #undef NOMINMAX 62 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ 63 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \ 64 defined(WIN32) */ 65 66 /* Override this file with one for your platform if you need to redefine 67 things. */ 68 69 #if !defined(GPR_NO_AUTODETECT_PLATFORM) 70 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) 71 #if defined(_WIN64) || defined(WIN64) 72 #define GPR_ARCH_64 1 73 #else 74 #define GPR_ARCH_32 1 75 #endif 76 #define GPR_PLATFORM_STRING "windows" 77 #define GPR_WINDOWS 1 78 #define GPR_WINDOWS_SUBPROCESS 1 79 #define GPR_WINDOWS_ENV 80 #ifdef __MSYS__ 81 #define GPR_GETPID_IN_UNISTD_H 1 82 #define GPR_MSYS_TMPFILE 83 #define GPR_POSIX_LOG 84 #define GPR_POSIX_STRING 85 #define GPR_POSIX_TIME 86 #else 87 #define GPR_GETPID_IN_PROCESS_H 1 88 #define GPR_WINDOWS_TMPFILE 89 #define GPR_WINDOWS_LOG 90 #define GPR_WINDOWS_CRASH_HANDLER 1 91 #define GPR_WINDOWS_STRING 92 #define GPR_WINDOWS_TIME 93 #endif 94 #ifdef __GNUC__ 95 #define GPR_GCC_ATOMIC 1 96 #define GPR_GCC_TLS 1 97 #else 98 #define GPR_WINDOWS_ATOMIC 1 99 #define GPR_MSVC_TLS 1 100 #endif 101 #elif defined(GPR_MANYLINUX1) 102 // TODO(atash): manylinux1 is just another __linux__ but with ancient 103 // libraries; it should be integrated with the `__linux__` definitions below. 104 #define GPR_PLATFORM_STRING "manylinux" 105 #define GPR_POSIX_CRASH_HANDLER 1 106 #define GPR_CPU_POSIX 1 107 #define GPR_GCC_ATOMIC 1 108 #define GPR_GCC_TLS 1 109 #define GPR_LINUX 1 110 #define GPR_LINUX_LOG 1 111 #define GPR_SUPPORT_CHANNELS_FROM_FD 1 112 #define GPR_LINUX_ENV 1 113 #define GPR_POSIX_TMPFILE 1 114 #define GPR_POSIX_STRING 1 115 #define GPR_POSIX_SUBPROCESS 1 116 #define GPR_POSIX_SYNC 1 117 #define GPR_POSIX_TIME 1 118 #define GPR_GETPID_IN_UNISTD_H 1 119 #ifdef _LP64 120 #define GPR_ARCH_64 1 121 #else /* _LP64 */ 122 #define GPR_ARCH_32 1 123 #endif /* _LP64 */ 124 #elif defined(ANDROID) || defined(__ANDROID__) 125 #define GPR_PLATFORM_STRING "android" 126 #define GPR_ANDROID 1 127 #ifdef _LP64 128 #define GPR_ARCH_64 1 129 #else /* _LP64 */ 130 #define GPR_ARCH_32 1 131 #endif /* _LP64 */ 132 #define GPR_CPU_POSIX 1 133 #define GPR_GCC_SYNC 1 134 #define GPR_GCC_TLS 1 135 #define GPR_POSIX_ENV 1 136 #define GPR_POSIX_TMPFILE 1 137 #define GPR_ANDROID_LOG 1 138 #define GPR_POSIX_STRING 1 139 #define GPR_POSIX_SUBPROCESS 1 140 #define GPR_POSIX_SYNC 1 141 #define GPR_POSIX_TIME 1 142 #define GPR_GETPID_IN_UNISTD_H 1 143 #define GPR_SUPPORT_CHANNELS_FROM_FD 1 144 #elif defined(__linux__) 145 #define GPR_PLATFORM_STRING "linux" 146 #ifndef _BSD_SOURCE 147 #define _BSD_SOURCE 148 #endif 149 #ifndef _DEFAULT_SOURCE 150 #define _DEFAULT_SOURCE 151 #endif 152 #ifndef _GNU_SOURCE 153 #define _GNU_SOURCE 154 #endif 155 #include <features.h> 156 #define GPR_CPU_LINUX 1 157 #define GPR_GCC_ATOMIC 1 158 #define GPR_GCC_TLS 1 159 #define GPR_LINUX 1 160 #define GPR_LINUX_LOG 161 #define GPR_SUPPORT_CHANNELS_FROM_FD 1 162 #define GPR_LINUX_ENV 1 163 #define GPR_POSIX_TMPFILE 1 164 #define GPR_POSIX_STRING 1 165 #define GPR_POSIX_SUBPROCESS 1 166 #define GPR_POSIX_SYNC 1 167 #define GPR_POSIX_TIME 1 168 #define GPR_GETPID_IN_UNISTD_H 1 169 #ifdef _LP64 170 #define GPR_ARCH_64 1 171 #else /* _LP64 */ 172 #define GPR_ARCH_32 1 173 #endif /* _LP64 */ 174 #ifdef __GLIBC__ 175 #define GPR_POSIX_CRASH_HANDLER 1 176 #define GPR_LINUX_PTHREAD_NAME 1 177 #include <linux/version.h> 178 #else /* musl libc */ 179 #define GPR_MUSL_LIBC_COMPAT 1 180 #endif 181 #elif defined(__APPLE__) 182 #include <Availability.h> 183 #include <TargetConditionals.h> 184 #ifndef _BSD_SOURCE 185 #define _BSD_SOURCE 186 #endif 187 #if TARGET_OS_IPHONE 188 #define GPR_PLATFORM_STRING "ios" 189 #define GPR_CPU_IPHONE 1 190 #define GPR_PTHREAD_TLS 1 191 #else /* TARGET_OS_IPHONE */ 192 #define GPR_PLATFORM_STRING "osx" 193 #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED 194 #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7 195 #define GPR_CPU_IPHONE 1 196 #define GPR_PTHREAD_TLS 1 197 #else /* __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7 */ 198 #define GPR_CPU_POSIX 1 199 /* TODO(vjpai): there is a reported issue in bazel build for Mac where __thread 200 in a header is currently not working (bazelbuild/bazel#4341). Remove 201 the following conditional and use GPR_GCC_TLS when that is fixed */ 202 #ifndef GRPC_BAZEL_BUILD 203 #define GPR_GCC_TLS 1 204 #else /* GRPC_BAZEL_BUILD */ 205 #define GPR_PTHREAD_TLS 1 206 #endif /* GRPC_BAZEL_BUILD */ 207 #define GPR_APPLE_PTHREAD_NAME 1 208 #endif 209 #else /* __MAC_OS_X_VERSION_MIN_REQUIRED */ 210 #define GPR_CPU_POSIX 1 211 /* TODO(vjpai): Remove the following conditional and use only GPR_GCC_TLS 212 when bazelbuild/bazel#4341 is fixed */ 213 #ifndef GRPC_BAZEL_BUILD 214 #define GPR_GCC_TLS 1 215 #else /* GRPC_BAZEL_BUILD */ 216 #define GPR_PTHREAD_TLS 1 217 #endif /* GRPC_BAZEL_BUILD */ 218 #endif 219 #define GPR_POSIX_CRASH_HANDLER 1 220 #endif 221 #define GPR_APPLE 1 222 #define GPR_GCC_ATOMIC 1 223 #define GPR_POSIX_LOG 1 224 #define GPR_POSIX_ENV 1 225 #define GPR_POSIX_TMPFILE 1 226 #define GPR_POSIX_STRING 1 227 #define GPR_POSIX_SUBPROCESS 1 228 #define GPR_POSIX_SYNC 1 229 #define GPR_POSIX_TIME 1 230 #define GPR_GETPID_IN_UNISTD_H 1 231 /* TODO(mxyan): Remove when CFStream becomes default */ 232 #ifndef GRPC_CFSTREAM 233 #define GPR_SUPPORT_CHANNELS_FROM_FD 1 234 #endif 235 #ifdef _LP64 236 #define GPR_ARCH_64 1 237 #else /* _LP64 */ 238 #define GPR_ARCH_32 1 239 #endif /* _LP64 */ 240 #elif defined(__FreeBSD__) 241 #define GPR_PLATFORM_STRING "freebsd" 242 #ifndef _BSD_SOURCE 243 #define _BSD_SOURCE 244 #endif 245 #define GPR_FREEBSD 1 246 #define GPR_CPU_POSIX 1 247 #define GPR_GCC_ATOMIC 1 248 #define GPR_GCC_TLS 1 249 #define GPR_POSIX_LOG 1 250 #define GPR_POSIX_ENV 1 251 #define GPR_POSIX_TMPFILE 1 252 #define GPR_POSIX_STRING 1 253 #define GPR_POSIX_SUBPROCESS 1 254 #define GPR_POSIX_SYNC 1 255 #define GPR_POSIX_TIME 1 256 #define GPR_GETPID_IN_UNISTD_H 1 257 #define GPR_SUPPORT_CHANNELS_FROM_FD 1 258 #ifdef _LP64 259 #define GPR_ARCH_64 1 260 #else /* _LP64 */ 261 #define GPR_ARCH_32 1 262 #endif /* _LP64 */ 263 #elif defined(__OpenBSD__) 264 #define GPR_PLATFORM_STRING "openbsd" 265 #ifndef _BSD_SOURCE 266 #define _BSD_SOURCE 267 #endif 268 #define GPR_OPENBSD 1 269 #define GPR_CPU_POSIX 1 270 #define GPR_GCC_ATOMIC 1 271 #define GPR_GCC_TLS 1 272 #define GPR_POSIX_LOG 1 273 #define GPR_POSIX_ENV 1 274 #define GPR_POSIX_TMPFILE 1 275 #define GPR_POSIX_STRING 1 276 #define GPR_POSIX_SUBPROCESS 1 277 #define GPR_POSIX_SYNC 1 278 #define GPR_POSIX_TIME 1 279 #define GPR_GETPID_IN_UNISTD_H 1 280 #define GPR_SUPPORT_CHANNELS_FROM_FD 1 281 #ifdef _LP64 282 #define GPR_ARCH_64 1 283 #else /* _LP64 */ 284 #define GPR_ARCH_32 1 285 #endif /* _LP64 */ 286 #elif defined(__sun) && defined(__SVR4) 287 #define GPR_PLATFORM_STRING "solaris" 288 #define GPR_SOLARIS 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_GETPID_IN_UNISTD_H 1 300 #ifdef _LP64 301 #define GPR_ARCH_64 1 302 #else /* _LP64 */ 303 #define GPR_ARCH_32 1 304 #endif /* _LP64 */ 305 #elif defined(_AIX) 306 #define GPR_PLATFORM_STRING "aix" 307 #ifndef _ALL_SOURCE 308 #define _ALL_SOURCE 309 #endif 310 #define GPR_AIX 1 311 #define GPR_CPU_POSIX 1 312 #define GPR_GCC_ATOMIC 1 313 #define GPR_GCC_TLS 1 314 #define GPR_POSIX_LOG 1 315 #define GPR_POSIX_ENV 1 316 #define GPR_POSIX_TMPFILE 1 317 #define GPR_POSIX_STRING 1 318 #define GPR_POSIX_SUBPROCESS 1 319 #define GPR_POSIX_SYNC 1 320 #define GPR_POSIX_TIME 1 321 #define GPR_GETPID_IN_UNISTD_H 1 322 #ifdef _LP64 323 #define GPR_ARCH_64 1 324 #else /* _LP64 */ 325 #define GPR_ARCH_32 1 326 #endif /* _LP64 */ 327 #elif defined(__native_client__) 328 #define GPR_PLATFORM_STRING "nacl" 329 #ifndef _BSD_SOURCE 330 #define _BSD_SOURCE 331 #endif 332 #ifndef _DEFAULT_SOURCE 333 #define _DEFAULT_SOURCE 334 #endif 335 #ifndef _GNU_SOURCE 336 #define _GNU_SOURCE 337 #endif 338 #define GPR_NACL 1 339 #define GPR_CPU_POSIX 1 340 #define GPR_GCC_ATOMIC 1 341 #define GPR_GCC_TLS 1 342 #define GPR_POSIX_LOG 1 343 #define GPR_POSIX_ENV 1 344 #define GPR_POSIX_TMPFILE 1 345 #define GPR_POSIX_STRING 1 346 #define GPR_POSIX_SUBPROCESS 1 347 #define GPR_POSIX_SYNC 1 348 #define GPR_POSIX_TIME 1 349 #define GPR_GETPID_IN_UNISTD_H 1 350 #ifdef _LP64 351 #define GPR_ARCH_64 1 352 #else /* _LP64 */ 353 #define GPR_ARCH_32 1 354 #endif /* _LP64 */ 355 #else 356 #error "Could not auto-detect platform" 357 #endif 358 #endif /* GPR_NO_AUTODETECT_PLATFORM */ 359 360 /* 361 * There are platforms for which TLS should not be used even though the 362 * compiler makes it seem like it's supported (Android NDK < r12b for example). 363 * This is primarily because of linker problems and toolchain misconfiguration: 364 * TLS isn't supported until NDK r12b per 365 * https://developer.android.com/ndk/downloads/revision_history.html 366 * TLS also does not work with Android NDK if GCC is being used as the compiler 367 * instead of Clang. 368 * Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in 369 * <android/ndk-version.h>. For NDK < r16, users should define these macros, 370 * e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11. */ 371 #if defined(__ANDROID__) && defined(GPR_GCC_TLS) 372 #if __has_include(<android/ndk-version.h>) 373 #include <android/ndk-version.h> 374 #endif /* __has_include(<android/ndk-version.h>) */ 375 #if (defined(__clang__) && defined(__NDK_MAJOR__) && defined(__NDK_MINOR__) && \ 376 ((__NDK_MAJOR__ < 12) || \ 377 ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))) || \ 378 (defined(__GNUC__) && !defined(__clang__)) 379 #undef GPR_GCC_TLS 380 #define GPR_PTHREAD_TLS 1 381 #endif 382 #endif /*defined(__ANDROID__) && defined(GPR_GCC_TLS) */ 383 384 #if defined(__has_include) 385 #if __has_include(<atomic>) 386 #define GRPC_HAS_CXX11_ATOMIC 387 #endif /* __has_include(<atomic>) */ 388 #endif /* defined(__has_include) */ 389 390 #ifndef GPR_PLATFORM_STRING 391 #warning "GPR_PLATFORM_STRING not auto-detected" 392 #define GPR_PLATFORM_STRING "unknown" 393 #endif 394 395 #ifdef GPR_GCOV 396 #undef GPR_FORBID_UNREACHABLE_CODE 397 #define GPR_FORBID_UNREACHABLE_CODE 1 398 #endif 399 400 #ifdef _MSC_VER 401 #if _MSC_VER < 1700 402 typedef __int8 int8_t; 403 typedef __int16 int16_t; 404 typedef __int32 int32_t; 405 typedef __int64 int64_t; 406 typedef unsigned __int8 uint8_t; 407 typedef unsigned __int16 uint16_t; 408 typedef unsigned __int32 uint32_t; 409 typedef unsigned __int64 uint64_t; 410 #else 411 #include <stdint.h> 412 #endif /* _MSC_VER < 1700 */ 413 #else 414 #include <stdint.h> 415 #endif /* _MSC_VER */ 416 417 /* Cache line alignment */ 418 #ifndef GPR_CACHELINE_SIZE_LOG 419 #if defined(__i386__) || defined(__x86_64__) 420 #define GPR_CACHELINE_SIZE_LOG 6 421 #endif 422 #ifndef GPR_CACHELINE_SIZE_LOG 423 /* A reasonable default guess. Note that overestimates tend to waste more 424 space, while underestimates tend to waste more time. */ 425 #define GPR_CACHELINE_SIZE_LOG 6 426 #endif /* GPR_CACHELINE_SIZE_LOG */ 427 #endif /* GPR_CACHELINE_SIZE_LOG */ 428 429 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG) 430 431 /* scrub GCC_ATOMIC if it's not available on this compiler */ 432 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED) 433 #undef GPR_GCC_ATOMIC 434 #define GPR_GCC_SYNC 1 435 #endif 436 437 /* Validate platform combinations */ 438 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \ 439 defined(GPR_WINDOWS_ATOMIC) != \ 440 1 441 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC 442 #endif 443 444 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1 445 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64 446 #endif 447 448 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \ 449 defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \ 450 1 451 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM 452 #endif 453 454 #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \ 455 defined(GPR_CUSTOM_TLS) != \ 456 1 457 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS 458 #endif 459 460 /* maximum alignment needed for any type on this platform, rounded up to a 461 power of two */ 462 #define GPR_MAX_ALIGNMENT 16 463 464 #ifndef GRPC_ARES 465 #define GRPC_ARES 1 466 #endif 467 468 #ifndef GRPC_MUST_USE_RESULT 469 #if defined(__GNUC__) && !defined(__MINGW32__) 470 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result)) 471 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n))) 472 #else 473 #define GRPC_MUST_USE_RESULT 474 #define GPR_ALIGN_STRUCT(n) 475 #endif 476 #endif 477 478 #ifndef GRPC_UNUSED 479 #if defined(__GNUC__) && !defined(__MINGW32__) 480 #define GRPC_UNUSED __attribute__((unused)) 481 #else 482 #define GRPC_UNUSED 483 #endif 484 #endif 485 486 #ifndef GPR_PRINT_FORMAT_CHECK 487 #ifdef __GNUC__ 488 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \ 489 __attribute__((format(printf, FORMAT_STR, ARGS))) 490 #else 491 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) 492 #endif 493 #endif /* GPR_PRINT_FORMAT_CHECK */ 494 495 #if GPR_FORBID_UNREACHABLE_CODE 496 #define GPR_UNREACHABLE_CODE(STATEMENT) 497 #else 498 #define GPR_UNREACHABLE_CODE(STATEMENT) \ 499 do { \ 500 gpr_log(GPR_ERROR, "Should never reach here."); \ 501 abort(); \ 502 STATEMENT; \ 503 } while (0) 504 #endif /* GPR_FORBID_UNREACHABLE_CODE */ 505 506 #ifndef GPRAPI 507 #define GPRAPI 508 #endif 509 510 #ifndef GRPCAPI 511 #define GRPCAPI GPRAPI 512 #endif 513 514 #ifndef CENSUSAPI 515 #define CENSUSAPI GRPCAPI 516 #endif 517 518 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */ 519 #if defined(__has_feature) 520 #if __has_feature(thread_sanitizer) 521 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread"))) 522 #endif /* __has_feature(thread_sanitizer) */ 523 #endif /* defined(__has_feature) */ 524 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */ 525 #define GPR_ATTRIBUTE_NO_TSAN 526 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */ 527 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */ 528 529 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */ 530 #ifndef GRPC_ALLOW_EXCEPTIONS 531 /* If not already set, set to 1 on Windows (style guide standard) but to 532 * 0 on non-Windows platforms unless the compiler defines __EXCEPTIONS */ 533 #ifdef GPR_WINDOWS 534 #define GRPC_ALLOW_EXCEPTIONS 1 535 #else /* GPR_WINDOWS */ 536 #ifdef __EXCEPTIONS 537 #define GRPC_ALLOW_EXCEPTIONS 1 538 #else /* __EXCEPTIONS */ 539 #define GRPC_ALLOW_EXCEPTIONS 0 540 #endif /* __EXCEPTIONS */ 541 #endif /* __GPR_WINDOWS */ 542 #endif /* GRPC_ALLOW_EXCEPTIONS */ 543 544 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the 545 * most likely. Ideally, also collect performance numbers to justify the claim. 546 */ 547 #ifdef __GNUC__ 548 #define GPR_LIKELY(x) __builtin_expect((x), 1) 549 #define GPR_UNLIKELY(x) __builtin_expect((x), 0) 550 #else /* __GNUC__ */ 551 #define GPR_LIKELY(x) (x) 552 #define GPR_UNLIKELY(x) (x) 553 #endif /* __GNUC__ */ 554 555 #ifndef __STDC_FORMAT_MACROS 556 #define __STDC_FORMAT_MACROS 557 #endif 558 559 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */ 560