pull/14647/head
kpayson64 7 years ago
parent 38ab21ee09
commit 701e70da07
  1. 4
      BUILD
  2. 4
      CMakeLists.txt
  3. 6
      Makefile
  4. 6
      build.yaml
  5. 2
      config.m4
  6. 2
      config.w32
  7. 4
      gRPC-C++.podspec
  8. 6
      gRPC-Core.podspec
  9. 4
      grpc.gemspec
  10. 2
      grpc.gyp
  11. 4
      package.xml
  12. 153
      src/core/lib/gprpp/fork.cc
  13. 41
      src/core/lib/gprpp/fork.h
  14. 8
      src/core/lib/gprpp/thd_posix.cc
  15. 8
      src/core/lib/iomgr/exec_ctx.h
  16. 14
      src/core/lib/iomgr/fork_posix.cc
  17. 7
      src/core/lib/surface/init.cc
  18. 2
      src/python/grpcio/grpc_core_dependencies.py
  19. 96
      test/core/gprpp/fork_test.cc
  20. 2
      tools/doxygen/Doxyfile.c++.internal
  21. 4
      tools/doxygen/Doxyfile.core.internal
  22. 8
      tools/run_tests/generated/sources_and_headers.json

@ -511,7 +511,6 @@ grpc_cc_library(
"src/core/lib/gpr/env_linux.cc", "src/core/lib/gpr/env_linux.cc",
"src/core/lib/gpr/env_posix.cc", "src/core/lib/gpr/env_posix.cc",
"src/core/lib/gpr/env_windows.cc", "src/core/lib/gpr/env_windows.cc",
"src/core/lib/gpr/fork.cc",
"src/core/lib/gpr/host_port.cc", "src/core/lib/gpr/host_port.cc",
"src/core/lib/gpr/log.cc", "src/core/lib/gpr/log.cc",
"src/core/lib/gpr/log_android.cc", "src/core/lib/gpr/log_android.cc",
@ -536,6 +535,7 @@ grpc_cc_library(
"src/core/lib/gpr/tmpfile_posix.cc", "src/core/lib/gpr/tmpfile_posix.cc",
"src/core/lib/gpr/tmpfile_windows.cc", "src/core/lib/gpr/tmpfile_windows.cc",
"src/core/lib/gpr/wrap_memcpy.cc", "src/core/lib/gpr/wrap_memcpy.cc",
"src/core/lib/gprpp/fork.cc",
"src/core/lib/gprpp/thd_posix.cc", "src/core/lib/gprpp/thd_posix.cc",
"src/core/lib/gprpp/thd_windows.cc", "src/core/lib/gprpp/thd_windows.cc",
"src/core/lib/profiling/basic_timers.cc", "src/core/lib/profiling/basic_timers.cc",
@ -544,7 +544,6 @@ grpc_cc_library(
hdrs = [ hdrs = [
"src/core/lib/gpr/arena.h", "src/core/lib/gpr/arena.h",
"src/core/lib/gpr/env.h", "src/core/lib/gpr/env.h",
"src/core/lib/gpr/fork.h",
"src/core/lib/gpr/host_port.h", "src/core/lib/gpr/host_port.h",
"src/core/lib/gpr/mpscq.h", "src/core/lib/gpr/mpscq.h",
"src/core/lib/gpr/murmur_hash.h", "src/core/lib/gpr/murmur_hash.h",
@ -559,6 +558,7 @@ grpc_cc_library(
"src/core/lib/gpr/tmpfile.h", "src/core/lib/gpr/tmpfile.h",
"src/core/lib/gpr/useful.h", "src/core/lib/gpr/useful.h",
"src/core/lib/gprpp/abstract.h", "src/core/lib/gprpp/abstract.h",
"src/core/lib/gprpp/fork.h",
"src/core/lib/gprpp/manual_constructor.h", "src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/memory.h", "src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/thd.h", "src/core/lib/gprpp/thd.h",

@ -703,7 +703,6 @@ add_library(gpr
src/core/lib/gpr/env_linux.cc src/core/lib/gpr/env_linux.cc
src/core/lib/gpr/env_posix.cc src/core/lib/gpr/env_posix.cc
src/core/lib/gpr/env_windows.cc src/core/lib/gpr/env_windows.cc
src/core/lib/gpr/fork.cc
src/core/lib/gpr/host_port.cc src/core/lib/gpr/host_port.cc
src/core/lib/gpr/log.cc src/core/lib/gpr/log.cc
src/core/lib/gpr/log_android.cc src/core/lib/gpr/log_android.cc
@ -728,6 +727,7 @@ add_library(gpr
src/core/lib/gpr/tmpfile_posix.cc src/core/lib/gpr/tmpfile_posix.cc
src/core/lib/gpr/tmpfile_windows.cc src/core/lib/gpr/tmpfile_windows.cc
src/core/lib/gpr/wrap_memcpy.cc src/core/lib/gpr/wrap_memcpy.cc
src/core/lib/gprpp/fork.cc
src/core/lib/gprpp/thd_posix.cc src/core/lib/gprpp/thd_posix.cc
src/core/lib/gprpp/thd_windows.cc src/core/lib/gprpp/thd_windows.cc
src/core/lib/profiling/basic_timers.cc src/core/lib/profiling/basic_timers.cc
@ -6161,7 +6161,7 @@ if (gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC)
add_executable(fork_test add_executable(fork_test
test/core/gpr/fork_test.cc test/core/gprpp/fork_test.cc
) )

@ -3035,7 +3035,6 @@ LIBGPR_SRC = \
src/core/lib/gpr/env_linux.cc \ src/core/lib/gpr/env_linux.cc \
src/core/lib/gpr/env_posix.cc \ src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \ src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/fork.cc \
src/core/lib/gpr/host_port.cc \ src/core/lib/gpr/host_port.cc \
src/core/lib/gpr/log.cc \ src/core/lib/gpr/log.cc \
src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_android.cc \
@ -3060,6 +3059,7 @@ LIBGPR_SRC = \
src/core/lib/gpr/tmpfile_posix.cc \ src/core/lib/gpr/tmpfile_posix.cc \
src/core/lib/gpr/tmpfile_windows.cc \ src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/wrap_memcpy.cc \ src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/thd_posix.cc \ src/core/lib/gprpp/thd_posix.cc \
src/core/lib/gprpp/thd_windows.cc \ src/core/lib/gprpp/thd_windows.cc \
src/core/lib/profiling/basic_timers.cc \ src/core/lib/profiling/basic_timers.cc \
@ -10959,7 +10959,7 @@ endif
FORK_TEST_SRC = \ FORK_TEST_SRC = \
test/core/gpr/fork_test.cc \ test/core/gprpp/fork_test.cc \
FORK_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(FORK_TEST_SRC)))) FORK_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(FORK_TEST_SRC))))
ifeq ($(NO_SECURE),true) ifeq ($(NO_SECURE),true)
@ -10979,7 +10979,7 @@ $(BINDIR)/$(CONFIG)/fork_test: $(FORK_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr_test
endif endif
$(OBJDIR)/$(CONFIG)/test/core/gpr/fork_test.o: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(OBJDIR)/$(CONFIG)/test/core/gprpp/fork_test.o: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_fork_test: $(FORK_TEST_OBJS:.o=.dep) deps_fork_test: $(FORK_TEST_OBJS:.o=.dep)

@ -121,7 +121,6 @@ filegroups:
- src/core/lib/gpr/env_linux.cc - src/core/lib/gpr/env_linux.cc
- src/core/lib/gpr/env_posix.cc - src/core/lib/gpr/env_posix.cc
- src/core/lib/gpr/env_windows.cc - src/core/lib/gpr/env_windows.cc
- src/core/lib/gpr/fork.cc
- src/core/lib/gpr/host_port.cc - src/core/lib/gpr/host_port.cc
- src/core/lib/gpr/log.cc - src/core/lib/gpr/log.cc
- src/core/lib/gpr/log_android.cc - src/core/lib/gpr/log_android.cc
@ -146,6 +145,7 @@ filegroups:
- src/core/lib/gpr/tmpfile_posix.cc - src/core/lib/gpr/tmpfile_posix.cc
- src/core/lib/gpr/tmpfile_windows.cc - src/core/lib/gpr/tmpfile_windows.cc
- src/core/lib/gpr/wrap_memcpy.cc - src/core/lib/gpr/wrap_memcpy.cc
- src/core/lib/gprpp/fork.cc
- src/core/lib/gprpp/thd_posix.cc - src/core/lib/gprpp/thd_posix.cc
- src/core/lib/gprpp/thd_windows.cc - src/core/lib/gprpp/thd_windows.cc
- src/core/lib/profiling/basic_timers.cc - src/core/lib/profiling/basic_timers.cc
@ -174,7 +174,6 @@ filegroups:
headers: headers:
- src/core/lib/gpr/arena.h - src/core/lib/gpr/arena.h
- src/core/lib/gpr/env.h - src/core/lib/gpr/env.h
- src/core/lib/gpr/fork.h
- src/core/lib/gpr/host_port.h - src/core/lib/gpr/host_port.h
- src/core/lib/gpr/mpscq.h - src/core/lib/gpr/mpscq.h
- src/core/lib/gpr/murmur_hash.h - src/core/lib/gpr/murmur_hash.h
@ -192,6 +191,7 @@ filegroups:
- src/core/lib/gprpp/atomic.h - src/core/lib/gprpp/atomic.h
- src/core/lib/gprpp/atomic_with_atm.h - src/core/lib/gprpp/atomic_with_atm.h
- src/core/lib/gprpp/atomic_with_std.h - src/core/lib/gprpp/atomic_with_std.h
- src/core/lib/gprpp/fork.h
- src/core/lib/gprpp/manual_constructor.h - src/core/lib/gprpp/manual_constructor.h
- src/core/lib/gprpp/memory.h - src/core/lib/gprpp/memory.h
- src/core/lib/gprpp/thd.h - src/core/lib/gprpp/thd.h
@ -2320,7 +2320,7 @@ targets:
build: test build: test
language: c language: c
src: src:
- test/core/gpr/fork_test.cc - test/core/gprpp/fork_test.cc
deps: deps:
- gpr_test_util - gpr_test_util
- gpr - gpr

@ -49,7 +49,6 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gpr/env_linux.cc \ src/core/lib/gpr/env_linux.cc \
src/core/lib/gpr/env_posix.cc \ src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \ src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/fork.cc \
src/core/lib/gpr/host_port.cc \ src/core/lib/gpr/host_port.cc \
src/core/lib/gpr/log.cc \ src/core/lib/gpr/log.cc \
src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_android.cc \
@ -74,6 +73,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gpr/tmpfile_posix.cc \ src/core/lib/gpr/tmpfile_posix.cc \
src/core/lib/gpr/tmpfile_windows.cc \ src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/wrap_memcpy.cc \ src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/thd_posix.cc \ src/core/lib/gprpp/thd_posix.cc \
src/core/lib/gprpp/thd_windows.cc \ src/core/lib/gprpp/thd_windows.cc \
src/core/lib/profiling/basic_timers.cc \ src/core/lib/profiling/basic_timers.cc \

@ -26,7 +26,6 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\env_linux.cc " + "src\\core\\lib\\gpr\\env_linux.cc " +
"src\\core\\lib\\gpr\\env_posix.cc " + "src\\core\\lib\\gpr\\env_posix.cc " +
"src\\core\\lib\\gpr\\env_windows.cc " + "src\\core\\lib\\gpr\\env_windows.cc " +
"src\\core\\lib\\gpr\\fork.cc " +
"src\\core\\lib\\gpr\\host_port.cc " + "src\\core\\lib\\gpr\\host_port.cc " +
"src\\core\\lib\\gpr\\log.cc " + "src\\core\\lib\\gpr\\log.cc " +
"src\\core\\lib\\gpr\\log_android.cc " + "src\\core\\lib\\gpr\\log_android.cc " +
@ -51,6 +50,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\tmpfile_posix.cc " + "src\\core\\lib\\gpr\\tmpfile_posix.cc " +
"src\\core\\lib\\gpr\\tmpfile_windows.cc " + "src\\core\\lib\\gpr\\tmpfile_windows.cc " +
"src\\core\\lib\\gpr\\wrap_memcpy.cc " + "src\\core\\lib\\gpr\\wrap_memcpy.cc " +
"src\\core\\lib\\gprpp\\fork.cc " +
"src\\core\\lib\\gprpp\\thd_posix.cc " + "src\\core\\lib\\gprpp\\thd_posix.cc " +
"src\\core\\lib\\gprpp\\thd_windows.cc " + "src\\core\\lib\\gprpp\\thd_windows.cc " +
"src\\core\\lib\\profiling\\basic_timers.cc " + "src\\core\\lib\\profiling\\basic_timers.cc " +

@ -213,7 +213,6 @@ Pod::Spec.new do |s|
'src/cpp/codegen/codegen_init.cc', 'src/cpp/codegen/codegen_init.cc',
'src/core/lib/gpr/arena.h', 'src/core/lib/gpr/arena.h',
'src/core/lib/gpr/env.h', 'src/core/lib/gpr/env.h',
'src/core/lib/gpr/fork.h',
'src/core/lib/gpr/host_port.h', 'src/core/lib/gpr/host_port.h',
'src/core/lib/gpr/mpscq.h', 'src/core/lib/gpr/mpscq.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
@ -231,6 +230,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/atomic_with_atm.h', 'src/core/lib/gprpp/atomic_with_atm.h',
'src/core/lib/gprpp/atomic_with_std.h', 'src/core/lib/gprpp/atomic_with_std.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/manual_constructor.h', 'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/thd.h', 'src/core/lib/gprpp/thd.h',
@ -495,7 +495,6 @@ Pod::Spec.new do |s|
'src/cpp/thread_manager/thread_manager.h', 'src/cpp/thread_manager/thread_manager.h',
'src/core/lib/gpr/arena.h', 'src/core/lib/gpr/arena.h',
'src/core/lib/gpr/env.h', 'src/core/lib/gpr/env.h',
'src/core/lib/gpr/fork.h',
'src/core/lib/gpr/host_port.h', 'src/core/lib/gpr/host_port.h',
'src/core/lib/gpr/mpscq.h', 'src/core/lib/gpr/mpscq.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
@ -513,6 +512,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/atomic_with_atm.h', 'src/core/lib/gprpp/atomic_with_atm.h',
'src/core/lib/gprpp/atomic_with_std.h', 'src/core/lib/gprpp/atomic_with_std.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/manual_constructor.h', 'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/thd.h', 'src/core/lib/gprpp/thd.h',

@ -185,7 +185,6 @@ Pod::Spec.new do |s|
# To save you from scrolling, this is the last part of the podspec. # To save you from scrolling, this is the last part of the podspec.
ss.source_files = 'src/core/lib/gpr/arena.h', ss.source_files = 'src/core/lib/gpr/arena.h',
'src/core/lib/gpr/env.h', 'src/core/lib/gpr/env.h',
'src/core/lib/gpr/fork.h',
'src/core/lib/gpr/host_port.h', 'src/core/lib/gpr/host_port.h',
'src/core/lib/gpr/mpscq.h', 'src/core/lib/gpr/mpscq.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
@ -203,6 +202,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/atomic_with_atm.h', 'src/core/lib/gprpp/atomic_with_atm.h',
'src/core/lib/gprpp/atomic_with_std.h', 'src/core/lib/gprpp/atomic_with_std.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/manual_constructor.h', 'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/thd.h', 'src/core/lib/gprpp/thd.h',
@ -217,7 +217,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/env_linux.cc', 'src/core/lib/gpr/env_linux.cc',
'src/core/lib/gpr/env_posix.cc', 'src/core/lib/gpr/env_posix.cc',
'src/core/lib/gpr/env_windows.cc', 'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/fork.cc',
'src/core/lib/gpr/host_port.cc', 'src/core/lib/gpr/host_port.cc',
'src/core/lib/gpr/log.cc', 'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_android.cc',
@ -242,6 +241,7 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/tmpfile_posix.cc', 'src/core/lib/gpr/tmpfile_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc', 'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/thd_posix.cc', 'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc', 'src/core/lib/gprpp/thd_windows.cc',
'src/core/lib/profiling/basic_timers.cc', 'src/core/lib/profiling/basic_timers.cc',
@ -778,7 +778,6 @@ Pod::Spec.new do |s|
ss.private_header_files = 'src/core/lib/gpr/arena.h', ss.private_header_files = 'src/core/lib/gpr/arena.h',
'src/core/lib/gpr/env.h', 'src/core/lib/gpr/env.h',
'src/core/lib/gpr/fork.h',
'src/core/lib/gpr/host_port.h', 'src/core/lib/gpr/host_port.h',
'src/core/lib/gpr/mpscq.h', 'src/core/lib/gpr/mpscq.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
@ -796,6 +795,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/atomic_with_atm.h', 'src/core/lib/gprpp/atomic_with_atm.h',
'src/core/lib/gprpp/atomic_with_std.h', 'src/core/lib/gprpp/atomic_with_std.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/manual_constructor.h', 'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/thd.h', 'src/core/lib/gprpp/thd.h',

@ -76,7 +76,6 @@ Gem::Specification.new do |s|
s.files += %w( include/grpc/impl/codegen/sync_windows.h ) s.files += %w( include/grpc/impl/codegen/sync_windows.h )
s.files += %w( src/core/lib/gpr/arena.h ) s.files += %w( src/core/lib/gpr/arena.h )
s.files += %w( src/core/lib/gpr/env.h ) s.files += %w( src/core/lib/gpr/env.h )
s.files += %w( src/core/lib/gpr/fork.h )
s.files += %w( src/core/lib/gpr/host_port.h ) s.files += %w( src/core/lib/gpr/host_port.h )
s.files += %w( src/core/lib/gpr/mpscq.h ) s.files += %w( src/core/lib/gpr/mpscq.h )
s.files += %w( src/core/lib/gpr/murmur_hash.h ) s.files += %w( src/core/lib/gpr/murmur_hash.h )
@ -94,6 +93,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/atomic.h ) s.files += %w( src/core/lib/gprpp/atomic.h )
s.files += %w( src/core/lib/gprpp/atomic_with_atm.h ) s.files += %w( src/core/lib/gprpp/atomic_with_atm.h )
s.files += %w( src/core/lib/gprpp/atomic_with_std.h ) s.files += %w( src/core/lib/gprpp/atomic_with_std.h )
s.files += %w( src/core/lib/gprpp/fork.h )
s.files += %w( src/core/lib/gprpp/manual_constructor.h ) s.files += %w( src/core/lib/gprpp/manual_constructor.h )
s.files += %w( src/core/lib/gprpp/memory.h ) s.files += %w( src/core/lib/gprpp/memory.h )
s.files += %w( src/core/lib/gprpp/thd.h ) s.files += %w( src/core/lib/gprpp/thd.h )
@ -108,7 +108,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/env_linux.cc ) s.files += %w( src/core/lib/gpr/env_linux.cc )
s.files += %w( src/core/lib/gpr/env_posix.cc ) s.files += %w( src/core/lib/gpr/env_posix.cc )
s.files += %w( src/core/lib/gpr/env_windows.cc ) s.files += %w( src/core/lib/gpr/env_windows.cc )
s.files += %w( src/core/lib/gpr/fork.cc )
s.files += %w( src/core/lib/gpr/host_port.cc ) s.files += %w( src/core/lib/gpr/host_port.cc )
s.files += %w( src/core/lib/gpr/log.cc ) s.files += %w( src/core/lib/gpr/log.cc )
s.files += %w( src/core/lib/gpr/log_android.cc ) s.files += %w( src/core/lib/gpr/log_android.cc )
@ -133,6 +132,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/tmpfile_posix.cc ) s.files += %w( src/core/lib/gpr/tmpfile_posix.cc )
s.files += %w( src/core/lib/gpr/tmpfile_windows.cc ) s.files += %w( src/core/lib/gpr/tmpfile_windows.cc )
s.files += %w( src/core/lib/gpr/wrap_memcpy.cc ) s.files += %w( src/core/lib/gpr/wrap_memcpy.cc )
s.files += %w( src/core/lib/gprpp/fork.cc )
s.files += %w( src/core/lib/gprpp/thd_posix.cc ) s.files += %w( src/core/lib/gprpp/thd_posix.cc )
s.files += %w( src/core/lib/gprpp/thd_windows.cc ) s.files += %w( src/core/lib/gprpp/thd_windows.cc )
s.files += %w( src/core/lib/profiling/basic_timers.cc ) s.files += %w( src/core/lib/profiling/basic_timers.cc )

