diff --git a/include/grpc/impl/codegen/sync.h b/include/grpc/impl/codegen/sync.h index 1b30ea7551d..96e6c91c442 100644 --- a/include/grpc/impl/codegen/sync.h +++ b/include/grpc/impl/codegen/sync.h @@ -21,48 +21,9 @@ // IWYU pragma: private, include -/** Synchronization primitives for GPR. +#include - The type gpr_mu provides a non-reentrant mutex (lock). - - The type gpr_cv provides a condition variable. - - The type gpr_once provides for one-time initialization. - - The type gpr_event provides one-time-setting, reading, and - waiting of a void*, with memory barriers. - - The type gpr_refcount provides an object reference counter, - with memory barriers suitable to control - object lifetimes. - - The type gpr_stats_counter provides an atomic statistics counter. It - provides no memory barriers. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Platform-specific type declarations of gpr_mu and gpr_cv. */ -#include - -#include // IWYU pragma: export - -#if defined(GPR_CUSTOM_SYNC) -#include // IWYU pragma: export -#elif defined(GPR_ABSEIL_SYNC) -#include // IWYU pragma: export -#elif defined(GPR_POSIX_SYNC) -#include // IWYU pragma: export -#elif defined(GPR_WINDOWS) -#include // IWYU pragma: export -#else -#error Unable to determine platform for sync -#endif - -#ifdef __cplusplus -} -#endif +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif /* GRPC_IMPL_CODEGEN_SYNC_H */ diff --git a/include/grpc/impl/codegen/sync_abseil.h b/include/grpc/impl/codegen/sync_abseil.h index 92b31697fd0..afb492a84d3 100644 --- a/include/grpc/impl/codegen/sync_abseil.h +++ b/include/grpc/impl/codegen/sync_abseil.h @@ -21,18 +21,9 @@ // IWYU pragma: private, include -#include +#include -#include - -#ifdef GPR_ABSEIL_SYNC - -typedef intptr_t gpr_mu; -typedef intptr_t gpr_cv; -typedef int32_t gpr_once; - -#define GPR_ONCE_INIT 0 - -#endif +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif /* GRPC_IMPL_CODEGEN_SYNC_ABSEIL_H */ diff --git a/include/grpc/impl/codegen/sync_custom.h b/include/grpc/impl/codegen/sync_custom.h index ec0d6728e87..ab8e95a6f7a 100644 --- a/include/grpc/impl/codegen/sync_custom.h +++ b/include/grpc/impl/codegen/sync_custom.h @@ -21,20 +21,9 @@ // IWYU pragma: private, include -#include +#include -#include - -/* Users defining GPR_CUSTOM_SYNC need to define the following macros. */ - -#ifdef GPR_CUSTOM_SYNC - -typedef GPR_CUSTOM_MU_TYPE gpr_mu; -typedef GPR_CUSTOM_CV_TYPE gpr_cv; -typedef GPR_CUSTOM_ONCE_TYPE gpr_once; - -#define GPR_ONCE_INIT GPR_CUSTOM_ONCE_INIT - -#endif +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif /* GRPC_IMPL_CODEGEN_SYNC_CUSTOM_H */ diff --git a/include/grpc/impl/codegen/sync_generic.h b/include/grpc/impl/codegen/sync_generic.h index a79b9c648b2..e4924b2be15 100644 --- a/include/grpc/impl/codegen/sync_generic.h +++ b/include/grpc/impl/codegen/sync_generic.h @@ -21,31 +21,9 @@ // IWYU pragma: private, include -/* Generic type definitions for gpr_sync. */ +#include -#include - -#include - -/* gpr_event */ -typedef struct { - gpr_atm state; -} gpr_event; - -#define GPR_EVENT_INIT \ - { 0 } - -/* gpr_refcount */ -typedef struct { - gpr_atm count; -} gpr_refcount; - -/* gpr_stats_counter */ -typedef struct { - gpr_atm value; -} gpr_stats_counter; - -#define GPR_STATS_INIT \ - { 0 } +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif /* GRPC_IMPL_CODEGEN_SYNC_GENERIC_H */ diff --git a/include/grpc/impl/codegen/sync_posix.h b/include/grpc/impl/codegen/sync_posix.h index f5cf482c71c..c895ec59b7f 100644 --- a/include/grpc/impl/codegen/sync_posix.h +++ b/include/grpc/impl/codegen/sync_posix.h @@ -21,34 +21,9 @@ // IWYU pragma: private, include -#include +#include -#include - -#include - -#ifdef GRPC_ASAN_ENABLED -/* The member |leak_checker| is used to check whether there is a memory leak - * caused by upper layer logic that's missing the |gpr_xx_destroy| call - * to the object before freeing it. - * This issue was reported at https://github.com/grpc/grpc/issues/17563 - * and discussed at https://github.com/grpc/grpc/pull/17586 - */ -typedef struct { - pthread_mutex_t mutex; - int* leak_checker; -} gpr_mu; - -typedef struct { - pthread_cond_t cond_var; - int* leak_checker; -} gpr_cv; -#else -typedef pthread_mutex_t gpr_mu; -typedef pthread_cond_t gpr_cv; -#endif -typedef pthread_once_t gpr_once; - -#define GPR_ONCE_INIT PTHREAD_ONCE_INIT +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif /* GRPC_IMPL_CODEGEN_SYNC_POSIX_H */ diff --git a/include/grpc/impl/codegen/sync_windows.h b/include/grpc/impl/codegen/sync_windows.h index 2bee03b653f..5da49f4b73d 100644 --- a/include/grpc/impl/codegen/sync_windows.h +++ b/include/grpc/impl/codegen/sync_windows.h @@ -21,22 +21,9 @@ // IWYU pragma: private, include -#include +#include -#ifdef GPR_WINDOWS - -#include - -typedef struct { - CRITICAL_SECTION cs; /* Not an SRWLock until Vista is unsupported */ - int locked; -} gpr_mu; - -typedef CONDITION_VARIABLE gpr_cv; - -typedef INIT_ONCE gpr_once; -#define GPR_ONCE_INIT INIT_ONCE_STATIC_INIT - -#endif /* GPR_WINDOWS */ +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif /* GRPC_IMPL_CODEGEN_SYNC_WINDOWS_H */ diff --git a/include/grpc/support/sync.h b/include/grpc/support/sync.h index b1f5b786855..fe067ddc63d 100644 --- a/include/grpc/support/sync.h +++ b/include/grpc/support/sync.h @@ -19,15 +19,48 @@ #ifndef GRPC_SUPPORT_SYNC_H #define GRPC_SUPPORT_SYNC_H +/* Platform-specific type declarations of gpr_mu and gpr_cv. */ #include #include /* for gpr_timespec */ -#include // IWYU pragma: export #ifdef __cplusplus extern "C" { #endif +/** Synchronization primitives for GPR. + + The type gpr_mu provides a non-reentrant mutex (lock). + + The type gpr_cv provides a condition variable. + + The type gpr_once provides for one-time initialization. + + The type gpr_event provides one-time-setting, reading, and + waiting of a void*, with memory barriers. + + The type gpr_refcount provides an object reference counter, + with memory barriers suitable to control + object lifetimes. + + The type gpr_stats_counter provides an atomic statistics counter. It + provides no memory barriers. + */ + +#include // IWYU pragma: export + +#if defined(GPR_CUSTOM_SYNC) +#include // IWYU pragma: export +#elif defined(GPR_ABSEIL_SYNC) +#include // IWYU pragma: export +#elif defined(GPR_POSIX_SYNC) +#include // IWYU pragma: export +#elif defined(GPR_WINDOWS) +#include // IWYU pragma: export +#else +#error Unable to determine platform for sync +#endif + /** --- Mutex interface --- At most one thread may hold an exclusive lock on a mutex at any given time. diff --git a/include/grpc/support/sync_abseil.h b/include/grpc/support/sync_abseil.h index d6ad969273e..85153191999 100644 --- a/include/grpc/support/sync_abseil.h +++ b/include/grpc/support/sync_abseil.h @@ -21,6 +21,16 @@ #include -#include // IWYU pragma: export +#include + +#ifdef GPR_ABSEIL_SYNC + +typedef intptr_t gpr_mu; +typedef intptr_t gpr_cv; +typedef int32_t gpr_once; + +#define GPR_ONCE_INIT 0 + +#endif #endif /* GRPC_SUPPORT_SYNC_ABSEIL_H */ diff --git a/include/grpc/support/sync_custom.h b/include/grpc/support/sync_custom.h index de7e2200d60..c0e6975f07f 100644 --- a/include/grpc/support/sync_custom.h +++ b/include/grpc/support/sync_custom.h @@ -21,6 +21,18 @@ #include -#include // IWYU pragma: export +#include + +/* Users defining GPR_CUSTOM_SYNC need to define the following macros. */ + +#ifdef GPR_CUSTOM_SYNC + +typedef GPR_CUSTOM_MU_TYPE gpr_mu; +typedef GPR_CUSTOM_CV_TYPE gpr_cv; +typedef GPR_CUSTOM_ONCE_TYPE gpr_once; + +#define GPR_ONCE_INIT GPR_CUSTOM_ONCE_INIT + +#endif #endif /* GRPC_SUPPORT_SYNC_CUSTOM_H */ diff --git a/include/grpc/support/sync_generic.h b/include/grpc/support/sync_generic.h index d1d9fd7e54f..9e92eb2fec7 100644 --- a/include/grpc/support/sync_generic.h +++ b/include/grpc/support/sync_generic.h @@ -19,8 +19,31 @@ #ifndef GRPC_SUPPORT_SYNC_GENERIC_H #define GRPC_SUPPORT_SYNC_GENERIC_H +/* Generic type definitions for gpr_sync. */ + #include -#include // IWYU pragma: export +#include + +/* gpr_event */ +typedef struct { + gpr_atm state; +} gpr_event; + +#define GPR_EVENT_INIT \ + { 0 } + +/* gpr_refcount */ +typedef struct { + gpr_atm count; +} gpr_refcount; + +/* gpr_stats_counter */ +typedef struct { + gpr_atm value; +} gpr_stats_counter; + +#define GPR_STATS_INIT \ + { 0 } #endif /* GRPC_SUPPORT_SYNC_GENERIC_H */ diff --git a/include/grpc/support/sync_posix.h b/include/grpc/support/sync_posix.h index b971cd10f4c..b7aba572443 100644 --- a/include/grpc/support/sync_posix.h +++ b/include/grpc/support/sync_posix.h @@ -21,6 +21,32 @@ #include -#include // IWYU pragma: export +#include + +#include + +#ifdef GRPC_ASAN_ENABLED +/* The member |leak_checker| is used to check whether there is a memory leak + * caused by upper layer logic that's missing the |gpr_xx_destroy| call + * to the object before freeing it. + * This issue was reported at https://github.com/grpc/grpc/issues/17563 + * and discussed at https://github.com/grpc/grpc/pull/17586 + */ +typedef struct { + pthread_mutex_t mutex; + int* leak_checker; +} gpr_mu; + +typedef struct { + pthread_cond_t cond_var; + int* leak_checker; +} gpr_cv; +#else +typedef pthread_mutex_t gpr_mu; +typedef pthread_cond_t gpr_cv; +#endif +typedef pthread_once_t gpr_once; + +#define GPR_ONCE_INIT PTHREAD_ONCE_INIT #endif /* GRPC_SUPPORT_SYNC_POSIX_H */ diff --git a/include/grpc/support/sync_windows.h b/include/grpc/support/sync_windows.h index 3ee4a6ffa1b..8cba8ae73e4 100644 --- a/include/grpc/support/sync_windows.h +++ b/include/grpc/support/sync_windows.h @@ -21,6 +21,20 @@ #include -#include // IWYU pragma: export +#ifdef GPR_WINDOWS + +#include + +typedef struct { + CRITICAL_SECTION cs; /* Not an SRWLock until Vista is unsupported */ + int locked; +} gpr_mu; + +typedef CONDITION_VARIABLE gpr_cv; + +typedef INIT_ONCE gpr_once; +#define GPR_ONCE_INIT INIT_ONCE_STATIC_INIT + +#endif /* GPR_WINDOWS */ #endif /* GRPC_SUPPORT_SYNC_WINDOWS_H */ diff --git a/test/core/iomgr/ios/CFStreamTests/CFStreamClientTests.mm b/test/core/iomgr/ios/CFStreamTests/CFStreamClientTests.mm index 99ae59f35ed..7d01e98ba27 100644 --- a/test/core/iomgr/ios/CFStreamTests/CFStreamClientTests.mm +++ b/test/core/iomgr/ios/CFStreamTests/CFStreamClientTests.mm @@ -25,7 +25,6 @@ #include #include -#include #include #include "src/core/lib/address_utils/parse_address.h" diff --git a/test/core/iomgr/ios/CFStreamTests/CFStreamEndpointTests.mm b/test/core/iomgr/ios/CFStreamTests/CFStreamEndpointTests.mm index 7bdbe590e36..550f1302316 100644 --- a/test/core/iomgr/ios/CFStreamTests/CFStreamEndpointTests.mm +++ b/test/core/iomgr/ios/CFStreamTests/CFStreamEndpointTests.mm @@ -27,7 +27,6 @@ #include #include -#include #include #include "src/core/lib/address_utils/parse_address.h"