|
|
|
@ -34,44 +34,49 @@ |
|
|
|
|
#include "src/core/lib/support/env.h" |
|
|
|
|
#include "src/core/lib/support/fork.h" |
|
|
|
|
#include "src/core/lib/support/thd_internal.h" |
|
|
|
|
#include "src/core/lib/surface/init.h" |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK |
|
|
|
|
* AROUND VERY SPECIFIC USE CASES. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
int grpc_prefork() { |
|
|
|
|
void grpc_prefork() { |
|
|
|
|
if (!grpc_fork_support_enabled()) { |
|
|
|
|
gpr_log(GPR_ERROR, |
|
|
|
|
"Fork support not enabled; try running with the " |
|
|
|
|
"environment variable GRPC_ENABLE_FORK_SUPPORT=1"); |
|
|
|
|
return 0; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_timer_manager_set_threading(false); |
|
|
|
|
grpc_executor_set_threading(&exec_ctx, false); |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
if (!gpr_await_threads( |
|
|
|
|
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), |
|
|
|
|
gpr_time_from_seconds(3, GPR_TIMESPAN)))) { |
|
|
|
|
gpr_log(GPR_ERROR, "gRPC thread still active! Cannot fork!"); |
|
|
|
|
return 0; |
|
|
|
|
if (grpc_is_initialized()) { |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_timer_manager_set_threading(false); |
|
|
|
|
grpc_executor_set_threading(&exec_ctx, false); |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
if (!gpr_await_threads( |
|
|
|
|
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), |
|
|
|
|
gpr_time_from_seconds(3, GPR_TIMESPAN)))) { |
|
|
|
|
gpr_log(GPR_ERROR, "gRPC thread still active! Cannot fork!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void grpc_postfork_parent() { |
|
|
|
|
grpc_timer_manager_set_threading(true); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_executor_set_threading(&exec_ctx, true); |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
if (grpc_is_initialized()) { |
|
|
|
|
grpc_timer_manager_set_threading(true); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_executor_set_threading(&exec_ctx, true); |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void grpc_postfork_child() { |
|
|
|
|
grpc_timer_manager_set_threading(true); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_executor_set_threading(&exec_ctx, true); |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
if (grpc_is_initialized()) { |
|
|
|
|
grpc_timer_manager_set_threading(true); |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
grpc_executor_set_threading(&exec_ctx, true); |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void grpc_fork_handlers_auto_register() { |
|
|
|
|