C++ize gpr_thread as grpc_core::Thread, make it 2-phase init (construct/Start)

reviewable/pr14459/r1
Vijay Pai 7 years ago
parent 5e1298f0a8
commit da69355f30
  1. 6
      BUILD
  2. 6
      CMakeLists.txt
  3. 8
      Makefile
  4. 8
      build.yaml
  5. 5
      config.m4
  6. 5
      config.w32
  7. 6
      gRPC-C++.podspec
  8. 8
      gRPC-Core.podspec
  9. 6
      grpc.gemspec
  10. 4
      grpc.gyp
  11. 6
      package.xml
  12. 48
      src/core/lib/gpr/thd.h
  13. 79
      src/core/lib/gprpp/thd.h
  14. 143
      src/core/lib/gprpp/thd_posix.cc
  15. 2
      src/core/lib/gprpp/thd_windows.cc
  16. 11
      src/core/lib/iomgr/ev_poll_posix.cc
  17. 2
      src/core/lib/iomgr/exec_ctx.cc
  18. 21
      src/core/lib/iomgr/executor.cc
  19. 4
      src/core/lib/iomgr/fork_posix.cc
  20. 2
      src/core/lib/iomgr/iocp_windows.cc
  21. 2
      src/core/lib/iomgr/iomgr.cc
  22. 2
      src/core/lib/iomgr/pollset_windows.cc
  23. 2
      src/core/lib/iomgr/resolve_address_posix.cc
  24. 2
      src/core/lib/iomgr/resolve_address_windows.cc
  25. 28
      src/core/lib/iomgr/timer_manager.cc
  26. 2
      src/core/lib/iomgr/wakeup_fd_cv.cc
  27. 11
      src/core/lib/profiling/basic_timers.cc
  28. 4
      src/core/lib/surface/init.cc
  29. 2
      src/core/tsi/alts_transport_security.cc
  30. 4
      src/core/tsi/alts_transport_security.h
  31. 2
      src/cpp/client/channel_cc.cc
  32. 4
      src/python/grpcio/grpc_core_dependencies.py
  33. 9
      test/core/bad_client/bad_client.cc
  34. 21
      test/core/end2end/bad_server_response_test.cc
  35. 1
      test/core/end2end/fixtures/h2_census.cc
  36. 1
      test/core/end2end/fixtures/h2_compress.cc
  37. 1
      test/core/end2end/fixtures/h2_full+pipe.cc
  38. 1
      test/core/end2end/fixtures/h2_full+trace.cc
  39. 1
      test/core/end2end/fixtures/h2_full+workarounds.cc
  40. 1
      test/core/end2end/fixtures/h2_full.cc
  41. 1
      test/core/end2end/fixtures/h2_http_proxy.cc
  42. 1
      test/core/end2end/fixtures/h2_load_reporting.cc
  43. 1
      test/core/end2end/fixtures/h2_proxy.cc
  44. 1
      test/core/end2end/fixtures/h2_sockpair+trace.cc
  45. 1
      test/core/end2end/fixtures/h2_sockpair.cc
  46. 1
      test/core/end2end/fixtures/h2_sockpair_1byte.cc
  47. 1
      test/core/end2end/fixtures/h2_uds.cc
  48. 11
      test/core/end2end/fixtures/http_proxy_fixture.cc
  49. 1
      test/core/end2end/fixtures/inproc.cc
  50. 12
      test/core/end2end/fixtures/proxy.cc
  51. 1
      test/core/end2end/tests/bad_ping.cc
  52. 8
      test/core/end2end/tests/connectivity.cc
  53. 1
      test/core/end2end/tests/ping.cc
  54. 18
      test/core/gpr/arena_test.cc
  55. 21
      test/core/gpr/cpu_test.cc
  56. 33
      test/core/gpr/mpscq_test.cc
  57. 21
      test/core/gpr/spinlock_test.cc
  58. 66
      test/core/gpr/sync_test.cc
  59. 1
      test/core/gpr/time_test.cc
  60. 23
      test/core/gpr/tls_test.cc
  61. 1
      test/core/gprpp/manual_constructor_test.cc
  62. 36
      test/core/gprpp/thd_test.cc
  63. 10
      test/core/handshake/client_ssl.cc
  64. 1
      test/core/handshake/readahead_handshaker_server_ssl.cc
  65. 1
      test/core/handshake/server_ssl.cc
  66. 10
      test/core/handshake/server_ssl_common.cc
  67. 1
      test/core/handshake/server_ssl_common.h
  68. 13
      test/core/iomgr/combiner_test.cc
  69. 1
      test/core/iomgr/error_test.cc
  70. 2
      test/core/iomgr/ev_epollsig_linux_test.cc
  71. 12
      test/core/iomgr/resolve_address_posix_test.cc
  72. 39
      test/core/iomgr/wakeup_fd_cv_test.cc
  73. 2
      test/core/network_benchmarks/low_level_ping_pong.cc
  74. 1
      test/core/statistics/rpc_stats_test.cc
  75. 2
      test/core/surface/byte_buffer_reader_test.cc
  76. 36
      test/core/surface/completion_queue_threading_test.cc
  77. 72
      test/core/surface/concurrent_connectivity_test.cc
  78. 2
      test/core/surface/num_external_connectivity_watchers_test.cc
  79. 8
      test/core/surface/sequential_connectivity_test.cc
  80. 1
      test/core/tsi/transport_security_test_lib.cc
  81. 2
      test/cpp/client/client_channel_stress_test.cc
  82. 2
      test/cpp/cocoapods/generic/generic.mm
  83. 1
      test/cpp/end2end/async_end2end_test.cc
  84. 1
      test/cpp/end2end/client_crash_test.cc
  85. 1
      test/cpp/end2end/client_lb_end2end_test.cc
  86. 1
      test/cpp/end2end/end2end_test.cc
  87. 1
      test/cpp/end2end/filter_end2end_test.cc
  88. 1
      test/cpp/end2end/generic_end2end_test.cc
  89. 1
      test/cpp/end2end/grpclb_end2end_test.cc
  90. 1
      test/cpp/end2end/mock_test.cc
  91. 1
      test/cpp/end2end/server_crash_test.cc
  92. 1
      test/cpp/end2end/server_early_return_test.cc
  93. 1
      test/cpp/end2end/streaming_throughput_test.cc
  94. 1
      test/cpp/end2end/thread_stress_test.cc
  95. 2
      tools/doxygen/Doxyfile.c++.internal
  96. 6
      tools/doxygen/Doxyfile.core.internal
  97. 10
      tools/run_tests/generated/sources_and_headers.json

@ -517,8 +517,8 @@ grpc_cc_library(
"src/core/lib/gpr/sync.cc",
"src/core/lib/gpr/sync_posix.cc",
"src/core/lib/gpr/sync_windows.cc",
"src/core/lib/gpr/thd_posix.cc",
"src/core/lib/gpr/thd_windows.cc",
"src/core/lib/gprpp/thd_posix.cc",
"src/core/lib/gprpp/thd_windows.cc",
"src/core/lib/gpr/time.cc",
"src/core/lib/gpr/time_posix.cc",
"src/core/lib/gpr/time_precise.cc",
@ -541,7 +541,7 @@ grpc_cc_library(
"src/core/lib/gpr/spinlock.h",
"src/core/lib/gpr/string.h",
"src/core/lib/gpr/string_windows.h",
"src/core/lib/gpr/thd.h",
"src/core/lib/gprpp/thd.h",
"src/core/lib/gpr/time_precise.h",
"src/core/lib/gpr/tls.h",
"src/core/lib/gpr/tls_gcc.h",

@ -651,8 +651,6 @@ add_library(gpr
src/core/lib/gpr/sync.cc
src/core/lib/gpr/sync_posix.cc
src/core/lib/gpr/sync_windows.cc
src/core/lib/gpr/thd_posix.cc
src/core/lib/gpr/thd_windows.cc
src/core/lib/gpr/time.cc
src/core/lib/gpr/time_posix.cc
src/core/lib/gpr/time_precise.cc
@ -662,6 +660,8 @@ add_library(gpr
src/core/lib/gpr/tmpfile_posix.cc
src/core/lib/gpr/tmpfile_windows.cc
src/core/lib/gpr/wrap_memcpy.cc
src/core/lib/gprpp/thd_posix.cc
src/core/lib/gprpp/thd_windows.cc
src/core/lib/profiling/basic_timers.cc
src/core/lib/profiling/stap_timers.cc
)
@ -6203,7 +6203,7 @@ endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_executable(gpr_thd_test
test/core/gpr/thd_test.cc
test/core/gprpp/thd_test.cc
)

@ -2899,8 +2899,6 @@ LIBGPR_SRC = \
src/core/lib/gpr/sync.cc \
src/core/lib/gpr/sync_posix.cc \
src/core/lib/gpr/sync_windows.cc \
src/core/lib/gpr/thd_posix.cc \
src/core/lib/gpr/thd_windows.cc \
src/core/lib/gpr/time.cc \
src/core/lib/gpr/time_posix.cc \
src/core/lib/gpr/time_precise.cc \
@ -2910,6 +2908,8 @@ LIBGPR_SRC = \
src/core/lib/gpr/tmpfile_posix.cc \
src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/thd_posix.cc \
src/core/lib/gprpp/thd_windows.cc \
src/core/lib/profiling/basic_timers.cc \
src/core/lib/profiling/stap_timers.cc \
@ -11014,7 +11014,7 @@ endif
GPR_THD_TEST_SRC = \
test/core/gpr/thd_test.cc \
test/core/gprpp/thd_test.cc \
GPR_THD_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GPR_THD_TEST_SRC))))
ifeq ($(NO_SECURE),true)
@ -11034,7 +11034,7 @@ $(BINDIR)/$(CONFIG)/gpr_thd_test: $(GPR_THD_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgp
endif
$(OBJDIR)/$(CONFIG)/test/core/gpr/thd_test.o: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/test/core/gprpp/thd_test.o: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_gpr_thd_test: $(GPR_THD_TEST_OBJS:.o=.dep)

@ -59,8 +59,6 @@ filegroups:
- src/core/lib/gpr/sync.cc
- src/core/lib/gpr/sync_posix.cc
- src/core/lib/gpr/sync_windows.cc
- src/core/lib/gpr/thd_posix.cc
- src/core/lib/gpr/thd_windows.cc
- src/core/lib/gpr/time.cc
- src/core/lib/gpr/time_posix.cc
- src/core/lib/gpr/time_precise.cc
@ -70,6 +68,8 @@ filegroups:
- src/core/lib/gpr/tmpfile_posix.cc
- src/core/lib/gpr/tmpfile_windows.cc
- src/core/lib/gpr/wrap_memcpy.cc
- src/core/lib/gprpp/thd_posix.cc
- src/core/lib/gprpp/thd_windows.cc
- src/core/lib/profiling/basic_timers.cc
- src/core/lib/profiling/stap_timers.cc
uses:
@ -103,7 +103,6 @@ filegroups:
- src/core/lib/gpr/spinlock.h
- src/core/lib/gpr/string.h
- src/core/lib/gpr/string_windows.h
- src/core/lib/gpr/thd.h
- src/core/lib/gpr/time_precise.h
- src/core/lib/gpr/tls.h
- src/core/lib/gpr/tls_gcc.h
@ -117,6 +116,7 @@ filegroups:
- src/core/lib/gprpp/atomic_with_std.h
- src/core/lib/gprpp/manual_constructor.h
- src/core/lib/gprpp/memory.h
- src/core/lib/gprpp/thd.h
- src/core/lib/profiling/timers.h
uses:
- gpr_codegen
@ -2325,7 +2325,7 @@ targets:
build: test
language: c
src:
- test/core/gpr/thd_test.cc
- test/core/gprpp/thd_test.cc
deps:
- gpr_test_util
- gpr

@ -65,8 +65,6 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gpr/sync.cc \
src/core/lib/gpr/sync_posix.cc \
src/core/lib/gpr/sync_windows.cc \
src/core/lib/gpr/thd_posix.cc \
src/core/lib/gpr/thd_windows.cc \
src/core/lib/gpr/time.cc \
src/core/lib/gpr/time_posix.cc \
src/core/lib/gpr/time_precise.cc \
@ -76,6 +74,8 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gpr/tmpfile_posix.cc \
src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/thd_posix.cc \
src/core/lib/gprpp/thd_windows.cc \
src/core/lib/profiling/basic_timers.cc \
src/core/lib/profiling/stap_timers.cc \
src/core/lib/surface/init.cc \
@ -626,6 +626,7 @@ if test "$PHP_GRPC" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/compression)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/debug)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gpr)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gprpp)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/http)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/iomgr)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/json)