@ -182,7 +182,6 @@
'src/core/lib/gpr/env_linux.cc', 'src/core/lib/gpr/env_linux.cc',
'src/core/lib/gpr/env_posix.cc', 'src/core/lib/gpr/env_posix.cc',
'src/core/lib/gpr/env_windows.cc', 'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/fork.cc',
'src/core/lib/gpr/host_port.cc', 'src/core/lib/gpr/host_port.cc',
'src/core/lib/gpr/log.cc', 'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_android.cc',
@ -207,6 +206,7 @@
'src/core/lib/gpr/tmpfile_posix.cc', 'src/core/lib/gpr/tmpfile_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc', 'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/thd_posix.cc', 'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc', 'src/core/lib/gprpp/thd_windows.cc',
'src/core/lib/profiling/basic_timers.cc', 'src/core/lib/profiling/basic_timers.cc',

@ -83,7 +83,6 @@
<file baseinstalldir="/" name="include/grpc/impl/codegen/sync_windows.h" role="src" /> <file baseinstalldir="/" name="include/grpc/impl/codegen/sync_windows.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/arena.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/arena.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/env.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/fork.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/host_port.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/host_port.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/mpscq.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/mpscq.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/murmur_hash.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/murmur_hash.h" role="src" />
@ -101,6 +100,7 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/atomic.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/atomic.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/atomic_with_atm.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/atomic_with_atm.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/atomic_with_std.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/atomic_with_std.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/manual_constructor.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/manual_constructor.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/memory.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/memory.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/thd.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/thd.h" role="src" />
@ -115,7 +115,6 @@
<file baseinstalldir="/" name="src/core/lib/gpr/env_linux.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/env_linux.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env_posix.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/env_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env_windows.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/env_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/fork.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/host_port.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/host_port.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_android.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log_android.cc" role="src" />
@ -140,6 +139,7 @@
<file baseinstalldir="/" name="src/core/lib/gpr/tmpfile_posix.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/tmpfile_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/tmpfile_windows.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/tmpfile_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/wrap_memcpy.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/wrap_memcpy.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/thd_posix.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/thd_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/thd_windows.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/thd_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/profiling/basic_timers.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/profiling/basic_timers.cc" role="src" />

