|
|
@ -18,6 +18,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <grpc/support/port_platform.h> |
|
|
|
#include <grpc/support/port_platform.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "src/core/lib/surface/init.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <limits.h> |
|
|
|
#include <limits.h> |
|
|
|
#include <memory.h> |
|
|
|
#include <memory.h> |
|
|
|
|
|
|
|
|
|
|
@ -26,6 +28,7 @@ |
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
#include <grpc/support/log.h> |
|
|
|
#include <grpc/support/log.h> |
|
|
|
#include <grpc/support/time.h> |
|
|
|
#include <grpc/support/time.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "src/core/lib/channel/channel_stack.h" |
|
|
|
#include "src/core/lib/channel/channel_stack.h" |
|
|
|
#include "src/core/lib/channel/channelz_registry.h" |
|
|
|
#include "src/core/lib/channel/channelz_registry.h" |
|
|
|
#include "src/core/lib/channel/connected_channel.h" |
|
|
|
#include "src/core/lib/channel/connected_channel.h" |
|
|
@ -37,6 +40,7 @@ |
|
|
|
#include "src/core/lib/http/parser.h" |
|
|
|
#include "src/core/lib/http/parser.h" |
|
|
|
#include "src/core/lib/iomgr/call_combiner.h" |
|
|
|
#include "src/core/lib/iomgr/call_combiner.h" |
|
|
|
#include "src/core/lib/iomgr/combiner.h" |
|
|
|
#include "src/core/lib/iomgr/combiner.h" |
|
|
|
|
|
|
|
#include "src/core/lib/iomgr/exec_ctx.h" |
|
|
|
#include "src/core/lib/iomgr/executor.h" |
|
|
|
#include "src/core/lib/iomgr/executor.h" |
|
|
|
#include "src/core/lib/iomgr/iomgr.h" |
|
|
|
#include "src/core/lib/iomgr/iomgr.h" |
|
|
|
#include "src/core/lib/iomgr/resource_quota.h" |
|
|
|
#include "src/core/lib/iomgr/resource_quota.h" |
|
|
@ -47,7 +51,6 @@ |
|
|
|
#include "src/core/lib/surface/call.h" |
|
|
|
#include "src/core/lib/surface/call.h" |
|
|
|
#include "src/core/lib/surface/channel_init.h" |
|
|
|
#include "src/core/lib/surface/channel_init.h" |
|
|
|
#include "src/core/lib/surface/completion_queue.h" |
|
|
|
#include "src/core/lib/surface/completion_queue.h" |
|
|
|
#include "src/core/lib/surface/init.h" |
|
|
|
|
|
|
|
#include "src/core/lib/surface/lame_client.h" |
|
|
|
#include "src/core/lib/surface/lame_client.h" |
|
|
|
#include "src/core/lib/surface/server.h" |
|
|
|
#include "src/core/lib/surface/server.h" |
|
|
|
#include "src/core/lib/transport/bdp_estimator.h" |
|
|
|
#include "src/core/lib/transport/bdp_estimator.h" |
|
|
@ -211,17 +214,31 @@ void grpc_shutdown_internal(void* /*ignored*/) { |
|
|
|
void grpc_shutdown(void) { |
|
|
|
void grpc_shutdown(void) { |
|
|
|
GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); |
|
|
|
GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); |
|
|
|
grpc_core::MutexLock lock(&g_init_mu); |
|
|
|
grpc_core::MutexLock lock(&g_init_mu); |
|
|
|
|
|
|
|
|
|
|
|
if (--g_initializations == 0) { |
|
|
|
if (--g_initializations == 0) { |
|
|
|
g_initializations++; |
|
|
|
grpc_core::ApplicationCallbackExecCtx* acec = |
|
|
|
|
|
|
|
grpc_core::ApplicationCallbackExecCtx::Get(); |
|
|
|
|
|
|
|
if (!grpc_iomgr_is_any_background_poller_thread() && |
|
|
|
|
|
|
|
(acec == nullptr || |
|
|
|
|
|
|
|
(acec->Flags() & GRPC_APP_CALLBACK_EXEC_CTX_FLAG_IS_INTERNAL_THREAD) == |
|
|
|
|
|
|
|
0)) { |
|
|
|
|
|
|
|
// just run clean-up when this is called on non-executor thread.
|
|
|
|
|
|
|
|
gpr_log(GPR_DEBUG, "grpc_shutdown starts clean-up now"); |
|
|
|
g_shutting_down = true; |
|
|
|
g_shutting_down = true; |
|
|
|
|
|
|
|
grpc_shutdown_internal_locked(); |
|
|
|
|
|
|
|
} else { |
|
|
|
// spawn a detached thread to do the actual clean up in case we are
|
|
|
|
// spawn a detached thread to do the actual clean up in case we are
|
|
|
|
// currently in an executor thread.
|
|
|
|
// currently in an executor thread.
|
|
|
|
|
|
|
|
gpr_log(GPR_DEBUG, "grpc_shutdown spawns clean-up thread"); |
|
|
|
|
|
|
|
g_initializations++; |
|
|
|
|
|
|
|
g_shutting_down = true; |
|
|
|
grpc_core::Thread cleanup_thread( |
|
|
|
grpc_core::Thread cleanup_thread( |
|
|
|
"grpc_shutdown", grpc_shutdown_internal, nullptr, nullptr, |
|
|
|
"grpc_shutdown", grpc_shutdown_internal, nullptr, nullptr, |
|
|
|
grpc_core::Thread::Options().set_joinable(false).set_tracked(false)); |
|
|
|
grpc_core::Thread::Options().set_joinable(false).set_tracked(false)); |
|
|
|
cleanup_thread.Start(); |
|
|
|
cleanup_thread.Start(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_shutdown_blocking(void) { |
|
|
|
void grpc_shutdown_blocking(void) { |
|
|
|
GRPC_API_TRACE("grpc_shutdown_blocking(void)", 0, ()); |
|
|
|
GRPC_API_TRACE("grpc_shutdown_blocking(void)", 0, ()); |
|
|
|