@ -42,8 +42,6 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\sync.cc " +
"src\\core\\lib\\gpr\\sync_posix.cc " +
"src\\core\\lib\\gpr\\sync_windows.cc " +
"src\\core\\lib\\gpr\\thd_posix.cc " +
"src\\core\\lib\\gpr\\thd_windows.cc " +
"src\\core\\lib\\gpr\\time.cc " +
"src\\core\\lib\\gpr\\time_posix.cc " +
"src\\core\\lib\\gpr\\time_precise.cc " +
@ -53,6 +51,8 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\tmpfile_posix.cc " +
"src\\core\\lib\\gpr\\tmpfile_windows.cc " +
"src\\core\\lib\\gpr\\wrap_memcpy.cc " +
"src\\core\\lib\\gprpp\\thd_posix.cc " +
"src\\core\\lib\\gprpp\\thd_windows.cc " +
"src\\core\\lib\\profiling\\basic_timers.cc " +
"src\\core\\lib\\profiling\\stap_timers.cc " +
"src\\core\\lib\\surface\\init.cc " +
@ -638,6 +638,7 @@ if (PHP_GRPC != "no") {
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\compression");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\debug");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gpr");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gprpp");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\http");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\iomgr");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\json");

@ -288,7 +288,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h',
'src/core/lib/gpr/string_windows.h',
'src/core/lib/gpr/thd.h',
'src/core/lib/gpr/time_precise.h',
'src/core/lib/gpr/tls.h',
'src/core/lib/gpr/tls_gcc.h',
@ -302,6 +301,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic_with_std.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h',
'src/core/ext/transport/chttp2/transport/bin_decoder.h',
'src/core/ext/transport/chttp2/transport/bin_encoder.h',
@ -541,7 +541,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h',
'src/core/lib/gpr/string_windows.h',
'src/core/lib/gpr/thd.h',
'src/core/lib/gpr/time_precise.h',
'src/core/lib/gpr/tls.h',
'src/core/lib/gpr/tls_gcc.h',
@ -555,6 +554,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic_with_std.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h',
'src/core/lib/avl/avl.h',
'src/core/lib/backoff/backoff.h',
@ -731,7 +731,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h',
'src/core/lib/gpr/string_windows.h',
'src/core/lib/gpr/thd.h',
'src/core/lib/gpr/time_precise.h',
'src/core/lib/gpr/tls.h',
'src/core/lib/gpr/tls_gcc.h',
@ -745,6 +744,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic_with_std.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h',
'src/core/ext/filters/client_channel/backup_poller.h',
'src/core/ext/filters/client_channel/client_channel.h',

@ -192,7 +192,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h',
'src/core/lib/gpr/string_windows.h',
'src/core/lib/gpr/thd.h',
'src/core/lib/gpr/time_precise.h',
'src/core/lib/gpr/tls.h',
'src/core/lib/gpr/tls_gcc.h',
@ -206,6 +205,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic_with_std.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h',
'src/core/lib/gpr/alloc.cc',
'src/core/lib/gpr/arena.cc',
@ -233,8 +233,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/sync.cc',
'src/core/lib/gpr/sync_posix.cc',
'src/core/lib/gpr/sync_windows.cc',
'src/core/lib/gpr/thd_posix.cc',
'src/core/lib/gpr/thd_windows.cc',
'src/core/lib/gpr/time.cc',
'src/core/lib/gpr/time_posix.cc',
'src/core/lib/gpr/time_precise.cc',
@ -244,6 +242,8 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/tmpfile_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc',
'src/core/lib/profiling/basic_timers.cc',
'src/core/lib/profiling/stap_timers.cc',
'src/core/ext/transport/chttp2/transport/bin_decoder.h',
@ -720,7 +720,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h',
'src/core/lib/gpr/string_windows.h',
'src/core/lib/gpr/thd.h',
'src/core/lib/gpr/time_precise.h',
'src/core/lib/gpr/tls.h',
'src/core/lib/gpr/tls_gcc.h',
@ -734,6 +733,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic_with_std.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h',
'src/core/ext/transport/chttp2/transport/bin_decoder.h',
'src/core/ext/transport/chttp2/transport/bin_encoder.h',

@ -83,7 +83,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/spinlock.h )
s.files += %w( src/core/lib/gpr/string.h )
s.files += %w( src/core/lib/gpr/string_windows.h )
s.files += %w( src/core/lib/gpr/thd.h )
s.files += %w( src/core/lib/gpr/time_precise.h )
s.files += %w( src/core/lib/gpr/tls.h )
s.files += %w( src/core/lib/gpr/tls_gcc.h )
@ -97,6 +96,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/atomic_with_std.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/thd.h )
s.files += %w( src/core/lib/profiling/timers.h )
s.files += %w( src/core/lib/gpr/alloc.cc )
s.files += %w( src/core/lib/gpr/arena.cc )
@ -124,8 +124,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/sync.cc )
s.files += %w( src/core/lib/gpr/sync_posix.cc )
s.files += %w( src/core/lib/gpr/sync_windows.cc )
s.files += %w( src/core/lib/gpr/thd_posix.cc )
s.files += %w( src/core/lib/gpr/thd_windows.cc )
s.files += %w( src/core/lib/gpr/time.cc )
s.files += %w( src/core/lib/gpr/time_posix.cc )
s.files += %w( src/core/lib/gpr/time_precise.cc )
@ -135,6 +133,8 @@ Gem::Specification.new do |s|
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/wrap_memcpy.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/profiling/basic_timers.cc )
s.files += %w( src/core/lib/profiling/stap_timers.cc )
s.files += %w( include/grpc/impl/codegen/byte_buffer.h )

@ -187,8 +187,6 @@
'src/core/lib/gpr/sync.cc',
'src/core/lib/gpr/sync_posix.cc',
'src/core/lib/gpr/sync_windows.cc',
'src/core/lib/gpr/thd_posix.cc',
'src/core/lib/gpr/thd_windows.cc',
'src/core/lib/gpr/time.cc',
'src/core/lib/gpr/time_posix.cc',
'src/core/lib/gpr/time_precise.cc',
@ -198,6 +196,8 @@
'src/core/lib/gpr/tmpfile_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc',
'src/core/lib/profiling/basic_timers.cc',
'src/core/lib/profiling/stap_timers.cc',
],

@ -90,7 +90,6 @@
<file baseinstalldir="/" name="src/core/lib/gpr/spinlock.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/string.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/string_windows.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/thd.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/time_precise.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/tls.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/tls_gcc.h" role="src" />
@ -104,6 +103,7 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/atomic_with_std.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/thd.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/profiling/timers.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/alloc.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/arena.cc" role="src" />
@ -131,8 +131,6 @@
<file baseinstalldir="/" name="src/core/lib/gpr/sync.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/sync_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/sync_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/thd_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/thd_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/time.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/time_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/time_precise.cc" role="src" />
@ -142,6 +140,8 @@
<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/wrap_memcpy.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/profiling/basic_timers.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/profiling/stap_timers.cc" role="src" />
<file baseinstalldir="/" name="include/grpc/impl/codegen/byte_buffer.h" role="src" />

@ -1,48 +0,0 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPC_CORE_LIB_GPR_THD_H
#define GRPC_CORE_LIB_GPR_THD_H
/** Internal thread interface for GPR.
Types
gpr_thd_options options used when creating a thread
*/
#include <grpc/support/port_platform.h>
#include <grpc/support/thd_id.h>
#include <grpc/support/time.h>
/** Create a new thread running (*thd_body)(arg) and place its thread identifier
in *t, and return true. If there are insufficient resources, return false.
thd_name is the name of the thread for identification purposes on platforms
that support thread naming.
The thread must be joined. */
int gpr_thd_new(gpr_thd_id* t, const char* thd_name,
void (*thd_body)(void* arg), void* arg);
/** Blocks until the specified thread properly terminates. */
void gpr_thd_join(gpr_thd_id t);
/* Internal interfaces between modules within the gpr support library. */
void gpr_thd_init();
/* Wait for all outstanding threads to finish, up to deadline */
int gpr_await_threads(gpr_timespec deadline);
#endif /* GRPC_CORE_LIB_GPR_THD_H */