@ -18,7 +18,7 @@
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include "src/core/lib/gpr/fork.h" #include "src/core/lib/gprpp/fork.h"
#include <string.h> #include <string.h>
@ -28,12 +28,15 @@
#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
/* /*
* NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK * NOTE: FORKING IS NOT GENERALLY SUPPORTED, THIS IS ONLY INTENDED TO WORK
* AROUND VERY SPECIFIC USE CASES. * AROUND VERY SPECIFIC USE CASES.
*/ */
namespace grpc_core {
namespace internal {
// The exec_ctx_count has 2 modes, blocked and unblocked. // The exec_ctx_count has 2 modes, blocked and unblocked.
// When unblocked, the count is 2-indexed; exec_ctx_count=2 indicates // When unblocked, the count is 2-indexed; exec_ctx_count=2 indicates
// 0 active ExecCtxs, exex_ctx_count=3 indicates 1 active ExecCtxs... // 0 active ExecCtxs, exex_ctx_count=3 indicates 1 active ExecCtxs...
@ -45,16 +48,15 @@
#define BLOCKED(n) (n) #define BLOCKED(n) (n)
class ExecCtxState { class ExecCtxState {
public: public:
ExecCtxState() : fork_complete_(true) { ExecCtxState() : fork_complete_(true) {
gpr_mu_init(&mu_); gpr_mu_init(&mu_);
gpr_cv_init(&cv_); gpr_cv_init(&cv_);
gpr_atm_no_barrier_store(&count_, UNBLOCKED(0)); gpr_atm_no_barrier_store(&count_, UNBLOCKED(0));
} }
void IncExecCtxCount() { void IncExecCtxCount() {
intptr_t count = static_cast<intptr_t>( intptr_t count = static_cast<intptr_t>(gpr_atm_no_barrier_load(&count_));
gpr_atm_no_barrier_load(&count_));
while (true) { while (true) {
if (count <= BLOCKED(1)) { if (count <= BLOCKED(1)) {
// This only occurs if we are trying to fork. Wait until the fork() // This only occurs if we are trying to fork. Wait until the fork()
@ -62,27 +64,22 @@ class ExecCtxState {
gpr_mu_lock(&mu_); gpr_mu_lock(&mu_);
if (gpr_atm_no_barrier_load(&count_) <= BLOCKED(1)) { if (gpr_atm_no_barrier_load(&count_) <= BLOCKED(1)) {
while (!fork_complete_) { while (!fork_complete_) {
gpr_cv_wait(&cv_, &mu_, gpr_cv_wait(&cv_, &mu_, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_inf_future(GPR_CLOCK_REALTIME));
} }
} }
gpr_mu_unlock(&mu_); gpr_mu_unlock(&mu_);
} else if (gpr_atm_no_barrier_cas(&count_, count, } else if (gpr_atm_no_barrier_cas(&count_, count, count + 1)) {
count + 1)) {
break; break;
} }
count = gpr_atm_no_barrier_load(&count_); count = gpr_atm_no_barrier_load(&count_);
} }
} }
void DecExecCtxCount() { void DecExecCtxCount() { gpr_atm_no_barrier_fetch_add(&count_, -1); }
gpr_atm_no_barrier_fetch_add(&count_, -1);
}
bool BlockExecCtx() { bool BlockExecCtx() {
// Assumes there is an active ExecCtx when this function is called // Assumes there is an active ExecCtx when this function is called
if (gpr_atm_no_barrier_cas(&count_, UNBLOCKED(1), if (gpr_atm_no_barrier_cas(&count_, UNBLOCKED(1), BLOCKED(1))) {
BLOCKED(1))) {
fork_complete_ = false; fork_complete_ = false;
return true; return true;
} }
@ -94,21 +91,27 @@ class ExecCtxState {
gpr_atm_no_barrier_store(&count_, UNBLOCKED(0)); gpr_atm_no_barrier_store(&count_, UNBLOCKED(0));
fork_complete_ = true; fork_complete_ = true;
gpr_cv_broadcast(&cv_); gpr_cv_broadcast(&cv_);
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&mu_);
} }
void ~ExecCtxState() { ~ExecCtxState() {
gpr_mu_destroy(&mu_); gpr_mu_destroy(&mu_);
gpr_cv_destroy(&cv_); gpr_cv_destroy(&cv_);
} }
}
private:
bool fork_complete_;
gpr_mu mu_;
gpr_cv cv_;
gpr_atm count_;
};
class ThreadState { class ThreadState {
public: public:
ThreadState() : awaiting_threads_(false), threads_done_(false), count_(0) { ThreadState() : awaiting_threads_(false), threads_done_(false), count_(0) {
gpr_mu_init(&mu_); gpr_mu_init(&mu_);
gpr_cv_init(&cv_); gpr_cv_init(&cv_);
} }
void IncThreadCount() { void IncThreadCount() {
gpr_mu_lock(&mu_); gpr_mu_lock(&mu_);
@ -120,7 +123,7 @@ class ThreadState {
gpr_mu_lock(&mu_); gpr_mu_lock(&mu_);
count_--; count_--;
if (awaiting_threads_ && count_ == 0) { if (awaiting_threads_ && count_ == 0) {
threads_done = true; threads_done_ = true;
gpr_cv_signal(&cv_); gpr_cv_signal(&cv_);
} }
gpr_mu_unlock(&mu_); gpr_mu_unlock(&mu_);
@ -130,8 +133,7 @@ class ThreadState {
awaiting_threads_ = true; awaiting_threads_ = true;
threads_done_ = (count_ == 0); threads_done_ = (count_ == 0);
while (!threads_done_) { while (!threads_done_) {
gpr_cv_wait(&cv_, &mu_, gpr_cv_wait(&cv_, &mu_, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_inf_future(GPR_CLOCK_REALTIME));
} }
awaiting_threads_ = true; awaiting_threads_ = true;
gpr_mu_unlock(&mu_); gpr_mu_unlock(&mu_);
@ -141,13 +143,22 @@ class ThreadState {
gpr_mu_destroy(&mu_); gpr_mu_destroy(&mu_);
gpr_cv_destroy(&cv_); gpr_cv_destroy(&cv_);
} }
}
static void Fork::GlobalInit() { private:
bool awaiting_threads_;
bool threads_done_;
gpr_mu mu_;
gpr_cv cv_;
int count_;
};
} // namespace
void Fork::GlobalInit() {
#ifdef GRPC_ENABLE_FORK_SUPPORT #ifdef GRPC_ENABLE_FORK_SUPPORT
bool supportEnabled_ = true; supportEnabled_ = true;
#else #else
bool supportEnabled_ = false; supportEnabled_ = false;
#endif #endif
bool env_var_set = false; bool env_var_set = false;
char* env = gpr_getenv("GRPC_ENABLE_FORK_SUPPORT"); char* env = gpr_getenv("GRPC_ENABLE_FORK_SUPPORT");
@ -178,62 +189,52 @@ static void Fork::GlobalInit() {
supportEnabled_ = (overrideEnabled_ == 1); supportEnabled_ = (overrideEnabled_ == 1);
} }
if (supportEnabled_) { if (supportEnabled_) {
execCtxState_ = grpc_core::New<ExecCtxState>(); execCtxState_ = grpc_core::New<internal::ExecCtxState>();
threadState_ = grpc_core::New<ThreadState>(); threadState_ = grpc_core::New<internal::ThreadState>();
} }
} }
static void Fork::GlobalShutdown() { void Fork::GlobalShutdown() {
if (supportEnabled_) { if (supportEnabled_) {
grpc_core::Delete(execCtxState_); grpc_core::Delete(execCtxState_);
grpc_core::Delete(threadState_); grpc_core::Delete(threadState_);
}
} }
}
static bool Fork::Enabled() { bool Fork::Enabled() { return supportEnabled_; }
return supportEnabled_;
}
// Testing Only // Testing Only
static void Fork::Enable(bool enable) { void Fork::Enable(bool enable) { overrideEnabled_ = enable ? 1 : 0; }
overrideEnabled_ = enable ? 1 : 0;
}
static void Fork::IncExecCtxCount() { void Fork::IncExecCtxCount() {
if(supportEnabled_) { if (supportEnabled_) {
execCtxState->IncExecCtxCount(); execCtxState_->IncExecCtxCount();
}
} }
}
static void Fork::DecExecCtxCount() { void Fork::DecExecCtxCount() {
if(supportEnabled_) { if (supportEnabled_) {
execCtxState->DecExecCtxCount(); execCtxState_->DecExecCtxCount();
}
} }
}
static bool Fork::BlockExecCtx() { bool Fork::BlockExecCtx() {
if(supportEnabled_) { if (supportEnabled_) {
return execCtxState->BlockExecCtx(); return execCtxState_->BlockExecCtx();
}
return false;
} }
return false;
}
static void Fork::AllowExecCtx() { void Fork::AllowExecCtx() { execCtxState_->AllowExecCtx(); }
execCtxState->AllowExecCtx();
}
static void Fork::IncThreadCount() { void Fork::IncThreadCount() { threadState_->IncThreadCount(); }
threadState->IncThreadCount();
}
static void Fork::DecThreadCount() { void Fork::DecThreadCount() { threadState_->DecThreadCount(); }
threadState_->DecThreadCount(); void Fork::AwaitThreads() { threadState_->AwaitThreads(); }
}
static void Fork::AwaitThreads() {
threadState_->AwaitThreads();
}
private: internal::ExecCtxState* Fork::execCtxState_ = nullptr;
ExecCtxState* execCtxState_; internal::ThreadState* Fork::threadState_ = nullptr;
ThreadState* threadState_; bool Fork::supportEnabled_ = false;
} int Fork::overrideEnabled_ = -1;
} // namespace grpc_core

@ -26,14 +26,12 @@
namespace grpc_core { namespace grpc_core {
namespace {
class ExecCtxState;
class ThreadState;
}
namespace internal { namespace internal {
class ExecCtxState;
class ThreadState;
} // namespace internal
class ForkSupport { class Fork {
public: public:
static void GlobalInit(); static void GlobalInit();
static void GlobalShutdown(); static void GlobalShutdown();
@ -43,40 +41,39 @@ class ForkSupport {
// Increment the count of active ExecCtxs. // Increment the count of active ExecCtxs.
// Will block until a pending fork is complete if one is in progress. // Will block until a pending fork is complete if one is in progress.
void IncExecCtxCount(); static void IncExecCtxCount();
// Decrement the count of active ExecCtxs // Decrement the count of active ExecCtxs
void DecExecCtxCount(); static void DecExecCtxCount();
// Check if there is a single active ExecCtx // Check if there is a single active ExecCtx
// (the one used to invoke this function). If there are more, // (the one used to invoke this function). If there are more,
// return false. Otherwise, return true and block creation of // return false. Otherwise, return true and block creation of
// more ExecCtx s until AlloWExecCtx() is called // more ExecCtx s until AlloWExecCtx() is called
// //
bool BlockExecCtx(); static bool BlockExecCtx();
void AllowExecCtx(); static void AllowExecCtx();
// Increment the count of active threads. // Increment the count of active threads.
void IncThreadCount(); static void IncThreadCount();
// Decrement the count of active threads. // Decrement the count of active threads.
void DecThreadCount(); static void DecThreadCount();
// Await all core threads to be joined. // Await all core threads to be joined.
void AwaitThreads(); static void AwaitThreads();
// Test only: overrides environment variables/compile flags // Test only: overrides environment variables/compile flags
// Must be called before grpc_init() // Must be called before grpc_init()
void Enable(bool enable); static void Enable(bool enable);
private: private:
static ExecCtxState* execCtxState_ = nullptr; static internal::ExecCtxState* execCtxState_;
static ThreadState* threadState_ = nullptr; static internal::ThreadState* threadState_;
static bool supportEnabled_ = false; static bool supportEnabled_;
static int overrideEnabled_ = -1; static int overrideEnabled_;
} };
} // namespace internal } // namespace grpc_core
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPR_FORK_H */ #endif /* GRPC_CORE_LIB_GPR_FORK_H */

@ -32,8 +32,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "src/core/lib/gpr/fork.h"
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/memory.h"
namespace grpc_core { namespace grpc_core {
@ -63,7 +63,7 @@ class ThreadInternalsPosix
info->body = thd_body; info->body = thd_body;
info->arg = arg; info->arg = arg;
info->name = thd_name; info->name = thd_name;
grpc_fork_inc_thd_count(); grpc_core::Fork::IncThreadCount();
GPR_ASSERT(pthread_attr_init(&attr) == 0); GPR_ASSERT(pthread_attr_init(&attr) == 0);
GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) == GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) ==
@ -98,7 +98,7 @@ class ThreadInternalsPosix
gpr_mu_unlock(&arg.thread->mu_); gpr_mu_unlock(&arg.thread->mu_);
(*arg.body)(arg.arg); (*arg.body)(arg.arg);
grpc_fork_dec_thd_count(); grpc_core::Fork::DecThreadCount();
return nullptr; return nullptr;
}, },
info) == 0); info) == 0);
@ -108,7 +108,7 @@ class ThreadInternalsPosix
if (!success) { if (!success) {
/* don't use gpr_free, as this was allocated using malloc (see above) */ /* don't use gpr_free, as this was allocated using malloc (see above) */
free(info); free(info);
grpc_fork_dec_thd_count(); grpc_core::Fork::DecThreadCount();
} }
}; };

