Rename new public API

reviewable/pr17308/r1
yang-g 6 years ago
parent 233406d450
commit 545c555d31
  1. 2
      grpc.def
  2. 5
      include/grpc/grpc.h
  3. 32
      src/core/lib/surface/init.cc
  4. 1
      src/core/lib/surface/init.h
  5. 3
      src/php/ext/grpc/php_grpc.c
  6. 4
      src/ruby/ext/grpc/rb_grpc_imports.generated.c
  7. 6
      src/ruby/ext/grpc/rb_grpc_imports.generated.h
  8. 4
      test/core/memory_usage/client.cc
  9. 4
      test/core/memory_usage/server.cc
  10. 16
      test/core/surface/init_test.cc
  11. 2
      test/core/surface/public_headers_must_be_c89.c
  12. 4
      test/core/util/port.cc
  13. 1
      test/core/util/test_config.cc
  14. 6
      test/cpp/naming/address_sorting_test.cc

@ -16,7 +16,7 @@ EXPORTS
grpc_init grpc_init
grpc_shutdown grpc_shutdown
grpc_is_initialized grpc_is_initialized
grpc_maybe_wait_for_async_shutdown grpc_shutdown_blocking
grpc_version_string grpc_version_string
grpc_g_stands_for grpc_g_stands_for
grpc_completion_queue_factory_lookup grpc_completion_queue_factory_lookup

@ -86,9 +86,10 @@ GRPCAPI void grpc_shutdown(void);
part of stabilizing the fork support API, as tracked in part of stabilizing the fork support API, as tracked in
https://github.com/grpc/grpc/issues/15334 */ https://github.com/grpc/grpc/issues/15334 */
GRPCAPI int grpc_is_initialized(void); GRPCAPI int grpc_is_initialized(void);
/** EXPERIMENTAL. Wait for grpc_shutdown to finish if it is in process.
/** EXPERIMENTAL. Blocking shut down grpc library.
This is only for wrapped language to use now. */ This is only for wrapped language to use now. */
GRPCAPI void grpc_maybe_wait_for_async_shutdown(void); GRPCAPI void grpc_shutdown_blocking(void);
/** Return a string representing the current version of grpc */ /** Return a string representing the current version of grpc */
GRPCAPI const char* grpc_version_string(void); GRPCAPI const char* grpc_version_string(void);