@ -0,0 +1,79 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPC_CORE_LIB_GPRPP_THD_H
#define GRPC_CORE_LIB_GPRPP_THD_H
/** Internal thread interface. */
#include <grpc/support/port_platform.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd_id.h>
#include <grpc/support/time.h>
namespace grpc_core {
class Thread {
public:
/// Default constructor only to allow use in structs that lack constructors
/// Does not produce a validly-constructed thread; must later
/// use placement new to construct a real thread. Does not init mu_ and cv_
Thread(): real_(false), alive_(false), started_(false), joined_(false) {}
Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg,
bool* success = nullptr);
~Thread() {
if (!alive_) {
// This thread never existed, so nothing to do
} else {
GPR_ASSERT(joined_);
}
if (real_) {
gpr_mu_destroy(&mu_);
gpr_cv_destroy(&ready_);
}
}
void Start() {
gpr_mu_lock(&mu_);
if (alive_) {
started_ = true;
gpr_cv_signal(&ready_);
}
gpr_mu_unlock(&mu_);
}
void Join();
static void Init();
static bool AwaitAll(gpr_timespec deadline);
private:
gpr_mu mu_;
gpr_cv ready_;
gpr_thd_id id_;
bool real_;
bool alive_;
bool started_;
bool joined_;
};
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_THD_H */