@ -25,8 +25,8 @@
#include <grpc/support/cpu.h> #include <grpc/support/cpu.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/gpr/fork.h"
#include "src/core/lib/gpr/tls.h" #include "src/core/lib/gpr/tls.h"
#include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/closure.h"
typedef gpr_atm grpc_millis; typedef gpr_atm grpc_millis;
@ -78,13 +78,13 @@ class ExecCtx {
/** Default Constructor */ /** Default Constructor */
ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) { ExecCtx() : flags_(GRPC_EXEC_CTX_FLAG_IS_FINISHED) {
grpc_fork_inc_exec_ctx_count(); grpc_core::Fork::IncExecCtxCount();
Set(this); Set(this);
} }
/** Parameterised Constructor */ /** Parameterised Constructor */
ExecCtx(uintptr_t fl) : flags_(fl) { ExecCtx(uintptr_t fl) : flags_(fl) {
grpc_fork_inc_exec_ctx_count(); grpc_core::Fork::IncExecCtxCount();
Set(this); Set(this);
} }
@ -93,7 +93,7 @@ class ExecCtx {
flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; flags_ |= GRPC_EXEC_CTX_FLAG_IS_FINISHED;
Flush(); Flush();
Set(last_exec_ctx_); Set(last_exec_ctx_);
grpc_fork_dec_exec_ctx_count(); grpc_core::Fork::DecExecCtxCount();
} }
/** Disallow copy and assignment operators */ /** Disallow copy and assignment operators */