@ -164,16 +164,8 @@ void grpc_init(void) {
GRPC_API_TRACE("grpc_init(void)", 0, ()); GRPC_API_TRACE("grpc_init(void)", 0, ());
} }
void grpc_shutdown_internal(void* ignored) { void grpc_shutdown_internal_locked(void) {
int i; int i;
GRPC_API_TRACE("grpc_shutdown_internal", 0, ());
gpr_mu_lock(&g_init_mu);
// We have released lock from the shutdown thread and it is possible that
// another grpc_init has been called, and do nothing if that is the case.
if (--g_initializations != 0) {
gpr_mu_unlock(&g_init_mu);
return;
}
{ {
grpc_core::ExecCtx exec_ctx(0); grpc_core::ExecCtx exec_ctx(0);
grpc_iomgr_shutdown_background_closure(); grpc_iomgr_shutdown_background_closure();
@ -200,6 +192,18 @@ void grpc_shutdown_internal(void* ignored) {
grpc_core::ApplicationCallbackExecCtx::GlobalShutdown(); grpc_core::ApplicationCallbackExecCtx::GlobalShutdown();
g_shutting_down = false; g_shutting_down = false;
gpr_cv_broadcast(g_shutting_down_cv); gpr_cv_broadcast(g_shutting_down_cv);
}
void grpc_shutdown_internal(void* ignored) {
GRPC_API_TRACE("grpc_shutdown_internal", 0, ());
gpr_mu_lock(&g_init_mu);
// We have released lock from the shutdown thread and it is possible that
// another grpc_init has been called, and do nothing if that is the case.
if (--g_initializations != 0) {
gpr_mu_unlock(&g_init_mu);
return;
}
grpc_shutdown_internal_locked();
gpr_mu_unlock(&g_init_mu); gpr_mu_unlock(&g_init_mu);
} }
@ -219,6 +223,16 @@ void grpc_shutdown(void) {
gpr_mu_unlock(&g_init_mu); gpr_mu_unlock(&g_init_mu);
} }
void grpc_shutdown_blocking(void) {
GRPC_API_TRACE("grpc_shutdown_blocking(void)", 0, ());
gpr_mu_lock(&g_init_mu);
if (--g_initializations == 0) {
g_shutting_down = true;
grpc_shutdown_internal_locked();
}
gpr_mu_unlock(&g_init_mu);
}
int grpc_is_initialized(void) { int grpc_is_initialized(void) {
int r; int r;
gpr_once_init(&g_basic_init, do_basic_init); gpr_once_init(&g_basic_init, do_basic_init);

@ -22,5 +22,6 @@
void grpc_register_security_filters(void); void grpc_register_security_filters(void);
void grpc_security_pre_init(void); void grpc_security_pre_init(void);
void grpc_security_init(void); void grpc_security_init(void);
void grpc_maybe_wait_for_async_shutdown(void);
#endif /* GRPC_CORE_LIB_SURFACE_INIT_H */ #endif /* GRPC_CORE_LIB_SURFACE_INIT_H */

@ -361,8 +361,7 @@ PHP_MSHUTDOWN_FUNCTION(grpc) {
zend_hash_destroy(&grpc_target_upper_bound_map); zend_hash_destroy(&grpc_target_upper_bound_map);
grpc_shutdown_timeval(TSRMLS_C); grpc_shutdown_timeval(TSRMLS_C);
grpc_php_shutdown_completion_queue(TSRMLS_C); grpc_php_shutdown_completion_queue(TSRMLS_C);
grpc_shutdown(); grpc_shutdown_blocking();
grpc_maybe_wait_for_async_shutdown();
GRPC_G(initialized) = 0; GRPC_G(initialized) = 0;
} }
return SUCCESS; return SUCCESS;

@ -39,7 +39,7 @@ grpc_register_plugin_type grpc_register_plugin_import;
grpc_init_type grpc_init_import; grpc_init_type grpc_init_import;
grpc_shutdown_type grpc_shutdown_import; grpc_shutdown_type grpc_shutdown_import;
grpc_is_initialized_type grpc_is_initialized_import; grpc_is_initialized_type grpc_is_initialized_import;
grpc_maybe_wait_for_async_shutdown_type grpc_maybe_wait_for_async_shutdown_import; grpc_shutdown_blocking_type grpc_shutdown_blocking_import;
grpc_version_string_type grpc_version_string_import; grpc_version_string_type grpc_version_string_import;
grpc_g_stands_for_type grpc_g_stands_for_import; grpc_g_stands_for_type grpc_g_stands_for_import;
grpc_completion_queue_factory_lookup_type grpc_completion_queue_factory_lookup_import; grpc_completion_queue_factory_lookup_type grpc_completion_queue_factory_lookup_import;
@ -307,7 +307,7 @@ void grpc_rb_load_imports(HMODULE library) {
grpc_init_import = (grpc_init_type) GetProcAddress(library, "grpc_init"); grpc_init_import = (grpc_init_type) GetProcAddress(library, "grpc_init");
grpc_shutdown_import = (grpc_shutdown_type) GetProcAddress(library, "grpc_shutdown"); grpc_shutdown_import = (grpc_shutdown_type) GetProcAddress(library, "grpc_shutdown");
grpc_is_initialized_import = (grpc_is_initialized_type) GetProcAddress(library, "grpc_is_initialized"); grpc_is_initialized_import = (grpc_is_initialized_type) GetProcAddress(library, "grpc_is_initialized");
grpc_maybe_wait_for_async_shutdown_import = (grpc_maybe_wait_for_async_shutdown_type) GetProcAddress(library, "grpc_maybe_wait_for_async_shutdown"); grpc_shutdown_blocking_import = (grpc_shutdown_blocking_type) GetProcAddress(library, "grpc_shutdown_blocking");
grpc_version_string_import = (grpc_version_string_type) GetProcAddress(library, "grpc_version_string"); grpc_version_string_import = (grpc_version_string_type) GetProcAddress(library, "grpc_version_string");
grpc_g_stands_for_import = (grpc_g_stands_for_type) GetProcAddress(library, "grpc_g_stands_for"); grpc_g_stands_for_import = (grpc_g_stands_for_type) GetProcAddress(library, "grpc_g_stands_for");
grpc_completion_queue_factory_lookup_import = (grpc_completion_queue_factory_lookup_type) GetProcAddress(library, "grpc_completion_queue_factory_lookup"); grpc_completion_queue_factory_lookup_import = (grpc_completion_queue_factory_lookup_type) GetProcAddress(library, "grpc_completion_queue_factory_lookup");

@ -92,9 +92,9 @@ extern grpc_shutdown_type grpc_shutdown_import;
typedef int(*grpc_is_initialized_type)(void); typedef int(*grpc_is_initialized_type)(void);
extern grpc_is_initialized_type grpc_is_initialized_import; extern grpc_is_initialized_type grpc_is_initialized_import;
#define grpc_is_initialized grpc_is_initialized_import #define grpc_is_initialized grpc_is_initialized_import
typedef void(*grpc_maybe_wait_for_async_shutdown_type)(void); typedef void(*grpc_shutdown_blocking_type)(void);
extern grpc_maybe_wait_for_async_shutdown_type grpc_maybe_wait_for_async_shutdown_import; extern grpc_shutdown_blocking_type grpc_shutdown_blocking_import;
#define grpc_maybe_wait_for_async_shutdown grpc_maybe_wait_for_async_shutdown_import #define grpc_shutdown_blocking grpc_shutdown_blocking_import
typedef const char*(*grpc_version_string_type)(void); typedef const char*(*grpc_version_string_type)(void);
extern grpc_version_string_type grpc_version_string_import; extern grpc_version_string_type grpc_version_string_import;
#define grpc_version_string grpc_version_string_import #define grpc_version_string grpc_version_string_import

@ -29,7 +29,6 @@
#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/surface/init.h"
#include "test/core/util/cmdline.h" #include "test/core/util/cmdline.h"
#include "test/core/util/memory_counters.h" #include "test/core/util/memory_counters.h"
@ -286,8 +285,7 @@ int main(int argc, char** argv) {
grpc_slice_unref(slice); grpc_slice_unref(slice);
grpc_completion_queue_destroy(cq); grpc_completion_queue_destroy(cq);
grpc_shutdown(); grpc_shutdown_blocking();
grpc_maybe_wait_for_async_shutdown();
gpr_log(GPR_INFO, "---------client stats--------"); gpr_log(GPR_INFO, "---------client stats--------");
gpr_log( gpr_log(

@ -34,7 +34,6 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/surface/init.h"
#include "test/core/end2end/data/ssl_test_data.h" #include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/cmdline.h" #include "test/core/util/cmdline.h"
#include "test/core/util/memory_counters.h" #include "test/core/util/memory_counters.h"
@ -319,8 +318,7 @@ int main(int argc, char** argv) {
grpc_server_destroy(server); grpc_server_destroy(server);
grpc_completion_queue_destroy(cq); grpc_completion_queue_destroy(cq);
grpc_shutdown(); grpc_shutdown_blocking();
grpc_maybe_wait_for_async_shutdown();
grpc_memory_counters_destroy(); grpc_memory_counters_destroy();
return 0; return 0;
} }

@ -36,6 +36,16 @@ static void test(int rounds) {
grpc_maybe_wait_for_async_shutdown(); grpc_maybe_wait_for_async_shutdown();
} }
static void test_blocking(int rounds) {
int i;
for (i = 0; i < rounds; i++) {
grpc_init();
}
for (i = 0; i < rounds; i++) {
grpc_shutdown_blocking();
}
}
static void test_mixed(void) { static void test_mixed(void) {
grpc_init(); grpc_init();
grpc_init(); grpc_init();
@ -53,8 +63,7 @@ static void test_plugin() {
grpc_register_plugin(plugin_init, plugin_destroy); grpc_register_plugin(plugin_init, plugin_destroy);
grpc_init(); grpc_init();
GPR_ASSERT(g_flag == 1); GPR_ASSERT(g_flag == 1);
grpc_shutdown(); grpc_shutdown_blocking();
grpc_maybe_wait_for_async_shutdown();
GPR_ASSERT(g_flag == 2); GPR_ASSERT(g_flag == 2);
} }
@ -71,6 +80,9 @@ int main(int argc, char** argv) {
test(1); test(1);
test(2); test(2);
test(3); test(3);
test_blocking(1);
test_blocking(2);
test_blocking(3);
test_mixed(); test_mixed();
test_plugin(); test_plugin();
test_repeatedly(); test_repeatedly();

@ -78,7 +78,7 @@ int main(int argc, char **argv) {
printf("%lx", (unsigned long) grpc_init); printf("%lx", (unsigned long) grpc_init);
printf("%lx", (unsigned long) grpc_shutdown); printf("%lx", (unsigned long) grpc_shutdown);
printf("%lx", (unsigned long) grpc_is_initialized); printf("%lx", (unsigned long) grpc_is_initialized);
printf("%lx", (unsigned long) grpc_maybe_wait_for_async_shutdown); printf("%lx", (unsigned long) grpc_shutdown_blocking);
printf("%lx", (unsigned long) grpc_version_string); printf("%lx", (unsigned long) grpc_version_string);
printf("%lx", (unsigned long) grpc_g_stands_for); printf("%lx", (unsigned long) grpc_g_stands_for);
printf("%lx", (unsigned long) grpc_completion_queue_factory_lookup); printf("%lx", (unsigned long) grpc_completion_queue_factory_lookup);

@ -34,7 +34,6 @@
#include "src/core/lib/http/httpcli.h" #include "src/core/lib/http/httpcli.h"
#include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/surface/init.h"
#include "test/core/util/port_server_client.h" #include "test/core/util/port_server_client.h"
static int* chosen_ports = nullptr; static int* chosen_ports = nullptr;
@ -67,8 +66,7 @@ static void free_chosen_ports(void) {
for (i = 0; i < num_chosen_ports; i++) { for (i = 0; i < num_chosen_ports; i++) {
grpc_free_port_using_server(chosen_ports[i]); grpc_free_port_using_server(chosen_ports[i]);
} }
grpc_shutdown(); grpc_shutdown_blocking();
grpc_maybe_wait_for_async_shutdown();
gpr_free(chosen_ports); gpr_free(chosen_ports);
} }

@ -25,7 +25,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>

@ -47,7 +47,6 @@
#include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/surface/init.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
@ -198,10 +197,7 @@ void VerifyLbAddrOutputs(const grpc_core::ServerAddressList addresses,
class AddressSortingTest : public ::testing::Test { class AddressSortingTest : public ::testing::Test {
protected: protected:
void SetUp() override { grpc_init(); } void SetUp() override { grpc_init(); }
void TearDown() override { void TearDown() override { grpc_shutdown_blocking(); }
grpc_shutdown();
grpc_maybe_wait_for_async_shutdown();
}
}; };
/* Tests for rule 1 */ /* Tests for rule 1 */

Loading…
Cancel
Save