@ -22,7 +22,7 @@
#ifdef GPR_POSIX_SYNC
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -35,51 +35,56 @@
#include "src/core/lib/gpr/fork.h"
#include "src/core/lib/gpr/useful.h"
static gpr_mu g_mu;
static gpr_cv g_cv;
static int g_thread_count;
static int g_awaiting_threads;
namespace grpc_core {
namespace {
gpr_mu g_mu;
gpr_cv g_cv;
int g_thread_count;
int g_awaiting_threads;
struct thd_arg {
Thread* thread;
void (*body)(void* arg); /* body of a thread */
void* arg; /* argument to a thread */
const char* name; /* name of thread. Can be nullptr. */
};
static void inc_thd_count();
static void dec_thd_count();
/*****************************************
* Only used when fork support is enabled
*/
/* Body of every thread started via gpr_thd_new. */
static void* thread_body(void* v) {
struct thd_arg a = *static_cast<struct thd_arg*>(v);
free(v);
if (a.name != nullptr) {
#if GPR_APPLE_PTHREAD_NAME
/* Apple supports 64 characters, and will truncate if it's longer. */
pthread_setname_np(a.name);
#elif GPR_LINUX_PTHREAD_NAME
/* Linux supports 16 characters max, and will error if it's longer. */
char buf[16];
size_t buf_len = GPR_ARRAY_SIZE(buf) - 1;
strncpy(buf, a.name, buf_len);
buf[buf_len] = '\0';
pthread_setname_np(pthread_self(), buf);
#endif // GPR_APPLE_PTHREAD_NAME
void inc_thd_count() {
if (grpc_fork_support_enabled()) {
gpr_mu_lock(&g_mu);
g_thread_count++;
gpr_mu_unlock(&g_mu);
}
}
void dec_thd_count() {
if (grpc_fork_support_enabled()) {
gpr_mu_lock(&g_mu);
g_thread_count--;
if (g_awaiting_threads && g_thread_count == 0) {
gpr_cv_signal(&g_cv);
}
gpr_mu_unlock(&g_mu);
}
(*a.body)(a.arg);
dec_thd_count();
return nullptr;
}
int gpr_thd_new(gpr_thd_id* t, const char* thd_name,
void (*thd_body)(void* arg), void* arg) {
int thread_started;
} // namespace
Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg,
bool* success):
real_(true), alive_(false), started_(false), joined_(false) {
gpr_mu_init(&mu_);
gpr_cv_init(&ready_);
pthread_attr_t attr;
pthread_t p;
/* don't use gpr_malloc as we may cause an infinite recursion with
* the profiling code */
struct thd_arg* a = static_cast<struct thd_arg*>(malloc(sizeof(*a)));
thd_arg* a = static_cast<thd_arg*>(malloc(sizeof(*a)));
GPR_ASSERT(a != nullptr);
a->thread = this;
a->body = thd_body;
a->arg = arg;
a->name = thd_name;
@ -88,54 +93,63 @@ int gpr_thd_new(gpr_thd_id* t, const char* thd_name,
GPR_ASSERT(pthread_attr_init(&attr) == 0);
GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) == 0);
thread_started = (pthread_create(&p, &attr, &thread_body, a) == 0);
pthread_t p;
alive_ = (pthread_create(&p, &attr, [](void *v) -> void* {
thd_arg a = *static_cast<thd_arg*>(v);
free(v);
if (a.name != nullptr) {
#if GPR_APPLE_PTHREAD_NAME
/* Apple supports 64 characters, and will truncate if it's longer. */
pthread_setname_np(a.name);
#elif GPR_LINUX_PTHREAD_NAME
/* Linux supports 16 characters max, and will error if it's longer. */
char buf[16];
size_t buf_len = GPR_ARRAY_SIZE(buf) - 1;
strncpy(buf, a.name, buf_len);
buf[buf_len] = '\0';
pthread_setname_np(pthread_self(), buf);
#endif // GPR_APPLE_PTHREAD_NAME
}
gpr_mu_lock(&a.thread->mu_);
if (!a.thread->started_) {
gpr_cv_wait(&a.thread->ready_, &a.thread->mu_,
gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_unlock(&a.thread->mu_);
(*a.body)(a.arg);
dec_thd_count();
return nullptr;
}, a) == 0);
if (success != nullptr) { *success = alive_; }
id_ = reinterpret_cast<gpr_thd_id>(p);
GPR_ASSERT(pthread_attr_destroy(&attr) == 0);
if (!thread_started) {
if (!alive_) {
/* don't use gpr_free, as this was allocated using malloc (see above) */
free(a);
dec_thd_count();
}
*t = (gpr_thd_id)p;
return thread_started;
}
gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)pthread_self(); }
void gpr_thd_join(gpr_thd_id t) { pthread_join((pthread_t)t, nullptr); }
/*****************************************
* Only used when fork support is enabled
*/
static void inc_thd_count() {
if (grpc_fork_support_enabled()) {
gpr_mu_lock(&g_mu);
g_thread_count++;
gpr_mu_unlock(&g_mu);
void Thread::Join() {
if (alive_) {
pthread_join(reinterpret_cast<pthread_t>(id_), nullptr);
}
joined_ = true;
}
static void dec_thd_count() {
if (grpc_fork_support_enabled()) {
gpr_mu_lock(&g_mu);
g_thread_count--;
if (g_awaiting_threads && g_thread_count == 0) {
gpr_cv_signal(&g_cv);
}
gpr_mu_unlock(&g_mu);
}
}
void gpr_thd_init() {
void Thread::Init() {
gpr_mu_init(&g_mu);
gpr_cv_init(&g_cv);
g_thread_count = 0;
g_awaiting_threads = 0;
}
int gpr_await_threads(gpr_timespec deadline) {
bool Thread::AwaitAll(gpr_timespec deadline) {
gpr_mu_lock(&g_mu);
g_awaiting_threads = 1;
int res = 0;
@ -147,4 +161,9 @@ int gpr_await_threads(gpr_timespec deadline) {
return res == 0;
}
} // namespace grpc_core
// The following is in the external namespace as it is exposed as C89 API
gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)pthread_self(); }
#endif /* GPR_POSIX_SYNC */

@ -22,7 +22,7 @@
#ifdef GPR_WINDOWS
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>

@ -22,6 +22,7 @@
#include "src/core/lib/iomgr/ev_poll_posix.h"
#include <new>
#include <assert.h>
#include <errno.h>
#include <limits.h>
@ -36,7 +37,7 @@
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/murmur_hash.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/tls.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/block_annotate.h"
@ -253,7 +254,7 @@ typedef struct poll_result {
} poll_result;
typedef struct poll_args {
gpr_thd_id poller_thd;
grpc_core::Thread poller_thd;
gpr_cv trigger;
int trigger_set;
gpr_cv harvest;
@ -1377,7 +1378,8 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) {
init_result(pargs);
cache_poller_locked(pargs);
gpr_ref(&g_cvfds.pollcount);
GPR_ASSERT(gpr_thd_new(&pargs->poller_thd, "grpc_poller", &run_poll, pargs));
new (&pargs->poller_thd) grpc_core::Thread("grpc_poller", &run_poll, pargs);
pargs->poller_thd.Start();
return pargs;
}
@ -1462,7 +1464,8 @@ static void cache_harvest_locked() {
}
gpr_cv_signal(&args->harvest);
gpr_cv_wait(&args->join, &g_cvfds.mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
gpr_thd_join(args->poller_thd);
args->poller_thd.Join();
args->poller_thd.~Thread();
gpr_free(args);
}
}

@ -21,7 +21,7 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/profiling/timers.h"

@ -18,6 +18,7 @@
#include "src/core/lib/iomgr/executor.h"
#include <new>
#include <string.h>
#include <grpc/support/alloc.h>
@ -27,7 +28,7 @@
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/spinlock.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/tls.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h"
@ -41,7 +42,7 @@ typedef struct {
size_t depth;
bool shutdown;
bool queued_long_job;
gpr_thd_id id;
grpc_core::Thread thd;
} thread_state;
static thread_state* g_thread_state;
@ -99,11 +100,14 @@ void grpc_executor_set_threading(bool threading) {
for (size_t i = 0; i < g_max_threads; i++) {
gpr_mu_init(&g_thread_state[i].mu);
gpr_cv_init(&g_thread_state[i].cv);
new (&g_thread_state[i].thd) grpc_core::Thread();
g_thread_state[i].elems = GRPC_CLOSURE_LIST_INIT;
}
gpr_thd_new(&g_thread_state[0].id, "grpc_executor", executor_thread,
&g_thread_state[0]);
new (&g_thread_state[0].thd) grpc_core::Thread("grpc_executor",
executor_thread,
&g_thread_state[0]);
g_thread_state[0].thd.Start();
} else {
if (cur_threads == 0) return;
for (size_t i = 0; i < g_max_threads; i++) {
@ -117,10 +121,11 @@ void grpc_executor_set_threading(bool threading) {
gpr_spinlock_lock(&g_adding_thread_lock);
gpr_spinlock_unlock(&g_adding_thread_lock);
for (gpr_atm i = 0; i < g_cur_threads; i++) {
gpr_thd_join(g_thread_state[i].id);
g_thread_state[i].thd.Join();
}
gpr_atm_no_barrier_store(&g_cur_threads, 0);
for (size_t i = 0; i < g_max_threads; i++) {
g_thread_state[i].thd.~Thread();
gpr_mu_destroy(&g_thread_state[i].mu);
gpr_cv_destroy(&g_thread_state[i].cv);
run_closures(g_thread_state[i].elems);
@ -260,8 +265,10 @@ static void executor_push(grpc_closure* closure, grpc_error* error,
if (cur_thread_count < g_max_threads) {
gpr_atm_no_barrier_store(&g_cur_threads, cur_thread_count + 1);
gpr_thd_new(&g_thread_state[cur_thread_count].id, "gpr_executor",
executor_thread, &g_thread_state[cur_thread_count]);
new (&g_thread_state[cur_thread_count].thd)
grpc_core::Thread("grpc_executor", executor_thread,
&g_thread_state[cur_thread_count]);
g_thread_state[cur_thread_count].thd.Start();
}
gpr_spinlock_unlock(&g_adding_thread_lock);
}

@ -27,7 +27,7 @@
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/fork.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/timer_manager.h"
@ -51,7 +51,7 @@ void grpc_prefork() {
grpc_timer_manager_set_threading(false);
grpc_executor_set_threading(false);
grpc_core::ExecCtx::Get()->Flush();
if (!gpr_await_threads(
if (!grpc_core::Thread::AwaitAll(
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!");

@ -28,7 +28,7 @@
#include <grpc/support/log_windows.h>
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/iocp_windows.h"
#include "src/core/lib/iomgr/iomgr_internal.h"
#include "src/core/lib/iomgr/socket_windows.h"

@ -31,7 +31,7 @@
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/executor.h"

@ -22,7 +22,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/iocp_windows.h"
#include "src/core/lib/iomgr/iomgr_internal.h"
#include "src/core/lib/iomgr/pollset.h"

@ -33,7 +33,7 @@
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/block_annotate.h"
#include "src/core/lib/iomgr/executor.h"

@ -35,7 +35,7 @@
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/block_annotate.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr_internal.h"

@ -18,20 +18,21 @@
#include "src/core/lib/iomgr/timer_manager.h"
#include <new>
#include <inttypes.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <inttypes.h>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/timer.h"
typedef struct completed_thread {
gpr_thd_id t;
struct completed_thread* next;
} completed_thread;
struct completed_thread {
grpc_core::Thread thd;
completed_thread* next;
};
extern grpc_core::TraceFlag grpc_timer_check_trace;
@ -67,7 +68,8 @@ static void gc_completed_threads(void) {
g_completed_threads = nullptr;
gpr_mu_unlock(&g_mu);
while (to_gc != nullptr) {
gpr_thd_join(to_gc->t);
to_gc->thd.Join();
to_gc->thd.~Thread();
completed_thread* next = to_gc->next;
gpr_free(to_gc);
to_gc = next;
@ -86,14 +88,8 @@ static void start_timer_thread_and_unlock(void) {
}
completed_thread* ct =
static_cast<completed_thread*>(gpr_malloc(sizeof(*ct)));
// The call to gpr_thd_new() has to be under the same lock used by
// gc_completed_threads(), particularly due to ct->t, which is written here
// (internally by gpr_thd_new) and read there. Otherwise it's possible for ct
// to leak through g_completed_threads and be freed in gc_completed_threads()
// before "&ct->t" is written to, causing a use-after-free.
gpr_mu_lock(&g_mu);
gpr_thd_new(&ct->t, "grpc_global_timer", timer_thread, ct);
gpr_mu_unlock(&g_mu);
new (&ct->thd) grpc_core::Thread("grpc_global_timer", timer_thread, ct);
ct->thd.Start();
}
void grpc_timer_manager_tick() {

@ -30,7 +30,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#define MAX_TABLE_RESIZE 256

@ -30,7 +30,7 @@
#include <string.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
typedef enum { BEGIN = '{', END = '}', MARK = '.' } marker_type;
@ -68,7 +68,7 @@ static pthread_cond_t g_cv;
static gpr_timer_log_list g_in_progress_logs;
static gpr_timer_log_list g_done_logs;
static int g_shutdown;
static gpr_thd_id g_writing_thread;
static grpc_core::Thread* g_writing_thread;
static __thread int g_thread_id;
static int g_next_thread_id;
static int g_writing_enabled = 1;
@ -182,7 +182,8 @@ static void finish_writing(void) {
g_shutdown = 1;
pthread_cond_signal(&g_cv);
pthread_mutex_unlock(&g_mu);
gpr_thd_join(g_writing_thread);
g_writing_thread->Join();
delete g_writing_thread;
gpr_log(GPR_INFO, "flushing logs");
@ -201,8 +202,8 @@ void gpr_timers_set_log_filename(const char* filename) {
}
static void init_output() {
GPR_ASSERT(gpr_thd_new(&g_writing_thread, "timer_output_thread",
writing_thread, NULL));
g_writing_thread = new grpc_core::Thread("timer_output_thread",
writing_thread, nullptr);
atexit(finish_writing);
}

@ -32,7 +32,7 @@
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/fork.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/http/parser.h"
#include "src/core/lib/iomgr/call_combiner.h"
#include "src/core/lib/iomgr/combiner.h"
@ -123,7 +123,7 @@ void grpc_init(void) {
gpr_mu_lock(&g_init_mu);
if (++g_initializations == 1) {
gpr_time_init();
gpr_thd_init();
grpc_core::Thread::Init();
grpc_stats_init();
grpc_slice_intern_init();
grpc_mdctx_global_init();

@ -54,7 +54,7 @@ void grpc_tsi_alts_shutdown() {
grpc_tsi_alts_wait_for_cq_drain();
grpc_completion_queue_destroy(g_alts_resource.cq);
grpc_channel_destroy(g_alts_resource.channel);
gpr_thd_join(g_alts_resource.thread_id);
g_alts_resource.thread.Join();
}
gpr_cv_destroy(&g_alts_resource.cv);
gpr_mu_destroy(&g_alts_resource.mu);

@ -22,10 +22,10 @@
#include <grpc/grpc.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
typedef struct alts_shared_resource {
gpr_thd_id thread_id;
grpc_core::Thread thread;
grpc_channel* channel;
grpc_completion_queue* cq;
gpr_mu mu;

@ -42,7 +42,7 @@
#include <grpcpp/support/time.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/profiling/timers.h"
namespace grpc {

@ -41,8 +41,6 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/sync.cc',
'src/core/lib/gpr/sync_posix.cc',
'src/core/lib/gpr/sync_windows.cc',
'src/core/lib/gpr/thd_posix.cc',
'src/core/lib/gpr/thd_windows.cc',
'src/core/lib/gpr/time.cc',
'src/core/lib/gpr/time_posix.cc',
'src/core/lib/gpr/time_precise.cc',
@ -52,6 +50,8 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/tmpfile_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc',
'src/core/lib/profiling/basic_timers.cc',
'src/core/lib/profiling/stap_timers.cc',
'src/core/lib/surface/init.cc',

@ -29,7 +29,7 @@
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/gpr/murmur_hash.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/completion_queue.h"
@ -220,11 +220,12 @@ void grpc_run_bad_client_test(
/* Check a ground truth */
GPR_ASSERT(grpc_server_has_open_connections(a.server));
gpr_thd_id server_validator_id;
gpr_event_init(&a.done_thd);
a.validator = server_validator;
/* Start validator */
gpr_thd_new(&server_validator_id, "grpc_bad_client", thd_func, &a);
grpc_core::Thread server_validator_thd("grpc_bad_client", thd_func, &a);
server_validator_thd.Start();
for (int i = 0; i < num_args; i++) {
grpc_run_client_side_validator(&args[i], i == (num_args - 1) ? flags : 0,
&sfd, client_cq);
@ -234,7 +235,7 @@ void grpc_run_bad_client_test(
/* Shutdown. */
shutdown_client(&sfd.client);
gpr_thd_join(server_validator_id);
server_validator_thd.Join();
shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
grpc_server_shutdown_and_notify(a.server, shutdown_cq, nullptr);

@ -31,7 +31,8 @@
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h"
@ -253,17 +254,18 @@ static void actually_poll_server(void* arg) {
gpr_free(pa);
}
static gpr_thd_id poll_server_until_read_done(test_tcp_server* server,
gpr_event* signal_when_done) {
static grpc_core::Thread*
poll_server_until_read_done(test_tcp_server* server,
gpr_event* signal_when_done) {
gpr_atm_rel_store(&state.done_atm, 0);
state.write_done = 0;
gpr_thd_id id;
poll_args* pa = static_cast<poll_args*>(gpr_malloc(sizeof(*pa)));
pa->server = server;
pa->signal_when_done = signal_when_done;
gpr_thd_new(&id, "grpc_poll_server", actually_poll_server, pa);
return id;
auto* th = grpc_core::New<grpc_core::Thread>("grpc_poll_server",
actually_poll_server, pa);
th->Start();
return th;
}
static void run_test(const char* response_payload,
@ -283,10 +285,11 @@ static void run_test(const char* response_payload,
state.response_payload_length = response_payload_length;
/* poll server until sending out the response */
gpr_thd_id id = poll_server_until_read_done(&test_server, &ev);
grpc_core::UniquePtr<grpc_core::Thread>
thdptr(poll_server_until_read_done(&test_server, &ev));
start_rpc(server_port, expected_status, expected_detail);
gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_thd_join(id);
thdptr->Join();
/* clean up */
grpc_endpoint_shutdown(state.tcp,

@ -30,7 +30,6 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"

@ -30,7 +30,6 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"

@ -34,7 +34,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"

@ -35,7 +35,6 @@
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"

@ -31,7 +31,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"

@ -29,7 +29,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"

@ -31,7 +31,6 @@
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/end2end/fixtures/http_proxy_fixture.h"

@ -31,7 +31,6 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"

@ -29,7 +29,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/end2end/fixtures/proxy.h"

@ -36,7 +36,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/surface/channel.h"

@ -30,7 +30,6 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/surface/channel.h"

@ -30,7 +30,6 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/surface/channel.h"

@ -33,7 +33,6 @@
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"

@ -20,6 +20,7 @@
#include "src/core/lib/iomgr/sockaddr.h"
#include <new>
#include <string.h>
#include <grpc/grpc.h>
@ -33,7 +34,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/http/parser.h"
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/combiner.h"
@ -53,7 +54,7 @@
struct grpc_end2end_http_proxy {
char* proxy_name;
gpr_thd_id thd;
grpc_core::Thread thd;
grpc_tcp_server* server;
grpc_channel_args* channel_args;
gpr_mu* mu;
@ -550,7 +551,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create(
grpc_tcp_server_start(proxy->server, &proxy->pollset, 1, on_accept, proxy);
// Start proxy thread.
GPR_ASSERT(gpr_thd_new(&proxy->thd, "grpc_http_proxy", thread_main, proxy));
new (&proxy->thd) grpc_core::Thread("grpc_http_proxy", thread_main, proxy);
proxy->thd.Start();
return proxy;
}
@ -563,7 +565,8 @@ static void destroy_pollset(void* arg, grpc_error* error) {
void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) {
gpr_unref(&proxy->users); // Signal proxy thread to shutdown.
grpc_core::ExecCtx exec_ctx;
gpr_thd_join(proxy->thd);
proxy->thd.Join();
proxy->thd.~Thread();
grpc_tcp_server_shutdown_listeners(proxy->server);
grpc_tcp_server_unref(proxy->server);
gpr_free(proxy->proxy_name);

@ -29,7 +29,6 @@
#include "src/core/ext/transport/inproc/inproc_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"

@ -18,6 +18,7 @@
#include "test/core/end2end/fixtures/proxy.h"
#include <new>
#include <string.h>
#include <grpc/support/alloc.h>
@ -25,12 +26,12 @@
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/util/port.h"
struct grpc_end2end_proxy {
gpr_thd_id thd;
grpc_core::Thread thd;
char* proxy_port;
char* server_port;
grpc_completion_queue* cq;
@ -97,8 +98,8 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def,
grpc_server_start(proxy->server);
grpc_call_details_init(&proxy->new_call_details);
GPR_ASSERT(
gpr_thd_new(&proxy->thd, "grpc_end2end_proxy", thread_main, proxy));
new (&proxy->thd) grpc_core::Thread("grpc_end2end_proxy", thread_main, proxy);
proxy->thd.Start();
request_call(proxy);
@ -121,7 +122,8 @@ static void shutdown_complete(void* arg, int success) {
void grpc_end2end_proxy_destroy(grpc_end2end_proxy* proxy) {
grpc_server_shutdown_and_notify(proxy->server, proxy->cq,
new_closure(shutdown_complete, proxy));
gpr_thd_join(proxy->thd);
proxy->thd.Join();
proxy->thd.~Thread();
gpr_free(proxy->proxy_port);
gpr_free(proxy->server_port);
grpc_server_destroy(proxy->server);

@ -25,7 +25,6 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/end2end/cq_verifier.h"

@ -22,7 +22,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "test/core/end2end/cq_verifier.h"
static void* tag(intptr_t t) { return (void*)t; }
@ -50,7 +50,6 @@ static void test_connectivity(grpc_end2end_test_config config) {
grpc_connectivity_state state;
cq_verifier* cqv = cq_verifier_create(f.cq);
child_events ce;
gpr_thd_id thdid;
grpc_channel_args client_args;
grpc_arg arg_array[1];
@ -66,7 +65,8 @@ static void test_connectivity(grpc_end2end_test_config config) {
ce.channel = f.client;
ce.cq = f.cq;
gpr_event_init(&ce.started);
GPR_ASSERT(gpr_thd_new(&thdid, "grpc_connectivity", child_thread, &ce));
grpc_core::Thread thd("grpc_connectivity", child_thread, &ce);
thd.Start();
gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC));
@ -83,7 +83,7 @@ static void test_connectivity(grpc_end2end_test_config config) {
f.client, GRPC_CHANNEL_IDLE, gpr_now(GPR_CLOCK_MONOTONIC), f.cq, tag(1));
/* eventually the child thread completion should trigger */
gpr_thd_join(thdid);
thd.Join();
/* check that we're still in idle, and start connecting */
GPR_ASSERT(grpc_channel_check_connectivity_state(f.client, 1) ==

@ -22,7 +22,6 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/end2end/cq_verifier.h"

@ -18,15 +18,17 @@
#include "src/core/lib/gpr/arena.h"
#include <new>
#include <inttypes.h>
#include <string.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <inttypes.h>
#include <string.h>
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/util/test_config.h"
@ -97,16 +99,18 @@ static void concurrent_test(void) {
gpr_event_init(&args.ev_start);
args.arena = gpr_arena_create(1024);
gpr_thd_id thds[CONCURRENT_TEST_THREADS];
grpc_core::Thread thds[CONCURRENT_TEST_THREADS];
for (int i = 0; i < CONCURRENT_TEST_THREADS; i++) {
gpr_thd_new(&thds[i], "grpc_concurrent_test", concurrent_test_body, &args);
new (&thds[i]) grpc_core::Thread("grpc_concurrent_test",
concurrent_test_body, &args);
thds[i].Start();
}
gpr_event_set(&args.ev_start, (void*)1);
for (int i = 0; i < CONCURRENT_TEST_THREADS; i++) {
gpr_thd_join(thds[i]);
for (auto& th : thds) {
th.Join();
}
gpr_arena_destroy(args.arena);

@ -21,15 +21,18 @@
gpr_cpu_current_cpu()
*/
#include <grpc/support/alloc.h>
#include <grpc/support/cpu.h>
#include <new>
#include <stdio.h>
#include <string.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include <stdio.h>
#include <string.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
/* Test structure is essentially:
@ -101,7 +104,6 @@ static void cpu_test(void) {
uint32_t i;
int cores_seen = 0;
struct cpu_test ct;
gpr_thd_id* thd;
ct.ncores = gpr_cpu_num_cores();
GPR_ASSERT(ct.ncores > 0);
ct.nthreads = static_cast<int>(ct.ncores) * 3;
@ -112,10 +114,12 @@ static void cpu_test(void) {
ct.is_done = 0;
uint32_t nthreads = ct.ncores * 3;
thd = static_cast<gpr_thd_id*>(gpr_malloc(sizeof(thd[0]) * nthreads));
grpc_core::Thread* thd =
static_cast<grpc_core::Thread*>(gpr_malloc(sizeof(*thd)*nthreads));
for (i = 0; i < nthreads; i++) {
GPR_ASSERT(gpr_thd_new(&thd[i], "grpc_cpu_test", &worker_thread, &ct));
new (&thd[i]) grpc_core::Thread("grpc_cpu_test", &worker_thread, &ct);
thd[i].Start();
}
gpr_mu_lock(&ct.mu);
while (!ct.is_done) {
@ -123,7 +127,8 @@ static void cpu_test(void) {
}
gpr_mu_unlock(&ct.mu);
for (i = 0; i < nthreads; i++) {
gpr_thd_join(thd[i]);
thd[i].Join();
thd[i].~Thread();
}
gpr_free(thd);
fprintf(stderr, "Saw cores [");

@ -18,13 +18,14 @@
#include "src/core/lib/gpr/mpscq.h"
#include <new>
#include <stdlib.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/util/test_config.h"
@ -76,7 +77,7 @@ static void test_mt(void) {
gpr_log(GPR_DEBUG, "test_mt");
gpr_event start;
gpr_event_init(&start);
gpr_thd_id thds[100];
grpc_core::Thread thds[100];
thd_args ta[GPR_ARRAY_SIZE(thds)];
gpr_mpscq q;
gpr_mpscq_init(&q);
@ -84,7 +85,8 @@ static void test_mt(void) {
ta[i].ctr = 0;
ta[i].q = &q;
ta[i].start = &start;
GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_mt_test", test_thread, &ta[i]));
new (&thds[i]) grpc_core::Thread("grpc_mt_test", test_thread, &ta[i]);
thds[i].Start();
}
size_t num_done = 0;
size_t spins = 0;
@ -101,8 +103,8 @@ static void test_mt(void) {
gpr_free(tn);
}
gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, spins);
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
gpr_thd_join(thds[i]);
for (auto& th : thds) {
th.Join();
}
gpr_mpscq_destroy(&q);
}
@ -144,8 +146,8 @@ static void test_mt_multipop(void) {
gpr_log(GPR_DEBUG, "test_mt_multipop");
gpr_event start;
gpr_event_init(&start);
gpr_thd_id thds[100];
gpr_thd_id pull_thds[100];
grpc_core::Thread thds[100];
grpc_core::Thread pull_thds[100];
thd_args ta[GPR_ARRAY_SIZE(thds)];
gpr_mpscq q;
gpr_mpscq_init(&q);
@ -153,8 +155,8 @@ static void test_mt_multipop(void) {
ta[i].ctr = 0;
ta[i].q = &q;
ta[i].start = &start;
GPR_ASSERT(
gpr_thd_new(&thds[i], "grpc_multipop_test", test_thread, &ta[i]));
new (&thds[i]) grpc_core::Thread("grpc_multipop_test", test_thread, &ta[i]);
thds[i].Start();
}
pull_args pa;
pa.ta = ta;
@ -165,16 +167,17 @@ static void test_mt_multipop(void) {
pa.start = &start;
gpr_mu_init(&pa.mu);
for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) {
GPR_ASSERT(
gpr_thd_new(&pull_thds[i], "grpc_multipop_pull", pull_thread, &pa));
new (&pull_thds[i]) grpc_core::Thread("grpc_multipop_pull",
pull_thread, &pa);
pull_thds[i].Start();
}
gpr_event_set(&start, (void*)1);
for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) {
gpr_thd_join(pull_thds[i]);
for (auto& pth: pull_thds) {
pth.Join();
}
gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, pa.spins);
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
gpr_thd_join(thds[i]);
for (auto& th : thds) {
th.Join();
}
gpr_mpscq_destroy(&q);
}

@ -16,24 +16,27 @@
*
*/
/* Test of gpr synchronization support. */
/* Test of gpr spin-lock support. */
#include "src/core/lib/gpr/spinlock.h"
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include <stdio.h>
#include <stdlib.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
/* ------------------------------------------------- */
/* Tests for gpr_spinlock. */
struct test {
int thread_count; /* number of threads */
gpr_thd_id* threads;
grpc_core::Thread* threads;
int64_t iterations; /* number of iterations per thread */
int64_t counter;
@ -46,7 +49,7 @@ struct test {
static struct test* test_new(int threads, int64_t iterations, int incr_step) {
struct test* m = static_cast<struct test*>(gpr_malloc(sizeof(*m)));
m->thread_count = threads;
m->threads = static_cast<gpr_thd_id*>(
m->threads = static_cast<grpc_core::Thread*>(
gpr_malloc(sizeof(*m->threads) * static_cast<size_t>(threads)));
m->iterations = iterations;
m->counter = 0;
@ -66,7 +69,8 @@ static void test_destroy(struct test* m) {
static void test_create_threads(struct test* m, void (*body)(void* arg)) {
int i;
for (i = 0; i != m->thread_count; i++) {
GPR_ASSERT(gpr_thd_new(&m->threads[i], "grpc_create_threads", body, m));
new (&m->threads[i]) grpc_core::Thread("grpc_create_threads", body, m);
m->threads[i].Start();
}
}
@ -74,7 +78,8 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) {
static void test_wait(struct test* m) {
int i;
for (i = 0; i != m->thread_count; i++) {
gpr_thd_join(m->threads[i]);
m->threads[i].Join();
m->threads[i].~Thread();
}
}

@ -18,14 +18,17 @@
/* Test of gpr synchronization support. */
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include "src/core/lib/gpr/thd.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
/* ==================Example use of interface===================
@ -133,8 +136,8 @@ int queue_remove(queue* q, int* head, gpr_timespec abs_deadline) {
/* ------------------------------------------------- */
/* Tests for gpr_mu and gpr_cv, and the queue example. */
struct test {
int threads; /* number of threads */
gpr_thd_id* thread_ids;
int nthreads; /* number of threads */
grpc_core::Thread* threads;
int64_t iterations; /* number of iterations per thread */
int64_t counter;
@ -158,15 +161,15 @@ struct test {
};
/* Return pointer to a new struct test. */
static struct test* test_new(int threads, int64_t iterations, int incr_step) {
static struct test* test_new(int nthreads, int64_t iterations, int incr_step) {
struct test* m = static_cast<struct test*>(gpr_malloc(sizeof(*m)));
m->threads = threads;
m->thread_ids =
static_cast<gpr_thd_id*>(gpr_malloc(sizeof(*m->thread_ids) * threads));
m->nthreads = nthreads;
m->threads =
static_cast<grpc_core::Thread*>(gpr_malloc(sizeof(*m->threads) * nthreads));
m->iterations = iterations;
m->counter = 0;
m->thread_count = 0;
m->done = threads;
m->done = nthreads;
m->incr_step = incr_step;
gpr_mu_init(&m->mu);
gpr_cv_init(&m->cv);
@ -174,7 +177,7 @@ static struct test* test_new(int threads, int64_t iterations, int incr_step) {
queue_init(&m->q);
gpr_stats_init(&m->stats_counter, 0);
gpr_ref_init(&m->refcount, 0);
gpr_ref_init(&m->thread_refcount, threads);
gpr_ref_init(&m->thread_refcount, nthreads);
gpr_event_init(&m->event);
return m;
}
@ -185,15 +188,16 @@ static void test_destroy(struct test* m) {
gpr_cv_destroy(&m->cv);
gpr_cv_destroy(&m->done_cv);
queue_destroy(&m->q);
gpr_free(m->thread_ids);
gpr_free(m->threads);
gpr_free(m);
}
/* Create m->threads threads, each running (*body)(m) */
/* Create m->nthreads threads, each running (*body)(m) */
static void test_create_threads(struct test* m, void (*body)(void* arg)) {
int i;
for (i = 0; i != m->threads; i++) {
GPR_ASSERT(gpr_thd_new(&m->thread_ids[i], "grpc_create_threads", body, m));
for (i = 0; i != m->nthreads; i++) {
new (&m->threads[i]) grpc_core::Thread("grpc_create_threads", body, m);
m->threads[i].Start();
}
}
@ -204,12 +208,13 @@ static void test_wait(struct test* m) {
gpr_cv_wait(&m->done_cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_unlock(&m->mu);
for (int i = 0; i != m->threads; i++) {
gpr_thd_join(m->thread_ids[i]);
for (int i = 0; i != m->nthreads; i++) {
m->threads[i].Join();
m->threads[i].~Thread();
}
}
/* Get an integer thread id in the raneg 0..threads-1 */
/* Get an integer thread id in the raneg 0..nthreads-1 */
static int thread_id(struct test* m) {
int id;
gpr_mu_lock(&m->mu);
@ -251,19 +256,20 @@ static void test(const char* name, void (*body)(void* m),
fprintf(stderr, " %ld", static_cast<long>(iterations));
fflush(stderr);
m = test_new(10, iterations, incr_step);
gpr_thd_id extra_id;
grpc_core::Thread extra_thd;
if (extra != nullptr) {
GPR_ASSERT(gpr_thd_new(&extra_id, name, extra, m));
new (&extra_thd) grpc_core::Thread(name, extra, m);
extra_thd.Start();
m->done++; /* one more thread to wait for */
}
test_create_threads(m, body);
test_wait(m);
if (extra != nullptr) {
gpr_thd_join(extra_id);
extra_thd.Join();
}
if (m->counter != m->threads * m->iterations * m->incr_step) {
if (m->counter != m->nthreads * m->iterations * m->incr_step) {
fprintf(stderr, "counter %ld threads %d iterations %ld\n",
static_cast<long>(m->counter), m->threads,
static_cast<long>(m->counter), m->nthreads,
static_cast<long>(m->iterations));
fflush(stderr);
GPR_ASSERT(0);
@ -305,7 +311,7 @@ static void inctry(void* v /*=m*/) {
mark_thread_done(m);
}
/* Increment counter only when (m->counter%m->threads)==m->thread_id; then mark
/* Increment counter only when (m->counter%m->nthreads)==m->thread_id; then mark
thread as done. */
static void inc_by_turns(void* v /*=m*/) {
struct test* m = static_cast<struct test*>(v);
@ -313,7 +319,7 @@ static void inc_by_turns(void* v /*=m*/) {
int id = thread_id(m);
for (i = 0; i != m->iterations; i++) {
gpr_mu_lock(&m->mu);
while ((m->counter % m->threads) != id) {
while ((m->counter % m->nthreads) != id) {
gpr_cv_wait(&m->cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
m->counter++;
@ -378,12 +384,12 @@ static void many_producers(void* v /*=m*/) {
mark_thread_done(m);
}
/* Consume elements from m->q until m->threads*m->iterations are seen,
/* Consume elements from m->q until m->nthreads*m->iterations are seen,
wait an extra second to confirm that no more elements are arriving,
then mark thread as done. */
static void consumer(void* v /*=m*/) {
struct test* m = static_cast<struct test*>(v);
int64_t n = m->iterations * m->threads;
int64_t n = m->iterations * m->nthreads;
int64_t i;
int value;
for (i = 0; i != n; i++) {
@ -433,11 +439,11 @@ static void refinc(void* v /*=m*/) {
}
/* Wait until m->event is set to (void *)1, then decrement m->refcount by 1
(m->threads * m->iterations * m->incr_step) times, and ensure that the last
(m->nthreads * m->iterations * m->incr_step) times, and ensure that the last
decrement caused the counter to reach zero, then mark thread as done. */
static void refcheck(void* v /*=m*/) {
struct test* m = static_cast<struct test*>(v);
int64_t n = m->iterations * m->threads * m->incr_step;
int64_t n = m->iterations * m->nthreads * m->incr_step;
int64_t i;
GPR_ASSERT(gpr_event_wait(&m->event, gpr_inf_future(GPR_CLOCK_REALTIME)) ==
(void*)1);

@ -26,7 +26,6 @@
#include <stdlib.h>
#include <string.h>
#include "src/core/lib/gpr/thd.h"
#include "test/core/util/test_config.h"
static void to_fp(void* arg, const char* buf, size_t len) {

@ -18,13 +18,16 @@
/* Test of gpr thread local storage support. */
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/tls.h"
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gpr/tls.h"
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
#define NUM_THREADS 100
@ -46,18 +49,18 @@ static void thd_body(void* arg) {
/* ------------------------------------------------- */
int main(int argc, char* argv[]) {
int i;
gpr_thd_id threads[NUM_THREADS];
grpc_core::Thread threads[NUM_THREADS];
grpc_test_init(argc, argv);
gpr_tls_init(&test_var);
for (i = 0; i < NUM_THREADS; i++) {
gpr_thd_new(&threads[i], "grpc_tls_test", thd_body, nullptr);
for (auto& th : threads) {
new (&th) grpc_core::Thread("grpc_tls_test", thd_body, nullptr);
th.Start();
}
for (i = 0; i < NUM_THREADS; i++) {
gpr_thd_join(threads[i]);
for (auto& th : threads) {
th.Join();
}
gpr_tls_destroy(&test_var);

@ -26,7 +26,6 @@
#include <stdlib.h>
#include <cstring>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/abstract.h"
#include "test/core/util/test_config.h"

@ -18,13 +18,15 @@
/* Test of gpr thread support. */
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include <stdio.h>
#include <stdlib.h>
#include "test/core/util/test_config.h"
@ -51,23 +53,23 @@ static void thd_body1(void* v) {
/* Test that we can create a number of threads, wait for them, and join them. */
static void test1(void) {
int i;
gpr_thd_id thds[NUM_THREADS];
grpc_core::Thread thds[NUM_THREADS];
struct test t;
gpr_mu_init(&t.mu);
gpr_cv_init(&t.done_cv);
t.n = NUM_THREADS;
t.is_done = 0;
for (i = 0; i < NUM_THREADS; i++) {
GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_thread_body1_test", &thd_body1, &t));
for (auto& th: thds) {
new (&th) grpc_core::Thread("grpc_thread_body1_test", &thd_body1, &t);
th.Start();
}
gpr_mu_lock(&t.mu);
while (!t.is_done) {
gpr_cv_wait(&t.done_cv, &t.mu, gpr_inf_future(GPR_CLOCK_REALTIME));
}
gpr_mu_unlock(&t.mu);
for (i = 0; i < NUM_THREADS; i++) {
gpr_thd_join(thds[i]);
for (auto& th: thds) {
th.Join();
}
GPR_ASSERT(t.n == 0);
}
@ -76,14 +78,16 @@ static void thd_body2(void* v) {}
/* Test that we can create a number of threads and join them. */
static void test2(void) {
int i;
gpr_thd_id thds[NUM_THREADS];
for (i = 0; i < NUM_THREADS; i++) {
GPR_ASSERT(
gpr_thd_new(&thds[i], "grpc_thread_body2_test", &thd_body2, nullptr));
grpc_core::Thread thds[NUM_THREADS];
for (auto& th: thds) {
bool ok;
new (&th) grpc_core::Thread("grpc_thread_body2_test", &thd_body2,
nullptr, &ok);
GPR_ASSERT(ok);
th.Start();
}
for (i = 0; i < NUM_THREADS; i++) {
gpr_thd_join(thds[i]);
for (auto& th: thds) {
th.Join();
}
}

@ -35,7 +35,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@ -230,9 +230,11 @@ static bool client_ssl_test(char* server_alpn_preferred) {
GPR_ASSERT(server_socket > 0 && port > 0);
// Launch the TLS server thread.
gpr_thd_id thdid;
server_args args = {server_socket, server_alpn_preferred};
GPR_ASSERT(gpr_thd_new(&thdid, "grpc_client_ssl_test", server_thread, &args));
bool ok;
grpc_core::Thread thd("grpc_client_ssl_test", server_thread, &args, &ok);
GPR_ASSERT(ok);
thd.Start();
// Load key pair and establish client SSL credentials.
grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
@ -300,7 +302,7 @@ static bool client_ssl_test(char* server_alpn_preferred) {
grpc_slice_unref(key_slice);
grpc_slice_unref(ca_slice);
gpr_thd_join(thdid);
thd.Join();
grpc_shutdown();

@ -30,7 +30,6 @@
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"

@ -30,7 +30,6 @@
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"

@ -32,7 +32,7 @@
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@ -138,8 +138,10 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len,
gpr_event_init(&client_handshake_complete);
// Launch the gRPC server thread.
gpr_thd_id thdid;
GPR_ASSERT(gpr_thd_new(&thdid, "grpc_ssl_test", server_thread, &port));
bool ok;
grpc_core::Thread thd("grpc_ssl_test", server_thread, &port, &ok);
GPR_ASSERT(ok);
thd.Start();
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
@ -232,7 +234,7 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len,
EVP_cleanup();
close(sock);
gpr_thd_join(thdid);
thd.Join();
grpc_shutdown();

@ -26,7 +26,6 @@
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"

@ -18,11 +18,13 @@
#include "src/core/lib/iomgr/combiner.h"
#include <new>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/util/test_config.h"
@ -97,19 +99,20 @@ static void test_execute_many(void) {
gpr_log(GPR_DEBUG, "test_execute_many");
grpc_combiner* lock = grpc_combiner_create();
gpr_thd_id thds[100];
grpc_core::Thread thds[100];
thd_args ta[GPR_ARRAY_SIZE(thds)];
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
ta[i].ctr = 0;
ta[i].lock = lock;
gpr_event_init(&ta[i].done);
GPR_ASSERT(
gpr_thd_new(&thds[i], "grpc_execute_many", execute_many_loop, &ta[i]));
new (&thds[i]) grpc_core::Thread("grpc_execute_many",
execute_many_loop, &ta[i]);
thds[i].Start();
}
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
GPR_ASSERT(gpr_event_wait(&ta[i].done,
gpr_inf_future(GPR_CLOCK_REALTIME)) != nullptr);
gpr_thd_join(thds[i]);
thds[i].Join();
}
grpc_core::ExecCtx exec_ctx;
GRPC_COMBINER_UNREF(lock, "test_execute_many");

@ -24,7 +24,6 @@
#include <string.h>
#include "src/core/lib/gpr/thd.h"
#include "test/core/util/test_config.h"
static void test_set_get_int() {

@ -30,7 +30,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"

@ -18,6 +18,7 @@
#include "src/core/lib/iomgr/resolve_address.h"
#include <new>
#include <string.h>
#include <sys/un.h>
@ -27,7 +28,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
@ -38,7 +39,7 @@ static gpr_timespec test_deadline(void) {
}
typedef struct args_struct {
gpr_thd_id id;
grpc_core::Thread thd;
gpr_event ev;
grpc_resolved_addresses* addrs;
gpr_atm done_atm;
@ -60,7 +61,9 @@ void args_init(args_struct* args) {
void args_finish(args_struct* args) {
GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline()));
gpr_thd_join(args->id);
args->thd.Join();
// Don't need to explicitly destruct args->thd since
// args is actually going to be destructed, not just freed
grpc_resolved_addresses_destroy(args->addrs);
grpc_pollset_set_del_pollset(args->pollset_set, args->pollset);
grpc_pollset_set_destroy(args->pollset_set);
@ -103,7 +106,8 @@ static void actually_poll(void* argsp) {
static void poll_pollset_until_request_done(args_struct* args) {
gpr_atm_rel_store(&args->done_atm, 0);
gpr_thd_new(&args->id, "grpc_poll_pollset", actually_poll, args);
new (&args->thd) grpc_core::Thread("grpc_poll_pollset", actually_poll, args);
args->thd.Start();
}
static void must_succeed(void* argsp, grpc_error* err) {

@ -26,7 +26,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/iomgr_posix.h"
@ -103,7 +103,6 @@ void test_poll_cv_trigger(void) {
grpc_wakeup_fd cvfd1, cvfd2, cvfd3;
struct pollfd pfds[6];
poll_args pargs;
gpr_thd_id t_id;
GPR_ASSERT(grpc_wakeup_fd_init(&cvfd1) == GRPC_ERROR_NONE);
GPR_ASSERT(grpc_wakeup_fd_init(&cvfd2) == GRPC_ERROR_NONE);
@ -134,11 +133,12 @@ void test_poll_cv_trigger(void) {
pargs.timeout = 1000;
pargs.result = -2;
gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs);
{
grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
thd.Start();
// Wakeup wakeup_fd not listening for events
GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd1) == GRPC_ERROR_NONE);
gpr_thd_join(t_id);
thd.Join();
GPR_ASSERT(pargs.result == 0);
GPR_ASSERT(pfds[0].revents == 0);
GPR_ASSERT(pfds[1].revents == 0);
@ -146,13 +146,16 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
}
{
// Pollin on socket fd
pargs.timeout = -1;
pargs.result = -2;
gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs);
grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
thd.Start();
trigger_socket_event();
gpr_thd_join(t_id);
thd.Join();
GPR_ASSERT(pargs.result == 1);
GPR_ASSERT(pfds[0].revents == 0);
GPR_ASSERT(pfds[1].revents == 0);
@ -160,13 +163,16 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
}
{
// Pollin on wakeup fd
reset_socket_event();
pargs.result = -2;
gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs);
grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
thd.Start();
GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd2) == GRPC_ERROR_NONE);
gpr_thd_join(t_id);
thd.Join();
GPR_ASSERT(pargs.result == 1);
GPR_ASSERT(pfds[0].revents == 0);
@ -175,11 +181,14 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
}
{
// Pollin on wakeupfd before poll()
pargs.result = -2;
gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs);
gpr_thd_join(t_id);
grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
thd.Start();
thd.Join();
GPR_ASSERT(pargs.result == 1);
GPR_ASSERT(pfds[0].revents == 0);
@ -188,15 +197,18 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
}
{
// No Events
pargs.result = -2;
pargs.timeout = 1000;
reset_socket_event();
GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd1) == GRPC_ERROR_NONE);
GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd2) == GRPC_ERROR_NONE);
gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs);
gpr_thd_join(t_id);
grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
thd.Start();
thd.Join();
GPR_ASSERT(pargs.result == 0);
GPR_ASSERT(pfds[0].revents == 0);
@ -205,6 +217,7 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
}
}
int main(int argc, char** argv) {

@ -38,7 +38,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"

@ -27,7 +27,6 @@
#include "src/core/ext/census/census_interface.h"
#include "src/core/ext/census/census_rpc_stats.h"
#include "src/core/ext/census/census_tracing.h"
#include "src/core/lib/gpr/thd.h"
#include "test/core/util/test_config.h"
/* Ensure all possible state transitions are called without causing problem */

@ -26,7 +26,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/compression/message_compress.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "test/core/util/test_config.h"

@ -18,11 +18,13 @@
#include "src/core/lib/surface/completion_queue.h"
#include <new>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"
@ -78,7 +80,7 @@ static void test_too_many_plucks(void) {
grpc_completion_queue* cc;
void* tags[GRPC_MAX_COMPLETION_QUEUE_PLUCKERS];
grpc_cq_completion completions[GPR_ARRAY_SIZE(tags)];
gpr_thd_id thread_ids[GPR_ARRAY_SIZE(tags)];
grpc_core::Thread threads[GPR_ARRAY_SIZE(tags)];
struct thread_state thread_states[GPR_ARRAY_SIZE(tags)];
grpc_core::ExecCtx exec_ctx;
unsigned i, j;
@ -94,8 +96,9 @@ static void test_too_many_plucks(void) {
}
thread_states[i].cc = cc;
thread_states[i].tag = tags[i];
gpr_thd_new(thread_ids + i, "grpc_pluck_test", pluck_one,
thread_states + i);
new (&threads[i]) grpc_core::Thread("grpc_pluck_test", pluck_one,
thread_states + i);
threads[i].Start();
}
/* wait until all other threads are plucking */
@ -111,8 +114,8 @@ static void test_too_many_plucks(void) {
nullptr, &completions[i]);
}
for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
gpr_thd_join(thread_ids[i]);
for (auto& th : threads) {
th.Join();
}
shutdown_and_destroy(cc);
@ -218,8 +221,9 @@ static void test_threading(size_t producers, size_t consumers) {
"test_threading", producers, consumers);
/* start all threads: they will wait for phase1 */
gpr_thd_id* ids = static_cast<gpr_thd_id*>(
gpr_malloc(sizeof(*ids) * (producers + consumers)));
grpc_core::Thread* threads =
reinterpret_cast<grpc_core::Thread*>(
gpr_malloc(sizeof(*threads) * (producers + consumers)));
for (i = 0; i < producers + consumers; i++) {
gpr_event_init(&options[i].on_started);
gpr_event_init(&options[i].on_phase1_done);
@ -229,9 +233,14 @@ static void test_threading(size_t producers, size_t consumers) {
options[i].events_triggered = 0;
options[i].cc = cc;
options[i].id = optid++;
GPR_ASSERT(gpr_thd_new(
&ids[i], i < producers ? "grpc_producer" : "grpc_consumer",
i < producers ? producer_thread : consumer_thread, options + i));
bool ok;
new (&threads[i]) grpc_core::Thread(
i < producers ? "grpc_producer" : "grpc_consumer",
i < producers ? producer_thread : consumer_thread,
options + i, &ok);
GPR_ASSERT(ok);
threads[i].Start();
gpr_event_wait(&options[i].on_started, ten_seconds_time());
}
@ -265,9 +274,10 @@ static void test_threading(size_t producers, size_t consumers) {
grpc_completion_queue_destroy(cc);
for (i = 0; i < producers + consumers; i++) {
gpr_thd_join(ids[i]);
threads[i].Join();
threads[i].~Thread();
}
gpr_free(ids);
gpr_free(threads);
/* verify that everything was produced and consumed */
for (i = 0; i < producers + consumers; i++) {

@ -22,6 +22,7 @@
headers. Therefore, sockaddr.h must always be included first */
#include "src/core/lib/iomgr/sockaddr.h"
#include <new>
#include <memory.h>
#include <stdio.h>
@ -30,7 +31,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/resolve_address.h"
@ -172,21 +173,22 @@ int run_concurrent_connectivity_test() {
grpc_init();
gpr_thd_id threads[NUM_THREADS];
gpr_thd_id server;
char* localhost = gpr_strdup("localhost:54321");
/* First round, no server */
{
gpr_log(GPR_DEBUG, "Wave 1");
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_new(&threads[i], "grpc_wave_1", create_loop_destroy, localhost);
char* localhost = gpr_strdup("localhost:54321");
grpc_core::Thread threads[NUM_THREADS];
for (auto& th : threads) {
new (&th) grpc_core::Thread("grpc_wave_1", create_loop_destroy, localhost);
th.Start();
}
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_join(threads[i]);
for (auto& th : threads) {
th.Join();
}
gpr_free(localhost);
}
{
/* Second round, actual grpc server */
gpr_log(GPR_DEBUG, "Wave 2");
int port = grpc_pick_unused_port_or_die();
@ -196,44 +198,53 @@ int run_concurrent_connectivity_test() {
args.cq = grpc_completion_queue_create_for_next(nullptr);
grpc_server_register_completion_queue(args.server, args.cq, nullptr);
grpc_server_start(args.server);
gpr_thd_new(&server, "grpc_wave_2_server", server_thread, &args);
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_new(&threads[i], "grpc_wave_2", create_loop_destroy, args.addr);
}
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_join(threads[i]);
grpc_core::Thread server2("grpc_wave_2_server", server_thread, &args);
server2.Start();
grpc_core::Thread threads[NUM_THREADS];
for (auto& th : threads) {
new (&th) grpc_core::Thread("grpc_wave_2", create_loop_destroy, args.addr);
th.Start();
}
for (auto& th : threads) {
th.Join();
}
grpc_server_shutdown_and_notify(args.server, args.cq, tag(0xd1e));
gpr_thd_join(server);
server2.Join();
grpc_server_destroy(args.server);
grpc_completion_queue_destroy(args.cq);
gpr_free(args.addr);
}
{
/* Third round, bogus tcp server */
gpr_log(GPR_DEBUG, "Wave 3");
args.pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
grpc_pollset_init(args.pollset, &args.mu);
gpr_event_init(&args.ready);
gpr_thd_new(&server, "grpc_wave_3_server", bad_server_thread, &args);
grpc_core::Thread server3("grpc_wave_3_server", bad_server_thread, &args);
server3.Start();
gpr_event_wait(&args.ready, gpr_inf_future(GPR_CLOCK_MONOTONIC));
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_new(&threads[i], "grpc_wave_3", create_loop_destroy, args.addr);
grpc_core::Thread threads[NUM_THREADS];
for (auto& th : threads) {
new (&th) grpc_core::Thread("grpc_wave_3", create_loop_destroy, args.addr);
th.Start();
}
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_join(threads[i]);
for (auto& th : threads) {
th.Join();
}
gpr_atm_rel_store(&args.stop, 1);
gpr_thd_join(server);
server3.Join();
{
grpc_core::ExecCtx exec_ctx;
grpc_pollset_shutdown(
args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset,
grpc_schedule_on_exec_ctx));
}
}
grpc_shutdown();
return 0;
@ -272,16 +283,17 @@ void watches_with_short_timeouts(void* addr) {
int run_concurrent_watches_with_short_timeouts_test() {
grpc_init();
gpr_thd_id threads[NUM_THREADS];
grpc_core::Thread threads[NUM_THREADS];
char* localhost = gpr_strdup("localhost:54321");
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_new(&threads[i], "grpc_short_watches", watches_with_short_timeouts,
localhost);
for (auto& th : threads) {
new (&th) grpc_core::Thread("grpc_short_watches",
watches_with_short_timeouts, localhost);
th.Start();
}
for (size_t i = 0; i < NUM_THREADS; ++i) {
gpr_thd_join(threads[i]);
for (auto& th : threads) {
th.Join();
}
gpr_free(localhost);

@ -23,7 +23,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"

@ -23,7 +23,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
@ -67,8 +67,8 @@ static void run_test(const test_fixture* fixture) {
grpc_server_start(server);
server_thread_args sta = {server, server_cq};
gpr_thd_id server_thread;
gpr_thd_new(&server_thread, "grpc_server", server_thread_func, &sta);
grpc_core::Thread server_thread("grpc_server", server_thread_func, &sta);
server_thread.Start();
grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr);
grpc_channel* channels[NUM_CONNECTIONS];
@ -93,7 +93,7 @@ static void run_test(const test_fixture* fixture) {
}
grpc_server_shutdown_and_notify(server, server_cq, nullptr);
gpr_thd_join(server_thread);
server_thread.Join();
grpc_completion_queue_shutdown(server_cq);
grpc_completion_queue_shutdown(cq);

@ -24,7 +24,6 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/security/transport/tsi_error.h"
#include "test/core/tsi/transport_security_test_lib.h"

@ -35,7 +35,7 @@
#include <grpc/support/time.h>
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/sockaddr.h"

@ -32,7 +32,7 @@
#include <grpc/grpc.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"

@ -33,7 +33,6 @@
#include <grpc/support/time.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gpr/tls.h"
#include "src/core/lib/iomgr/port.h"
#include "src/proto/grpc/health/v1/health.grpc.pb.h"

@ -26,7 +26,6 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"

@ -38,7 +38,6 @@
#include "src/core/ext/filters/client_channel/subchannel_index.h"
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"

@ -35,7 +35,6 @@
#include <grpc/support/time.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"

@ -33,7 +33,6 @@
#include <grpc/grpc.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/cpp/common/channel_filter.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"

@ -31,7 +31,6 @@
#include <grpc/grpc.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"

@ -34,7 +34,6 @@
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/sockaddr.h"

@ -29,7 +29,6 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "src/proto/grpc/testing/echo_mock.grpc.pb.h"

@ -26,7 +26,6 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"

@ -29,7 +29,6 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"

@ -33,7 +33,6 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"

@ -28,7 +28,6 @@
#include <grpc/grpc.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/api_trace.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"

@ -1030,7 +1030,6 @@ src/core/lib/gpr/murmur_hash.h \
src/core/lib/gpr/spinlock.h \
src/core/lib/gpr/string.h \
src/core/lib/gpr/string_windows.h \
src/core/lib/gpr/thd.h \
src/core/lib/gpr/time_precise.h \
src/core/lib/gpr/tls.h \
src/core/lib/gpr/tls_gcc.h \
@ -1049,6 +1048,7 @@ src/core/lib/gprpp/memory.h \
src/core/lib/gprpp/orphanable.h \
src/core/lib/gprpp/ref_counted.h \
src/core/lib/gprpp/ref_counted_ptr.h \
src/core/lib/gprpp/thd.h \
src/core/lib/http/format_request.h \
src/core/lib/http/httpcli.h \
src/core/lib/http/parser.h \

@ -1094,9 +1094,6 @@ src/core/lib/gpr/string_windows.h \
src/core/lib/gpr/sync.cc \
src/core/lib/gpr/sync_posix.cc \
src/core/lib/gpr/sync_windows.cc \
src/core/lib/gpr/thd.h \
src/core/lib/gpr/thd_posix.cc \
src/core/lib/gpr/thd_windows.cc \
src/core/lib/gpr/time.cc \
src/core/lib/gpr/time_posix.cc \
src/core/lib/gpr/time_precise.cc \
@ -1125,6 +1122,9 @@ src/core/lib/gprpp/memory.h \
src/core/lib/gprpp/orphanable.h \
src/core/lib/gprpp/ref_counted.h \
src/core/lib/gprpp/ref_counted_ptr.h \
src/core/lib/gprpp/thd.h \
src/core/lib/gprpp/thd_posix.cc \
src/core/lib/gprpp/thd_windows.cc \
src/core/lib/http/format_request.cc \
src/core/lib/http/format_request.h \
src/core/lib/http/httpcli.cc \

@ -764,7 +764,7 @@
"language": "c",
"name": "gpr_thd_test",
"src": [
"test/core/gpr/thd_test.cc"
"test/core/gprpp/thd_test.cc"
],
"third_party": false,
"type": "target"
@ -8223,8 +8223,6 @@
"src/core/lib/gpr/sync.cc",
"src/core/lib/gpr/sync_posix.cc",
"src/core/lib/gpr/sync_windows.cc",
"src/core/lib/gpr/thd_posix.cc",
"src/core/lib/gpr/thd_windows.cc",
"src/core/lib/gpr/time.cc",
"src/core/lib/gpr/time_posix.cc",
"src/core/lib/gpr/time_precise.cc",
@ -8234,6 +8232,8 @@
"src/core/lib/gpr/tmpfile_posix.cc",
"src/core/lib/gpr/tmpfile_windows.cc",
"src/core/lib/gpr/wrap_memcpy.cc",
"src/core/lib/gprpp/thd_posix.cc",
"src/core/lib/gprpp/thd_windows.cc",
"src/core/lib/profiling/basic_timers.cc",
"src/core/lib/profiling/stap_timers.cc"
],
@ -8271,7 +8271,6 @@
"src/core/lib/gpr/spinlock.h",
"src/core/lib/gpr/string.h",
"src/core/lib/gpr/string_windows.h",
"src/core/lib/gpr/thd.h",
"src/core/lib/gpr/time_precise.h",
"src/core/lib/gpr/tls.h",
"src/core/lib/gpr/tls_gcc.h",
@ -8285,6 +8284,7 @@
"src/core/lib/gprpp/atomic_with_std.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/thd.h",
"src/core/lib/profiling/timers.h"
],
"is_filegroup": true,
@ -8317,7 +8317,6 @@
"src/core/lib/gpr/spinlock.h",
"src/core/lib/gpr/string.h",
"src/core/lib/gpr/string_windows.h",
"src/core/lib/gpr/thd.h",
"src/core/lib/gpr/time_precise.h",
"src/core/lib/gpr/tls.h",
"src/core/lib/gpr/tls_gcc.h",
@ -8331,6 +8330,7 @@
"src/core/lib/gprpp/atomic_with_std.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/thd.h",
"src/core/lib/profiling/timers.h"
],
"third_party": false,

Loading…
Cancel
Save