@ -28,7 +28,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/fork.h" #include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/executor.h"
@ -52,13 +52,13 @@ void grpc_prefork() {
if (!grpc_is_initialized()) { if (!grpc_is_initialized()) {
return; return;
} }
if (!grpc_fork_support_enabled()) { if (!grpc_core::Fork::Enabled()) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Fork support not enabled; try running with the " "Fork support not enabled; try running with the "
"environment variable GRPC_ENABLE_FORK_SUPPORT=1"); "environment variable GRPC_ENABLE_FORK_SUPPORT=1");
return; return;
} }
if (!grpc_fork_block_exec_ctx()) { if (!grpc_core::Fork::BlockExecCtx()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Other threads are currently calling into gRPC, skipping fork() " "Other threads are currently calling into gRPC, skipping fork() "
"handlers"); "handlers");
@ -67,13 +67,13 @@ void grpc_prefork() {
grpc_timer_manager_set_threading(false); grpc_timer_manager_set_threading(false);
grpc_executor_set_threading(false); grpc_executor_set_threading(false);
grpc_core::ExecCtx::Get()->Flush(); grpc_core::ExecCtx::Get()->Flush();
grpc_fork_await_thds(); grpc_core::Fork::AwaitThreads();
skipped_handler = false; skipped_handler = false;
} }
void grpc_postfork_parent() { void grpc_postfork_parent() {
if (!skipped_handler) { if (!skipped_handler) {
grpc_fork_allow_exec_ctx(); grpc_core::Fork::AllowExecCtx();
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
grpc_timer_manager_set_threading(true); grpc_timer_manager_set_threading(true);
grpc_executor_set_threading(true); grpc_executor_set_threading(true);
@ -82,7 +82,7 @@ void grpc_postfork_parent() {
void grpc_postfork_child() { void grpc_postfork_child() {
if (!skipped_handler) { if (!skipped_handler) {
grpc_fork_allow_exec_ctx(); grpc_core::Fork::AllowExecCtx();
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
grpc_timer_manager_set_threading(true); grpc_timer_manager_set_threading(true);
grpc_executor_set_threading(true); grpc_executor_set_threading(true);
@ -90,7 +90,7 @@ void grpc_postfork_child() {
} }
void grpc_fork_handlers_auto_register() { void grpc_fork_handlers_auto_register() {
if (grpc_fork_support_enabled() & !registered_handlers) { if (grpc_core::Fork::Enabled() & !registered_handlers) {
#ifdef GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK #ifdef GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK
pthread_atfork(grpc_prefork, grpc_postfork_parent, grpc_postfork_child); pthread_atfork(grpc_prefork, grpc_postfork_parent, grpc_postfork_child);
registered_handlers = true; registered_handlers = true;

@ -31,8 +31,7 @@
#include "src/core/lib/channel/handshaker_registry.h" #include "src/core/lib/channel/handshaker_registry.h"
#include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats.h"
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/fork.h" #include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/gprpp/thd.h"
#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"
@ -120,7 +119,7 @@ void grpc_init(void) {
gpr_mu_lock(&g_init_mu); gpr_mu_lock(&g_init_mu);
if (++g_initializations == 1) { if (++g_initializations == 1) {
grpc_fork_support_init(); grpc_core::Fork::GlobalInit();
grpc_fork_handlers_auto_register(); grpc_fork_handlers_auto_register();
gpr_time_init(); gpr_time_init();
grpc_stats_init(); grpc_stats_init();
@ -176,7 +175,7 @@ void grpc_shutdown(void) {
grpc_handshaker_factory_registry_shutdown(); grpc_handshaker_factory_registry_shutdown();
grpc_slice_intern_shutdown(); grpc_slice_intern_shutdown();
grpc_stats_shutdown(); grpc_stats_shutdown();
grpc_fork_support_destroy(); grpc_core::Fork::GlobalShutdown();
} }
grpc_core::ExecCtx::GlobalShutdown(); grpc_core::ExecCtx::GlobalShutdown();
} }

@ -25,7 +25,6 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/env_linux.cc', 'src/core/lib/gpr/env_linux.cc',
'src/core/lib/gpr/env_posix.cc', 'src/core/lib/gpr/env_posix.cc',
'src/core/lib/gpr/env_windows.cc', 'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/fork.cc',
'src/core/lib/gpr/host_port.cc', 'src/core/lib/gpr/host_port.cc',
'src/core/lib/gpr/log.cc', 'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_android.cc',
@ -50,6 +49,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/tmpfile_posix.cc', 'src/core/lib/gpr/tmpfile_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc', 'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/thd_posix.cc', 'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc', 'src/core/lib/gprpp/thd_windows.cc',
'src/core/lib/profiling/basic_timers.cc', 'src/core/lib/profiling/basic_timers.cc',

@ -16,30 +16,30 @@
* *
*/ */
#include "src/core/lib/gpr/fork.h" #include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
static void test_init() { static void test_init() {
GPR_ASSERT(!grpc_fork_support_enabled()); GPR_ASSERT(!grpc_core::Fork::Enabled());
// Default fork support (disabled) // Default fork support (disabled)
grpc_fork_support_init(); grpc_core::Fork::GlobalInit();
GPR_ASSERT(!grpc_fork_support_enabled()); GPR_ASSERT(!grpc_core::Fork::Enabled());
grpc_fork_support_destroy(); grpc_core::Fork::GlobalShutdown();
// Explicitly disabled fork support // Explicitly disabled fork support
grpc_enable_fork_support(false); grpc_core::Fork::Enable(false);
grpc_fork_support_init(); grpc_core::Fork::GlobalInit();
GPR_ASSERT(!grpc_fork_support_enabled()); GPR_ASSERT(!grpc_core::Fork::Enabled());
grpc_fork_support_destroy(); grpc_core::Fork::GlobalShutdown();
// Explicitly enabled fork support // Explicitly enabled fork support
grpc_enable_fork_support(true); grpc_core::Fork::Enable(true);
grpc_fork_support_init(); grpc_core::Fork::GlobalInit();
GPR_ASSERT(grpc_fork_support_enabled()); GPR_ASSERT(grpc_core::Fork::Enabled());
grpc_fork_support_destroy(); grpc_core::Fork::GlobalShutdown();
} }
#define THREAD_DELAY_MS 3000 #define THREAD_DELAY_MS 3000
@ -54,13 +54,13 @@ static void sleeping_thd(void* arg) {
static void test_thd_count() { static void test_thd_count() {
// Test no active threads // Test no active threads
grpc_enable_fork_support(true); grpc_core::Fork::Enable(true);
grpc_fork_support_init(); grpc_core::Fork::GlobalInit();
grpc_fork_await_thds(); grpc_core::Fork::AwaitThreads();
grpc_fork_support_destroy(); grpc_core::Fork::GlobalShutdown();
grpc_enable_fork_support(true); grpc_core::Fork::Enable(true);
grpc_fork_support_init(); grpc_core::Fork::GlobalInit();
grpc_core::Thread thds[CONCURRENT_TEST_THREADS]; grpc_core::Thread thds[CONCURRENT_TEST_THREADS];
gpr_timespec est_end_time = gpr_timespec est_end_time =
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
@ -74,56 +74,56 @@ static void test_thd_count() {
grpc_core::Thread("grpc_fork_test", sleeping_thd, (void*)sleep_time_ms); grpc_core::Thread("grpc_fork_test", sleeping_thd, (void*)sleep_time_ms);
thds[i].Start(); thds[i].Start();
} }
grpc_fork_await_thds(); grpc_core::Fork::AwaitThreads();
gpr_timespec end_time = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec end_time = gpr_now(GPR_CLOCK_REALTIME);
for (auto& thd : thds) { for (auto& thd : thds) {
thd.Join(); thd.Join();
} }
GPR_ASSERT(gpr_time_similar(end_time, est_end_time, tolerance)); GPR_ASSERT(gpr_time_similar(end_time, est_end_time, tolerance));
grpc_fork_support_destroy(); grpc_core::Fork::GlobalShutdown();
} }
static void exec_ctx_thread(void* arg) { static void exec_ctx_thread(void* arg) {
bool* exec_ctx_created = (bool*)arg; bool* exec_ctx_created = (bool*)arg;
grpc_fork_inc_exec_ctx_count(); grpc_core::Fork::IncExecCtxCount();
*exec_ctx_created = true; *exec_ctx_created = true;
} }
static void test_exec_count() { static void test_exec_count() {
grpc_fork_inc_exec_ctx_count(); grpc_core::Fork::IncExecCtxCount();
grpc_enable_fork_support(true); grpc_core::Fork::Enable(true);
grpc_fork_support_init(); grpc_core::Fork::GlobalInit();
grpc_fork_inc_exec_ctx_count(); grpc_core::Fork::IncExecCtxCount();
GPR_ASSERT(grpc_fork_block_exec_ctx()); GPR_ASSERT(grpc_core::Fork::BlockExecCtx());
grpc_fork_dec_exec_ctx_count(); grpc_core::Fork::DecExecCtxCount();
grpc_fork_allow_exec_ctx(); grpc_core::Fork::AllowExecCtx();
grpc_fork_inc_exec_ctx_count(); grpc_core::Fork::IncExecCtxCount();
grpc_fork_inc_exec_ctx_count(); grpc_core::Fork::IncExecCtxCount();
GPR_ASSERT(!grpc_fork_block_exec_ctx()); GPR_ASSERT(!grpc_core::Fork::BlockExecCtx());
grpc_fork_dec_exec_ctx_count(); grpc_core::Fork::DecExecCtxCount();
grpc_fork_dec_exec_ctx_count(); grpc_core::Fork::DecExecCtxCount();
grpc_fork_inc_exec_ctx_count(); grpc_core::Fork::IncExecCtxCount();
GPR_ASSERT(grpc_fork_block_exec_ctx()); GPR_ASSERT(grpc_core::Fork::BlockExecCtx());
grpc_fork_dec_exec_ctx_count(); grpc_core::Fork::DecExecCtxCount();
grpc_fork_allow_exec_ctx(); grpc_core::Fork::AllowExecCtx();
// Test that block_exec_ctx() blocks grpc_fork_inc_exec_ctx_count // Test that block_exec_ctx() blocks grpc_core::Fork::IncExecCtxCount
bool exec_ctx_created = false; bool exec_ctx_created = false;
grpc_core::Thread thd = grpc_core::Thread thd =
grpc_core::Thread("grpc_fork_test", exec_ctx_thread, &exec_ctx_created); grpc_core::Thread("grpc_fork_test", exec_ctx_thread, &exec_ctx_created);
grpc_fork_inc_exec_ctx_count(); grpc_core::Fork::IncExecCtxCount();
GPR_ASSERT(grpc_fork_block_exec_ctx()); GPR_ASSERT(grpc_core::Fork::BlockExecCtx());
grpc_fork_dec_exec_ctx_count(); grpc_core::Fork::DecExecCtxCount();
thd.Start(); thd.Start();
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(1, GPR_TIMESPAN))); gpr_time_from_seconds(1, GPR_TIMESPAN)));
GPR_ASSERT(!exec_ctx_created); GPR_ASSERT(!exec_ctx_created);
grpc_fork_allow_exec_ctx(); grpc_core::Fork::AllowExecCtx();
thd.Join(); // This ensure that the call got un-blocked thd.Join(); // This ensure that the call got un-blocked
grpc_fork_support_destroy(); grpc_core::Fork::GlobalShutdown();
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {

@ -1023,7 +1023,6 @@ src/core/lib/debug/stats_data.h \
src/core/lib/debug/trace.h \ src/core/lib/debug/trace.h \
src/core/lib/gpr/arena.h \ src/core/lib/gpr/arena.h \
src/core/lib/gpr/env.h \ src/core/lib/gpr/env.h \
src/core/lib/gpr/fork.h \
src/core/lib/gpr/host_port.h \ src/core/lib/gpr/host_port.h \
src/core/lib/gpr/mpscq.h \ src/core/lib/gpr/mpscq.h \
src/core/lib/gpr/murmur_hash.h \ src/core/lib/gpr/murmur_hash.h \
@ -1042,6 +1041,7 @@ src/core/lib/gprpp/atomic.h \
src/core/lib/gprpp/atomic_with_atm.h \ src/core/lib/gprpp/atomic_with_atm.h \
src/core/lib/gprpp/atomic_with_std.h \ src/core/lib/gprpp/atomic_with_std.h \
src/core/lib/gprpp/debug_location.h \ src/core/lib/gprpp/debug_location.h \
src/core/lib/gprpp/fork.h \
src/core/lib/gprpp/inlined_vector.h \ src/core/lib/gprpp/inlined_vector.h \
src/core/lib/gprpp/manual_constructor.h \ src/core/lib/gprpp/manual_constructor.h \
src/core/lib/gprpp/memory.h \ src/core/lib/gprpp/memory.h \

@ -1074,8 +1074,6 @@ src/core/lib/gpr/env.h \
src/core/lib/gpr/env_linux.cc \ src/core/lib/gpr/env_linux.cc \
src/core/lib/gpr/env_posix.cc \ src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \ src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/fork.cc \
src/core/lib/gpr/fork.h \
src/core/lib/gpr/host_port.cc \ src/core/lib/gpr/host_port.cc \
src/core/lib/gpr/host_port.h \ src/core/lib/gpr/host_port.h \
src/core/lib/gpr/log.cc \ src/core/lib/gpr/log.cc \
@ -1119,6 +1117,8 @@ src/core/lib/gprpp/atomic.h \
src/core/lib/gprpp/atomic_with_atm.h \ src/core/lib/gprpp/atomic_with_atm.h \
src/core/lib/gprpp/atomic_with_std.h \ src/core/lib/gprpp/atomic_with_std.h \
src/core/lib/gprpp/debug_location.h \ src/core/lib/gprpp/debug_location.h \
src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/fork.h \
src/core/lib/gprpp/inlined_vector.h \ src/core/lib/gprpp/inlined_vector.h \
src/core/lib/gprpp/manual_constructor.h \ src/core/lib/gprpp/manual_constructor.h \
src/core/lib/gprpp/memory.h \ src/core/lib/gprpp/memory.h \

@ -612,7 +612,7 @@
"language": "c", "language": "c",
"name": "fork_test", "name": "fork_test",
"src": [ "src": [
"test/core/gpr/fork_test.cc" "test/core/gprpp/fork_test.cc"
], ],
"third_party": false, "third_party": false,
"type": "target" "type": "target"
@ -8779,7 +8779,6 @@
"src/core/lib/gpr/env_linux.cc", "src/core/lib/gpr/env_linux.cc",
"src/core/lib/gpr/env_posix.cc", "src/core/lib/gpr/env_posix.cc",
"src/core/lib/gpr/env_windows.cc", "src/core/lib/gpr/env_windows.cc",
"src/core/lib/gpr/fork.cc",
"src/core/lib/gpr/host_port.cc", "src/core/lib/gpr/host_port.cc",
"src/core/lib/gpr/log.cc", "src/core/lib/gpr/log.cc",
"src/core/lib/gpr/log_android.cc", "src/core/lib/gpr/log_android.cc",
@ -8804,6 +8803,7 @@
"src/core/lib/gpr/tmpfile_posix.cc", "src/core/lib/gpr/tmpfile_posix.cc",
"src/core/lib/gpr/tmpfile_windows.cc", "src/core/lib/gpr/tmpfile_windows.cc",
"src/core/lib/gpr/wrap_memcpy.cc", "src/core/lib/gpr/wrap_memcpy.cc",
"src/core/lib/gprpp/fork.cc",
"src/core/lib/gprpp/thd_posix.cc", "src/core/lib/gprpp/thd_posix.cc",
"src/core/lib/gprpp/thd_windows.cc", "src/core/lib/gprpp/thd_windows.cc",
"src/core/lib/profiling/basic_timers.cc", "src/core/lib/profiling/basic_timers.cc",
@ -8836,7 +8836,6 @@
"include/grpc/support/time.h", "include/grpc/support/time.h",
"src/core/lib/gpr/arena.h", "src/core/lib/gpr/arena.h",
"src/core/lib/gpr/env.h", "src/core/lib/gpr/env.h",
"src/core/lib/gpr/fork.h",
"src/core/lib/gpr/host_port.h", "src/core/lib/gpr/host_port.h",
"src/core/lib/gpr/mpscq.h", "src/core/lib/gpr/mpscq.h",
"src/core/lib/gpr/murmur_hash.h", "src/core/lib/gpr/murmur_hash.h",
@ -8854,6 +8853,7 @@
"src/core/lib/gprpp/atomic.h", "src/core/lib/gprpp/atomic.h",
"src/core/lib/gprpp/atomic_with_atm.h", "src/core/lib/gprpp/atomic_with_atm.h",
"src/core/lib/gprpp/atomic_with_std.h", "src/core/lib/gprpp/atomic_with_std.h",
"src/core/lib/gprpp/fork.h",
"src/core/lib/gprpp/manual_constructor.h", "src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/memory.h", "src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/thd.h", "src/core/lib/gprpp/thd.h",
@ -8882,7 +8882,6 @@
"include/grpc/support/time.h", "include/grpc/support/time.h",
"src/core/lib/gpr/arena.h", "src/core/lib/gpr/arena.h",
"src/core/lib/gpr/env.h", "src/core/lib/gpr/env.h",
"src/core/lib/gpr/fork.h",
"src/core/lib/gpr/host_port.h", "src/core/lib/gpr/host_port.h",
"src/core/lib/gpr/mpscq.h", "src/core/lib/gpr/mpscq.h",
"src/core/lib/gpr/murmur_hash.h", "src/core/lib/gpr/murmur_hash.h",
@ -8900,6 +8899,7 @@
"src/core/lib/gprpp/atomic.h", "src/core/lib/gprpp/atomic.h",
"src/core/lib/gprpp/atomic_with_atm.h", "src/core/lib/gprpp/atomic_with_atm.h",
"src/core/lib/gprpp/atomic_with_std.h", "src/core/lib/gprpp/atomic_with_std.h",
"src/core/lib/gprpp/fork.h",
"src/core/lib/gprpp/manual_constructor.h", "src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/memory.h", "src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/thd.h", "src/core/lib/gprpp/thd.h",

Loading…
Cancel
Save