diff options
106 files changed, 1094 insertions, 950 deletions
@@ -527,9 +527,6 @@ 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.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", @@ -539,6 +536,8 @@ grpc_cc_library( "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", ], @@ -552,7 +551,6 @@ 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/gpr/time_precise.h", "src/core/lib/gpr/tls.h", "src/core/lib/gpr/tls_gcc.h", @@ -560,6 +558,10 @@ grpc_cc_library( "src/core/lib/gpr/tls_pthread.h", "src/core/lib/gpr/tmpfile.h", "src/core/lib/gpr/useful.h", + "src/core/lib/gprpp/abstract.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", ], language = "c++", @@ -602,16 +604,6 @@ grpc_cc_library( ) grpc_cc_library( - name = "gpr++_base", - language = "c++", - public_hdrs = [ - "src/core/lib/gprpp/abstract.h", - "src/core/lib/gprpp/manual_constructor.h", - "src/core/lib/gprpp/memory.h", - ], -) - -grpc_cc_library( name = "atomic", hdrs = [ "src/core/lib/gprpp/atomic_with_atm.h", @@ -633,7 +625,7 @@ grpc_cc_library( "src/core/lib/gprpp/inlined_vector.h", ], deps = [ - "gpr++_base", + "gpr_base", ], ) @@ -649,7 +641,7 @@ grpc_cc_library( public_hdrs = ["src/core/lib/gprpp/orphanable.h"], deps = [ "debug_location", - "gpr++_base", + "gpr_base", "grpc_trace", "ref_counted_ptr", ], @@ -661,7 +653,7 @@ grpc_cc_library( public_hdrs = ["src/core/lib/gprpp/ref_counted.h"], deps = [ "debug_location", - "gpr++_base", + "gpr_base", "grpc_trace", "ref_counted_ptr", ], @@ -672,7 +664,7 @@ grpc_cc_library( language = "c++", public_hdrs = ["src/core/lib/gprpp/ref_counted_ptr.h"], deps = [ - "gpr++_base", + "gpr_base", ], ) @@ -943,13 +935,12 @@ grpc_cc_library( language = "c++", public_hdrs = GRPC_PUBLIC_HDRS, deps = [ - "gpr++_base", "gpr_base", "grpc_codegen", "grpc_trace", + "inlined_vector", "ref_counted", "ref_counted_ptr", - "inlined_vector", ], ) @@ -1425,7 +1416,7 @@ grpc_cc_library( ], language = "c++", deps = [ - "gpr++_base", + "gpr_base", "grpc_base", "grpc_http_filters", "grpc_transport_chttp2_alpn", diff --git a/CMakeLists.txt b/CMakeLists.txt index 303a2f465f..ab4fa8a253 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -659,9 +659,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.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 @@ -671,6 +668,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 ) @@ -6284,7 +6283,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 ) @@ -2920,9 +2920,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.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 \ @@ -2932,6 +2929,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 \ @@ -11078,7 +11077,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) @@ -11098,7 +11097,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) diff --git a/build.yaml b/build.yaml index 56f1b40d63..e2d194041a 100644 --- a/build.yaml +++ b/build.yaml @@ -59,9 +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.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 @@ -71,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: @@ -104,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 @@ -118,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 @@ -2330,7 +2329,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,9 +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.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 \ @@ -77,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 \ @@ -629,6 +628,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) diff --git a/config.w32 b/config.w32 index 2875c10f3b..5e41295cbf 100644 --- a/config.w32 +++ b/config.w32 @@ -42,9 +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.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 " + @@ -54,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 " + @@ -641,6 +640,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"); diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index e7b0e8c5ea..821c16da45 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -220,7 +220,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', @@ -234,6 +233,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', @@ -475,7 +475,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', @@ -489,6 +488,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', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index dafd50a095..6c6c76991c 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -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,9 +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.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', @@ -245,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', @@ -726,7 +725,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', @@ -740,6 +738,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', diff --git a/grpc.gemspec b/grpc.gemspec index 090e73041f..fbe70aa795 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -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,9 +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.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 ) @@ -136,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,9 +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.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', @@ -199,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', ], diff --git a/package.xml b/package.xml index 61fcd259a8..db03230eba 100644 --- a/package.xml +++ b/package.xml @@ -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,9 +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.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" /> @@ -143,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" /> diff --git a/src/core/lib/gpr/thd.cc b/src/core/lib/gpr/thd.cc deleted file mode 100644 index b5341c41b4..0000000000 --- a/src/core/lib/gpr/thd.cc +++ /dev/null @@ -1,51 +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. - * - */ - -/* Platform-independent features for gpr threads. */ - -#include <grpc/support/port_platform.h> - -#include "src/core/lib/gpr/thd.h" - -#include <string.h> - -enum { GPR_THD_JOINABLE = 1 }; - -gpr_thd_options gpr_thd_options_default(void) { - gpr_thd_options options; - memset(&options, 0, sizeof(options)); - return options; -} - -void gpr_thd_options_set_detached(gpr_thd_options* options) { - options->flags &= ~GPR_THD_JOINABLE; -} - -void gpr_thd_options_set_joinable(gpr_thd_options* options) { - options->flags |= GPR_THD_JOINABLE; -} - -int gpr_thd_options_is_detached(const gpr_thd_options* options) { - if (!options) return 1; - return (options->flags & GPR_THD_JOINABLE) == 0; -} - -int gpr_thd_options_is_joinable(const gpr_thd_options* options) { - if (!options) return 0; - return (options->flags & GPR_THD_JOINABLE) == GPR_THD_JOINABLE; -} diff --git a/src/core/lib/gpr/thd.h b/src/core/lib/gpr/thd.h deleted file mode 100644 index 920b336708..0000000000 --- a/src/core/lib/gpr/thd.h +++ /dev/null @@ -1,72 +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> - -/** Thread creation options. */ -typedef struct { - int flags; /** Opaque field. Get and set with accessors below. */ -} gpr_thd_options; - -/** 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. - If options==NULL, default options are used. - The thread is immediately runnable, and exits when (*thd_body)() returns. */ -int gpr_thd_new(gpr_thd_id* t, const char* thd_name, - void (*thd_body)(void* arg), void* arg, - const gpr_thd_options* options); - -/** Return a gpr_thd_options struct with all fields set to defaults. */ -gpr_thd_options gpr_thd_options_default(void); - -/** Set the thread to become detached on startup - this is the default. */ -void gpr_thd_options_set_detached(gpr_thd_options* options); - -/** Set the thread to become joinable - mutually exclusive with detached. */ -void gpr_thd_options_set_joinable(gpr_thd_options* options); - -/** Returns non-zero if the option detached is set. */ -int gpr_thd_options_is_detached(const gpr_thd_options* options); - -/** Returns non-zero if the option joinable is set. */ -int gpr_thd_options_is_joinable(const gpr_thd_options* options); - -/** Blocks until the specified thread properly terminates. - Calling this on a detached thread has unpredictable results. */ -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 */ diff --git a/src/core/lib/gpr/thd_posix.cc b/src/core/lib/gpr/thd_posix.cc deleted file mode 100644 index fcd174bfba..0000000000 --- a/src/core/lib/gpr/thd_posix.cc +++ /dev/null @@ -1,154 +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. - * - */ - -/* Posix implementation for gpr threads. */ - -#include <grpc/support/port_platform.h> - -#ifdef GPR_POSIX_SYNC - -#include "src/core/lib/gpr/thd.h" - -#include <grpc/support/alloc.h> -#include <grpc/support/log.h> -#include <grpc/support/sync.h> -#include <grpc/support/thd_id.h> -#include <pthread.h> -#include <stdlib.h> -#include <string.h> - -#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; - -struct thd_arg { - 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(); - -/* 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 - } - (*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, - const gpr_thd_options* options) { - int thread_started; - 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))); - GPR_ASSERT(a != nullptr); - a->body = thd_body; - a->arg = arg; - a->name = thd_name; - inc_thd_count(); - - GPR_ASSERT(pthread_attr_init(&attr) == 0); - if (gpr_thd_options_is_detached(options)) { - GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == - 0); - } else { - GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) == - 0); - } - thread_started = (pthread_create(&p, &attr, &thread_body, a) == 0); - GPR_ASSERT(pthread_attr_destroy(&attr) == 0); - if (!thread_started) { - /* 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); - } -} - -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() { - 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) { - gpr_mu_lock(&g_mu); - g_awaiting_threads = 1; - int res = 0; - if (g_thread_count > 0) { - res = gpr_cv_wait(&g_cv, &g_mu, deadline); - } - g_awaiting_threads = 0; - gpr_mu_unlock(&g_mu); - return res == 0; -} - -#endif /* GPR_POSIX_SYNC */ diff --git a/src/core/lib/gpr/thd_windows.cc b/src/core/lib/gpr/thd_windows.cc deleted file mode 100644 index b467bd2662..0000000000 --- a/src/core/lib/gpr/thd_windows.cc +++ /dev/null @@ -1,107 +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. - * - */ - -/* Windows implementation for gpr threads. */ - -#include <grpc/support/port_platform.h> - -#ifdef GPR_WINDOWS - -#include "src/core/lib/gpr/thd.h" - -#include <grpc/support/alloc.h> -#include <grpc/support/log.h> -#include <grpc/support/thd_id.h> -#include <string.h> - -#if defined(_MSC_VER) -#define thread_local __declspec(thread) -#elif defined(__GNUC__) -#define thread_local __thread -#else -#error "Unknown compiler - please file a bug report" -#endif - -struct thd_info { - void (*body)(void* arg); /* body of a thread */ - void* arg; /* argument to a thread */ - HANDLE join_event; /* if joinable, the join event */ - int joinable; /* true if not detached */ -}; - -static thread_local struct thd_info* g_thd_info; - -/* Destroys a thread info */ -static void destroy_thread(struct thd_info* t) { - if (t->joinable) CloseHandle(t->join_event); - gpr_free(t); -} - -void gpr_thd_init(void) {} - -/* Body of every thread started via gpr_thd_new. */ -static DWORD WINAPI thread_body(void* v) { - g_thd_info = (struct thd_info*)v; - g_thd_info->body(g_thd_info->arg); - if (g_thd_info->joinable) { - BOOL ret = SetEvent(g_thd_info->join_event); - GPR_ASSERT(ret); - } else { - destroy_thread(g_thd_info); - } - return 0; -} - -int gpr_thd_new(gpr_thd_id* t, const char* thd_name, - void (*thd_body)(void* arg), void* arg, - const gpr_thd_options* options) { - HANDLE handle; - struct thd_info* info = (struct thd_info*)gpr_malloc(sizeof(*info)); - info->body = thd_body; - info->arg = arg; - *t = 0; - if (gpr_thd_options_is_joinable(options)) { - info->joinable = 1; - info->join_event = CreateEvent(NULL, FALSE, FALSE, NULL); - if (info->join_event == NULL) { - gpr_free(info); - return 0; - } - } else { - info->joinable = 0; - } - handle = CreateThread(NULL, 64 * 1024, thread_body, info, 0, NULL); - if (handle == NULL) { - destroy_thread(info); - } else { - *t = (gpr_thd_id)info; - CloseHandle(handle); - } - return handle != NULL; -} - -gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)g_thd_info; } - -void gpr_thd_join(gpr_thd_id t) { - struct thd_info* info = (struct thd_info*)t; - DWORD ret = WaitForSingleObject(info->join_event, INFINITE); - GPR_ASSERT(ret == WAIT_OBJECT_0); - destroy_thread(info); -} - -#endif /* GPR_WINDOWS */ diff --git a/src/core/lib/gprpp/thd.h b/src/core/lib/gprpp/thd.h new file mode 100644 index 0000000000..05c7ded45f --- /dev/null +++ b/src/core/lib/gprpp/thd.h @@ -0,0 +1,135 @@ +/* + * + * 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> + +#include "src/core/lib/gprpp/abstract.h" +#include "src/core/lib/gprpp/memory.h" + +namespace grpc_core { +namespace internal { + +/// Base class for platform-specific thread-state +class ThreadInternalsInterface { + public: + virtual ~ThreadInternalsInterface() {} + virtual void Start() GRPC_ABSTRACT; + virtual void Join() GRPC_ABSTRACT; + GRPC_ABSTRACT_BASE_CLASS +}; + +} // namespace internal + +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() : state_(FAKE), impl_(nullptr) {} + + /// Normal constructor to create a thread with name \a thd_name, + /// which will execute a thread based on function \a thd_body + /// with argument \a arg once it is started. + /// The optional \a success argument indicates whether the thread + /// is successfully created. + Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg, + bool* success = nullptr); + + /// Move constructor for thread. After this is called, the other thread + /// no longer represents a living thread object + Thread(Thread&& other) : state_(other.state_), impl_(other.impl_) { + other.state_ = MOVED; + other.impl_ = nullptr; + } + + /// Move assignment operator for thread. After this is called, the other + /// thread no longer represents a living thread object. Not allowed if this + /// thread actually exists + Thread& operator=(Thread&& other) { + if (this != &other) { + // TODO(vjpai): if we can be sure that all Thread's are actually + // constructed, then we should assert GPR_ASSERT(impl_ == nullptr) here. + // However, as long as threads come in structures that are + // allocated via gpr_malloc, this will not be the case, so we cannot + // assert it for the time being. + state_ = other.state_; + impl_ = other.impl_; + other.state_ = MOVED; + other.impl_ = nullptr; + } + return *this; + } + + /// The destructor is strictly optional; either the thread never came to life + /// and the constructor itself killed it or it has already been joined and + /// the Join function kills it. The destructor shouldn't have to do anything. + ~Thread() { GPR_ASSERT(impl_ == nullptr); } + + void Start() { + if (impl_ != nullptr) { + GPR_ASSERT(state_ == ALIVE); + state_ = STARTED; + impl_->Start(); + } else { + GPR_ASSERT(state_ == FAILED); + } + }; + + void Join() { + if (impl_ != nullptr) { + impl_->Join(); + grpc_core::Delete(impl_); + state_ = DONE; + impl_ = nullptr; + } else { + GPR_ASSERT(state_ == FAILED); + } + }; + + static void Init(); + static bool AwaitAll(gpr_timespec deadline); + + private: + Thread(const Thread&) = delete; + Thread& operator=(const Thread&) = delete; + + /// The thread states are as follows: + /// FAKE -- just a dummy placeholder Thread created by the default constructor + /// ALIVE -- an actual thread of control exists associated with this thread + /// STARTED -- the thread of control has been started + /// DONE -- the thread of control has completed and been joined + /// FAILED -- the thread of control never came alive + /// MOVED -- contents were moved out and we're no longer tracking them + enum ThreadState { FAKE, ALIVE, STARTED, DONE, FAILED, MOVED }; + ThreadState state_; + internal::ThreadInternalsInterface* impl_; +}; + +} // namespace grpc_core + +#endif /* GRPC_CORE_LIB_GPRPP_THD_H */ diff --git a/src/core/lib/gprpp/thd_posix.cc b/src/core/lib/gprpp/thd_posix.cc new file mode 100644 index 0000000000..2f6c2edcae --- /dev/null +++ b/src/core/lib/gprpp/thd_posix.cc @@ -0,0 +1,209 @@ +/* + * + * 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. + * + */ + +/* Posix implementation for gpr threads. */ + +#include <grpc/support/port_platform.h> + +#ifdef GPR_POSIX_SYNC + +#include "src/core/lib/gprpp/thd.h" + +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/sync.h> +#include <grpc/support/thd_id.h> +#include <pthread.h> +#include <stdlib.h> +#include <string.h> + +#include "src/core/lib/gpr/fork.h" +#include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/memory.h" + +namespace grpc_core { +namespace { +gpr_mu g_mu; +gpr_cv g_cv; +int g_thread_count; +int g_awaiting_threads; + +class ThreadInternalsPosix; +struct thd_arg { + ThreadInternalsPosix* thread; + void (*body)(void* arg); /* body of a thread */ + void* arg; /* argument to a thread */ + const char* name; /* name of thread. Can be nullptr. */ +}; + +class ThreadInternalsPosix + : public grpc_core::internal::ThreadInternalsInterface { + public: + ThreadInternalsPosix(const char* thd_name, void (*thd_body)(void* arg), + void* arg, bool* success) + : started_(false) { + gpr_mu_init(&mu_); + gpr_cv_init(&ready_); + pthread_attr_t attr; + /* don't use gpr_malloc as we may cause an infinite recursion with + * the profiling code */ + thd_arg* info = static_cast<thd_arg*>(malloc(sizeof(*info))); + GPR_ASSERT(info != nullptr); + info->thread = this; + info->body = thd_body; + info->arg = arg; + info->name = thd_name; + inc_thd_count(); + + GPR_ASSERT(pthread_attr_init(&attr) == 0); + GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) == + 0); + + *success = + (pthread_create(&pthread_id_, &attr, + [](void* v) -> void* { + thd_arg arg = *static_cast<thd_arg*>(v); + free(v); + if (arg.name != nullptr) { +#if GPR_APPLE_PTHREAD_NAME + /* Apple supports 64 characters, and will + * truncate if it's longer. */ + pthread_setname_np(arg.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, arg.name, buf_len); + buf[buf_len] = '\0'; + pthread_setname_np(pthread_self(), buf); +#endif // GPR_APPLE_PTHREAD_NAME + } + + gpr_mu_lock(&arg.thread->mu_); + while (!arg.thread->started_) { + gpr_cv_wait(&arg.thread->ready_, &arg.thread->mu_, + gpr_inf_future(GPR_CLOCK_MONOTONIC)); + } + gpr_mu_unlock(&arg.thread->mu_); + + (*arg.body)(arg.arg); + dec_thd_count(); + return nullptr; + }, + info) == 0); + + GPR_ASSERT(pthread_attr_destroy(&attr) == 0); + + if (!success) { + /* don't use gpr_free, as this was allocated using malloc (see above) */ + free(info); + dec_thd_count(); + } + }; + + ~ThreadInternalsPosix() override { + gpr_mu_destroy(&mu_); + gpr_cv_destroy(&ready_); + } + + void Start() override { + gpr_mu_lock(&mu_); + started_ = true; + gpr_cv_signal(&ready_); + gpr_mu_unlock(&mu_); + } + + void Join() override { pthread_join(pthread_id_, nullptr); } + + private: + /***************************************** + * 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); + } + } + + 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); + } + } + + gpr_mu mu_; + gpr_cv ready_; + bool started_; + pthread_t pthread_id_; +}; + +} // namespace + +Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg, + bool* success) { + bool outcome = false; + impl_ = + grpc_core::New<ThreadInternalsPosix>(thd_name, thd_body, arg, &outcome); + if (outcome) { + state_ = ALIVE; + } else { + state_ = FAILED; + grpc_core::Delete(impl_); + impl_ = nullptr; + } + + if (success != nullptr) { + *success = outcome; + } +} + +void Thread::Init() { + gpr_mu_init(&g_mu); + gpr_cv_init(&g_cv); + g_thread_count = 0; + g_awaiting_threads = 0; +} + +bool Thread::AwaitAll(gpr_timespec deadline) { + gpr_mu_lock(&g_mu); + g_awaiting_threads = 1; + int res = 0; + while ((g_thread_count > 0) && + (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0)) { + res = gpr_cv_wait(&g_cv, &g_mu, deadline); + } + g_awaiting_threads = 0; + gpr_mu_unlock(&g_mu); + 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 */ diff --git a/src/core/lib/gprpp/thd_windows.cc b/src/core/lib/gprpp/thd_windows.cc new file mode 100644 index 0000000000..59ea02f3d2 --- /dev/null +++ b/src/core/lib/gprpp/thd_windows.cc @@ -0,0 +1,162 @@ +/* + * + * 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. + * + */ + +/* Windows implementation for gpr threads. */ + +#include <grpc/support/port_platform.h> + +#ifdef GPR_WINDOWS + +#include "src/core/lib/gprpp/thd.h" + +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/thd_id.h> +#include <string.h> + +#include "src/core/lib/gprpp/memory.h" + +#if defined(_MSC_VER) +#define thread_local __declspec(thread) +#define WIN_LAMBDA +#elif defined(__GNUC__) +#define thread_local __thread +#define WIN_LAMBDA WINAPI +#else +#error "Unknown compiler - please file a bug report" +#endif + +namespace { +class ThreadInternalsWindows; +struct thd_info { + ThreadInternalsWindows* thread; + void (*body)(void* arg); /* body of a thread */ + void* arg; /* argument to a thread */ + HANDLE join_event; /* the join event */ +}; + +thread_local struct thd_info* g_thd_info; + +class ThreadInternalsWindows + : public grpc_core::internal::ThreadInternalsInterface { + public: + ThreadInternalsWindows(void (*thd_body)(void* arg), void* arg, bool* success) + : started_(false) { + gpr_mu_init(&mu_); + gpr_cv_init(&ready_); + + HANDLE handle; + info_ = (struct thd_info*)gpr_malloc(sizeof(*info_)); + info_->thread = this; + info_->body = thd_body; + info_->arg = arg; + + info_->join_event = CreateEvent(nullptr, FALSE, FALSE, nullptr); + if (info_->join_event == nullptr) { + gpr_free(info_); + *success = false; + } else { + handle = CreateThread( + nullptr, 64 * 1024, + [](void* v) WIN_LAMBDA -> DWORD { + g_thd_info = static_cast<thd_info*>(v); + gpr_mu_lock(&g_thd_info->thread->mu_); + while (!g_thd_info->thread->started_) { + gpr_cv_wait(&g_thd_info->thread->ready_, &g_thd_info->thread->mu_, + gpr_inf_future(GPR_CLOCK_MONOTONIC)); + } + gpr_mu_unlock(&g_thd_info->thread->mu_); + g_thd_info->body(g_thd_info->arg); + BOOL ret = SetEvent(g_thd_info->join_event); + GPR_ASSERT(ret); + return 0; + }, + info_, 0, nullptr); + if (handle == nullptr) { + destroy_thread(); + *success = false; + } else { + CloseHandle(handle); + *success = true; + } + } + } + + ~ThreadInternalsWindows() override { + gpr_mu_destroy(&mu_); + gpr_cv_destroy(&ready_); + } + + void Start() override { + gpr_mu_lock(&mu_); + started_ = true; + gpr_cv_signal(&ready_); + gpr_mu_unlock(&mu_); + } + + void Join() override { + DWORD ret = WaitForSingleObject(info_->join_event, INFINITE); + GPR_ASSERT(ret == WAIT_OBJECT_0); + destroy_thread(); + } + + private: + void destroy_thread() { + CloseHandle(info_->join_event); + gpr_free(info_); + } + + gpr_mu mu_; + gpr_cv ready_; + bool started_; + thd_info* info_; +}; + +} // namespace + +namespace grpc_core { + +void Thread::Init() {} + +bool Thread::AwaitAll(gpr_timespec deadline) { + // TODO: Consider adding this if needed + return false; +} + +Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg, + bool* success) { + bool outcome = false; + impl_ = grpc_core::New<ThreadInternalsWindows>(thd_body, arg, &outcome); + if (outcome) { + state_ = ALIVE; + } else { + state_ = FAILED; + grpc_core::Delete(impl_); + impl_ = nullptr; + } + + if (success != nullptr) { + *success = outcome; + } +} + +} // namespace grpc_core + +gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)g_thd_info; } + +#endif /* GPR_WINDOWS */ diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index e979ff7eb5..6120f9f44b 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -38,9 +38,9 @@ #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/gpr/tls.h" #include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/block_annotate.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/wakeup_fd_cv.h" @@ -255,8 +255,13 @@ typedef struct poll_result { } poll_result; typedef struct poll_args { + grpc_core::Thread poller_thd; gpr_cv trigger; int trigger_set; + bool harvestable; + gpr_cv harvest; + bool joinable; + gpr_cv join; struct pollfd* fds; nfds_t nfds; poll_result* result; @@ -266,15 +271,17 @@ typedef struct poll_args { // This is a 2-tiered cache, we mantain a hash table // of active poll calls, so we can wait on the result -// of that call. We also maintain a freelist of inactive -// poll threads. +// of that call. We also maintain freelists of inactive +// poll args and of dead poller threads. typedef struct poll_hash_table { poll_args* free_pollers; poll_args** active_pollers; + poll_args* dead_pollers; unsigned int size; unsigned int count; } poll_hash_table; +// TODO(kpayson64): Eliminate use of global non-POD variables poll_hash_table poll_cache; grpc_cv_fd_table g_cvfds; @@ -1301,6 +1308,7 @@ static void pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { static void run_poll(void* args); static void cache_poller_locked(poll_args* args); +static void cache_harvest_locked(); static void cache_insert_locked(poll_args* args) { uint32_t key = gpr_murmur_hash3(args->fds, args->nfds * sizeof(struct pollfd), @@ -1363,6 +1371,10 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) { poll_args* pargs = static_cast<poll_args*>(gpr_malloc(sizeof(struct poll_args))); gpr_cv_init(&pargs->trigger); + gpr_cv_init(&pargs->harvest); + gpr_cv_init(&pargs->join); + pargs->harvestable = false; + pargs->joinable = false; pargs->fds = fds; pargs->nfds = count; pargs->next = nullptr; @@ -1370,11 +1382,9 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) { pargs->trigger_set = 0; init_result(pargs); cache_poller_locked(pargs); - gpr_thd_id t_id; - gpr_thd_options opt = gpr_thd_options_default(); gpr_ref(&g_cvfds.pollcount); - gpr_thd_options_set_detached(&opt); - GPR_ASSERT(gpr_thd_new(&t_id, "grpc_poller", &run_poll, pargs, &opt)); + pargs->poller_thd = grpc_core::Thread("grpc_poller", &run_poll, pargs); + pargs->poller_thd.Start(); return pargs; } @@ -1439,7 +1449,33 @@ static void cache_destroy_locked(poll_args* args) { poll_cache.free_pollers = args->next; } - gpr_free(args); + // Now move this args to the dead poller list for later join + if (poll_cache.dead_pollers != nullptr) { + poll_cache.dead_pollers->prev = args; + } + args->prev = nullptr; + args->next = poll_cache.dead_pollers; + poll_cache.dead_pollers = args; +} + +static void cache_harvest_locked() { + while (poll_cache.dead_pollers) { + poll_args* args = poll_cache.dead_pollers; + poll_cache.dead_pollers = poll_cache.dead_pollers->next; + // Keep the list consistent in case new dead pollers get added when we + // release the lock below to wait on joining + if (poll_cache.dead_pollers) { + poll_cache.dead_pollers->prev = nullptr; + } + args->harvestable = true; + gpr_cv_signal(&args->harvest); + while (!args->joinable) { + gpr_cv_wait(&args->join, &g_cvfds.mu, + gpr_inf_future(GPR_CLOCK_MONOTONIC)); + } + args->poller_thd.Join(); + gpr_free(args); + } } static void decref_poll_result(poll_result* res) { @@ -1471,6 +1507,7 @@ static void run_poll(void* args) { poll_result* result = pargs->result; int retval = g_cvfds.poll(result->fds, result->nfds, CV_POLL_PERIOD_MS); gpr_mu_lock(&g_cvfds.mu); + cache_harvest_locked(); if (retval != 0) { result->completed = 1; result->retval = retval; @@ -1490,6 +1527,7 @@ static void run_poll(void* args) { deadline = gpr_time_add(deadline, thread_grace); pargs->trigger_set = 0; gpr_cv_wait(&pargs->trigger, &g_cvfds.mu, deadline); + cache_harvest_locked(); if (!pargs->trigger_set) { cache_destroy_locked(pargs); break; @@ -1498,10 +1536,15 @@ static void run_poll(void* args) { gpr_mu_unlock(&g_cvfds.mu); } - // We still have the lock here if (gpr_unref(&g_cvfds.pollcount)) { gpr_cv_signal(&g_cvfds.shutdown_cv); } + while (!pargs->harvestable) { + gpr_cv_wait(&pargs->harvest, &g_cvfds.mu, + gpr_inf_future(GPR_CLOCK_MONOTONIC)); + } + pargs->joinable = true; + gpr_cv_signal(&pargs->join); gpr_mu_unlock(&g_cvfds.mu); } @@ -1514,6 +1557,7 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { nfds_t nsockfds = 0; poll_result* result = nullptr; gpr_mu_lock(&g_cvfds.mu); + cache_harvest_locked(); pollcv = static_cast<grpc_cv_node*>(gpr_malloc(sizeof(grpc_cv_node))); pollcv->next = nullptr; gpr_cv pollcv_cv; @@ -1577,12 +1621,14 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { pargs->trigger_set = 1; gpr_cv_signal(&pargs->trigger); gpr_cv_wait(&pollcv_cv, &g_cvfds.mu, deadline); + cache_harvest_locked(); res = result->retval; errno = result->err; result->watchcount--; remove_cvn(&result->watchers, pollcv); } else if (!skip_poll) { gpr_cv_wait(&pollcv_cv, &g_cvfds.mu, deadline); + cache_harvest_locked(); } idx = 0; @@ -1639,6 +1685,7 @@ static void global_cv_fd_table_init() { for (unsigned int i = 0; i < poll_cache.size; i++) { poll_cache.active_pollers[i] = nullptr; } + poll_cache.dead_pollers = nullptr; gpr_mu_unlock(&g_cvfds.mu); } @@ -1657,6 +1704,7 @@ static void global_cv_fd_table_shutdown() { grpc_poll_function = g_cvfds.poll; gpr_free(g_cvfds.cvfds); + cache_harvest_locked(); gpr_free(poll_cache.active_pollers); gpr_mu_unlock(&g_cvfds.mu); diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 132fe87870..2f544b20ab 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -23,7 +23,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" diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index e7f412a562..b017db53f8 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -29,9 +29,9 @@ #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/gpr/tls.h" #include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/exec_ctx.h" #define MAX_DEPTH 2 @@ -43,7 +43,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; @@ -101,13 +101,13 @@ 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); + g_thread_state[i].thd = grpc_core::Thread(); g_thread_state[i].elems = GRPC_CLOSURE_LIST_INIT; } - gpr_thd_options opt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&g_thread_state[0].id, "grpc_executor", executor_thread, - &g_thread_state[0], &opt); + 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++) { @@ -121,7 +121,7 @@ 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++) { @@ -264,10 +264,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_options opt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&g_thread_state[cur_thread_count].id, "gpr_executor", - executor_thread, &g_thread_state[cur_thread_count], &opt); + 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); } diff --git a/src/core/lib/iomgr/fork_posix.cc b/src/core/lib/iomgr/fork_posix.cc index d32fbc4588..f8645ab157 100644 --- a/src/core/lib/iomgr/fork_posix.cc +++ b/src/core/lib/iomgr/fork_posix.cc @@ -29,7 +29,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" @@ -53,7 +53,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!"); diff --git a/src/core/lib/iomgr/iocp_windows.cc b/src/core/lib/iomgr/iocp_windows.cc index 5285734719..ce77231036 100644 --- a/src/core/lib/iomgr/iocp_windows.cc +++ b/src/core/lib/iomgr/iocp_windows.cc @@ -30,7 +30,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" diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 70a80e1998..3c2b83a549 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -31,8 +31,8 @@ #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/gpr/useful.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/iomgr_internal.h" diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index 62ab760875..c1b83ddc14 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -24,7 +24,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" diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index 9307f19bcf..2f68dbe214 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -35,8 +35,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/gpr/useful.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" diff --git a/src/core/lib/iomgr/resolve_address_windows.cc b/src/core/lib/iomgr/resolve_address_windows.cc index 4e1dcaabaf..7a62c88720 100644 --- a/src/core/lib/iomgr/resolve_address_windows.cc +++ b/src/core/lib/iomgr/resolve_address_windows.cc @@ -37,7 +37,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" diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 0210e70015..94f288af27 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -18,21 +18,20 @@ #include <grpc/support/port_platform.h> -#include "src/core/lib/iomgr/timer_manager.h" +#include <inttypes.h> #include <grpc/support/alloc.h> #include <grpc/support/log.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" +#include "src/core/lib/iomgr/timer_manager.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; @@ -68,7 +67,7 @@ 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(); completed_thread* next = to_gc->next; gpr_free(to_gc); to_gc = next; @@ -85,18 +84,10 @@ static void start_timer_thread_and_unlock(void) { if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, "Spawn timer thread"); } - gpr_thd_options opt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&opt); 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, &opt); - gpr_mu_unlock(&g_mu); + ct->thd = grpc_core::Thread("grpc_global_timer", timer_thread, ct); + ct->thd.Start(); } void grpc_timer_manager_tick() { diff --git a/src/core/lib/iomgr/wakeup_fd_cv.cc b/src/core/lib/iomgr/wakeup_fd_cv.cc index ee322105ae..74faa6379e 100644 --- a/src/core/lib/iomgr/wakeup_fd_cv.cc +++ b/src/core/lib/iomgr/wakeup_fd_cv.cc @@ -32,8 +32,8 @@ #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 "src/core/lib/gprpp/thd.h" #define MAX_TABLE_RESIZE 256 diff --git a/src/core/lib/profiling/basic_timers.cc b/src/core/lib/profiling/basic_timers.cc index ca6705a6b3..43384fd0ca 100644 --- a/src/core/lib/profiling/basic_timers.cc +++ b/src/core/lib/profiling/basic_timers.cc @@ -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(); + grpc_core::Delete(g_writing_thread); gpr_log(GPR_INFO, "flushing logs"); @@ -201,10 +202,8 @@ void gpr_timers_set_log_filename(const char* filename) { } static void init_output() { - gpr_thd_options options = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&options); - GPR_ASSERT(gpr_thd_new(&g_writing_thread, "timer_output_thread", - writing_thread, NULL, &options)); + g_writing_thread = grpc_core::New<grpc_core::Thread>("timer_output_thread", + writing_thread, nullptr); atexit(finish_writing); } diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 7bc24a5049..ac9f9e6066 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -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(); diff --git a/src/core/tsi/alts_transport_security.cc b/src/core/tsi/alts_transport_security.cc index b45b4e0736..2fd408103b 100644 --- a/src/core/tsi/alts_transport_security.cc +++ b/src/core/tsi/alts_transport_security.cc @@ -56,7 +56,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); diff --git a/src/core/tsi/alts_transport_security.h b/src/core/tsi/alts_transport_security.h index 3ca064992b..d6b8e11137 100644 --- a/src/core/tsi/alts_transport_security.h +++ b/src/core/tsi/alts_transport_security.h @@ -24,10 +24,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; diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc index cba5984f4b..867f31f025 100644 --- a/src/cpp/client/channel_cc.cc +++ b/src/cpp/client/channel_cc.cc @@ -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 { diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index 81c78fe739..fe887486d1 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -19,20 +19,24 @@ #include "src/cpp/server/dynamic_thread_pool.h" #include <mutex> -#include <thread> #include <grpc/support/log.h> +#include "src/core/lib/gprpp/thd.h" + namespace grpc { DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool) : pool_(pool), - thd_(new std::thread(&DynamicThreadPool::DynamicThread::ThreadFunc, - this)) {} -DynamicThreadPool::DynamicThread::~DynamicThread() { - thd_->join(); - thd_.reset(); + thd_("dynamic thread pool thread", + [](void* th) { + reinterpret_cast<DynamicThreadPool::DynamicThread*>(th) + ->ThreadFunc(); + }, + this) { + thd_.Start(); } +DynamicThreadPool::DynamicThread::~DynamicThread() { thd_.Join(); } void DynamicThreadPool::DynamicThread::ThreadFunc() { pool_->ThreadFunc(); diff --git a/src/cpp/server/dynamic_thread_pool.h b/src/cpp/server/dynamic_thread_pool.h index 880a03d0f0..5df8cf2b04 100644 --- a/src/cpp/server/dynamic_thread_pool.h +++ b/src/cpp/server/dynamic_thread_pool.h @@ -24,10 +24,10 @@ #include <memory> #include <mutex> #include <queue> -#include <thread> #include <grpcpp/support/config.h> +#include "src/core/lib/gprpp/thd.h" #include "src/cpp/server/thread_pool_interface.h" namespace grpc { @@ -47,7 +47,7 @@ class DynamicThreadPool final : public ThreadPoolInterface { private: DynamicThreadPool* pool_; - std::unique_ptr<std::thread> thd_; + grpc_core::Thread thd_; void ThreadFunc(); }; std::mutex mu_; diff --git a/src/cpp/thread_manager/thread_manager.cc b/src/cpp/thread_manager/thread_manager.cc index 23264f1b5b..21cc9bbb31 100644 --- a/src/cpp/thread_manager/thread_manager.cc +++ b/src/cpp/thread_manager/thread_manager.cc @@ -20,18 +20,24 @@ #include <climits> #include <mutex> -#include <thread> #include <grpc/support/log.h> +#include "src/core/lib/gprpp/thd.h" + namespace grpc { ThreadManager::WorkerThread::WorkerThread(ThreadManager* thd_mgr) : thd_mgr_(thd_mgr) { // Make thread creation exclusive with respect to its join happening in // ~WorkerThread(). - std::lock_guard<std::mutex> lock(wt_mu_); - thd_ = std::thread(&ThreadManager::WorkerThread::Run, this); + thd_ = grpc_core::Thread( + "sync server thread", + [](void* th) { + reinterpret_cast<ThreadManager::WorkerThread*>(th)->Run(); + }, + this); + thd_.Start(); } void ThreadManager::WorkerThread::Run() { @@ -41,8 +47,7 @@ void ThreadManager::WorkerThread::Run() { ThreadManager::WorkerThread::~WorkerThread() { // Don't join until the thread is fully constructed. - std::lock_guard<std::mutex> lock(wt_mu_); - thd_.join(); + thd_.Join(); } ThreadManager::ThreadManager(int min_pollers, int max_pollers) diff --git a/src/cpp/thread_manager/thread_manager.h b/src/cpp/thread_manager/thread_manager.h index 1113031695..5a40f2de47 100644 --- a/src/cpp/thread_manager/thread_manager.h +++ b/src/cpp/thread_manager/thread_manager.h @@ -23,10 +23,11 @@ #include <list> #include <memory> #include <mutex> -#include <thread> #include <grpcpp/support/config.h> +#include "src/core/lib/gprpp/thd.h" + namespace grpc { class ThreadManager { @@ -84,8 +85,8 @@ class ThreadManager { virtual void Wait(); private: - // Helper wrapper class around std::thread. This takes a ThreadManager object - // and starts a new std::thread to calls the Run() function. + // Helper wrapper class around grpc_core::Thread. Takes a ThreadManager object + // and starts a new grpc_core::Thread to calls the Run() function. // // The Run() function calls ThreadManager::MainWorkLoop() function and once // that completes, it marks the WorkerThread completed by calling @@ -101,8 +102,7 @@ class ThreadManager { void Run(); ThreadManager* const thd_mgr_; - std::mutex wt_mu_; - std::thread thd_; + grpc_core::Thread thd_; }; // The main funtion in ThreadManager diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 8ba52ab3a0..75156793f1 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -41,9 +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.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 +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', diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index 6055ccbf4b..c03ebcf409 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.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 id; gpr_event_init(&a.done_thd); a.validator = server_validator; /* Start validator */ - gpr_thd_new(&id, "grpc_bad_client", thd_func, &a, nullptr); + + 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,6 +235,7 @@ void grpc_run_bad_client_test( /* Shutdown. */ shutdown_client(&sfd.client); + server_validator_thd.Join(); shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); grpc_server_shutdown_and_notify(a.server, shutdown_cq, nullptr); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 1af168e1f9..3d133cfc18 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -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,15 +254,17 @@ static void actually_poll_server(void* arg) { gpr_free(pa); } -static void 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, nullptr); + 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, @@ -281,9 +284,11 @@ static void run_test(const char* response_payload, state.response_payload_length = response_payload_length; /* poll server until sending out the response */ - 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)); + thdptr->Join(); /* clean up */ grpc_endpoint_shutdown(state.tcp, diff --git a/test/core/end2end/fixtures/h2_census.cc b/test/core/end2end/fixtures/h2_census.cc index 27b897ce5a..b3b4171a72 100644 --- a/test/core/end2end/fixtures/h2_census.cc +++ b/test/core/end2end/fixtures/h2_census.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc index b4ec78d710..565c96cf93 100644 --- a/test/core/end2end/fixtures/h2_compress.cc +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_full+pipe.cc b/test/core/end2end/fixtures/h2_full+pipe.cc index e97d078d9c..ed173c1afb 100644 --- a/test/core/end2end/fixtures/h2_full+pipe.cc +++ b/test/core/end2end/fixtures/h2_full+pipe.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_full+trace.cc b/test/core/end2end/fixtures/h2_full+trace.cc index 12aa69bb17..afb86ea899 100644 --- a/test/core/end2end/fixtures/h2_full+trace.cc +++ b/test/core/end2end/fixtures/h2_full+trace.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_full+workarounds.cc b/test/core/end2end/fixtures/h2_full+workarounds.cc index c6b358dcc5..bd9ddff5b5 100644 --- a/test/core/end2end/fixtures/h2_full+workarounds.cc +++ b/test/core/end2end/fixtures/h2_full+workarounds.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_full.cc b/test/core/end2end/fixtures/h2_full.cc index 32e3e55128..ca61ec8eff 100644 --- a/test/core/end2end/fixtures/h2_full.cc +++ b/test/core/end2end/fixtures/h2_full.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_http_proxy.cc b/test/core/end2end/fixtures/h2_http_proxy.cc index b990d7a763..90d0627860 100644 --- a/test/core/end2end/fixtures/h2_http_proxy.cc +++ b/test/core/end2end/fixtures/h2_http_proxy.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_load_reporting.cc b/test/core/end2end/fixtures/h2_load_reporting.cc index 6adc0c154e..ec9eedbd34 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.cc +++ b/test/core/end2end/fixtures/h2_load_reporting.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_proxy.cc b/test/core/end2end/fixtures/h2_proxy.cc index 28a6eeeb78..c97188fbb2 100644 --- a/test/core/end2end/fixtures/h2_proxy.cc +++ b/test/core/end2end/fixtures/h2_proxy.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc index 5dd5c2ad67..d539ddae8f 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.cc +++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_sockpair.cc b/test/core/end2end/fixtures/h2_sockpair.cc index 52a7b95c3a..75f64024cd 100644 --- a/test/core/end2end/fixtures/h2_sockpair.cc +++ b/test/core/end2end/fixtures/h2_sockpair.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.cc b/test/core/end2end/fixtures/h2_sockpair_1byte.cc index 0d3cb34724..929631917d 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.cc +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc @@ -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" diff --git a/test/core/end2end/fixtures/h2_uds.cc b/test/core/end2end/fixtures/h2_uds.cc index a97b14f1d6..1b081f9ea3 100644 --- a/test/core/end2end/fixtures/h2_uds.cc +++ b/test/core/end2end/fixtures/h2_uds.cc @@ -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" diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 18e8310251..58353376f3 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -33,7 +33,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 +53,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,10 +550,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_thd_options opt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&opt); - GPR_ASSERT( - gpr_thd_new(&proxy->thd, "grpc_http_proxy", thread_main, proxy, &opt)); + proxy->thd = grpc_core::Thread("grpc_http_proxy", thread_main, proxy); + proxy->thd.Start(); return proxy; } @@ -566,7 +564,7 @@ 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(); grpc_tcp_server_shutdown_listeners(proxy->server); grpc_tcp_server_unref(proxy->server); gpr_free(proxy->proxy_name); diff --git a/test/core/end2end/fixtures/inproc.cc b/test/core/end2end/fixtures/inproc.cc index 4ddcc78495..d47de42540 100644 --- a/test/core/end2end/fixtures/inproc.cc +++ b/test/core/end2end/fixtures/inproc.cc @@ -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" diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc index bc3b0ca35c..042c858b4c 100644 --- a/test/core/end2end/fixtures/proxy.cc +++ b/test/core/end2end/fixtures/proxy.cc @@ -25,12 +25,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/gpr/useful.h" +#include "src/core/lib/gprpp/thd.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; @@ -76,7 +76,6 @@ static void request_call(grpc_end2end_proxy* proxy); grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, grpc_channel_args* client_args, grpc_channel_args* server_args) { - gpr_thd_options opt = gpr_thd_options_default(); int proxy_port = grpc_pick_unused_port_or_die(); int server_port = grpc_pick_unused_port_or_die(); @@ -98,9 +97,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_thd_options_set_joinable(&opt); - GPR_ASSERT( - gpr_thd_new(&proxy->thd, "grpc_end2end_proxy", thread_main, proxy, &opt)); + proxy->thd = grpc_core::Thread("grpc_end2end_proxy", thread_main, proxy); + proxy->thd.Start(); request_call(proxy); @@ -123,7 +121,7 @@ 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(); gpr_free(proxy->proxy_port); gpr_free(proxy->server_port); grpc_server_destroy(proxy->server); diff --git a/test/core/end2end/tests/bad_ping.cc b/test/core/end2end/tests/bad_ping.cc index 9fff3bfb7d..f305ea5703 100644 --- a/test/core/end2end/tests/bad_ping.cc +++ b/test/core/end2end/tests/bad_ping.cc @@ -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" diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc index a517ffa686..caa4265aa2 100644 --- a/test/core/end2end/tests/connectivity.cc +++ b/test/core/end2end/tests/connectivity.cc @@ -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,8 +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_options thdopt = gpr_thd_options_default(); - gpr_thd_id thdid; grpc_channel_args client_args; grpc_arg arg_array[1]; @@ -67,9 +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_thd_options_set_joinable(&thdopt); - GPR_ASSERT( - gpr_thd_new(&thdid, "grpc_connectivity", child_thread, &ce, &thdopt)); + grpc_core::Thread thd("grpc_connectivity", child_thread, &ce); + thd.Start(); gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC)); @@ -86,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) == diff --git a/test/core/end2end/tests/ping.cc b/test/core/end2end/tests/ping.cc index 8fce295f90..f523cbb0c7 100644 --- a/test/core/end2end/tests/ping.cc +++ b/test/core/end2end/tests/ping.cc @@ -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" diff --git a/test/core/gpr/BUILD b/test/core/gpr/BUILD index 4032664b59..5308ea0934 100644 --- a/test/core/gpr/BUILD +++ b/test/core/gpr/BUILD @@ -129,16 +129,6 @@ grpc_cc_test( ) grpc_cc_test( - name = "thd_test", - srcs = ["thd_test.cc"], - language = "C++", - deps = [ - "//:gpr", - "//test/core/util:gpr_test_util", - ], -) - -grpc_cc_test( name = "time_test", srcs = ["time_test.cc"], language = "C++", diff --git a/test/core/gpr/arena_test.cc b/test/core/gpr/arena_test.cc index 9eaf57b631..111414ea3e 100644 --- a/test/core/gpr/arena_test.cc +++ b/test/core/gpr/arena_test.cc @@ -18,16 +18,17 @@ #include "src/core/lib/gpr/arena.h" +#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/gpr/useful.h" +#include "src/core/lib/gprpp/thd.h" #include "test/core/util/test_config.h" static void test_noop(void) { gpr_arena_destroy(gpr_arena_create(1)); } @@ -97,19 +98,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_options opt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&thds[i], "grpc_concurrent_test", concurrent_test_body, &args, - &opt); + 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); diff --git a/test/core/gpr/cpu_test.cc b/test/core/gpr/cpu_test.cc index 9f2c3f1923..1052d40b42 100644 --- a/test/core/gpr/cpu_test.cc +++ b/test/core/gpr/cpu_test.cc @@ -21,15 +21,17 @@ gpr_cpu_current_cpu() */ -#include <grpc/support/alloc.h> #include <grpc/support/cpu.h> + +#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 +103,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; @@ -110,15 +111,24 @@ static void cpu_test(void) { gpr_mu_init(&ct.mu); gpr_cv_init(&ct.done_cv); ct.is_done = 0; - for (i = 0; i < ct.ncores * 3; i++) { - GPR_ASSERT( - gpr_thd_new(&thd, "grpc_cpu_test", &worker_thread, &ct, nullptr)); + + uint32_t nthreads = ct.ncores * 3; + grpc_core::Thread* thd = + static_cast<grpc_core::Thread*>(gpr_malloc(sizeof(*thd) * nthreads)); + + for (i = 0; i < nthreads; i++) { + thd[i] = grpc_core::Thread("grpc_cpu_test", &worker_thread, &ct); + thd[i].Start(); } gpr_mu_lock(&ct.mu); while (!ct.is_done) { gpr_cv_wait(&ct.done_cv, &ct.mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(&ct.mu); + for (i = 0; i < nthreads; i++) { + thd[i].Join(); + } + gpr_free(thd); fprintf(stderr, "Saw cores ["); fflush(stderr); for (i = 0; i < ct.ncores; i++) { diff --git a/test/core/gpr/mpscq_test.cc b/test/core/gpr/mpscq_test.cc index 96813466c9..8c0873941f 100644 --- a/test/core/gpr/mpscq_test.cc +++ b/test/core/gpr/mpscq_test.cc @@ -24,8 +24,8 @@ #include <grpc/support/log.h> #include <grpc/support/sync.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/thd.h" #include "test/core/util/test_config.h" typedef struct test_node { @@ -76,18 +76,16 @@ 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); for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { - gpr_thd_options options = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&options); 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], &options)); + thds[i] = grpc_core::Thread("grpc_mt_test", test_thread, &ta[i]); + thds[i].Start(); } size_t num_done = 0; size_t spins = 0; @@ -104,8 +102,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); } @@ -147,19 +145,17 @@ 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[50]; + grpc_core::Thread pull_thds[50]; thd_args ta[GPR_ARRAY_SIZE(thds)]; gpr_mpscq q; gpr_mpscq_init(&q); for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { - gpr_thd_options options = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&options); 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], - &options)); + thds[i] = grpc_core::Thread("grpc_multipop_test", test_thread, &ta[i]); + thds[i].Start(); } pull_args pa; pa.ta = ta; @@ -170,18 +166,16 @@ 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_thd_options options = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&options); - GPR_ASSERT(gpr_thd_new(&pull_thds[i], "grpc_multipop_pull", pull_thread, - &pa, &options)); + 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); } diff --git a/test/core/gpr/spinlock_test.cc b/test/core/gpr/spinlock_test.cc index 9f182bc154..0ee72edb15 100644 --- a/test/core/gpr/spinlock_test.cc +++ b/test/core/gpr/spinlock_test.cc @@ -16,24 +16,26 @@ * */ -/* Test of gpr synchronization support. */ +/* Test of gpr spin-lock support. */ #include "src/core/lib/gpr/spinlock.h" + +#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 +48,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,10 +68,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_thd_options opt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&opt); - GPR_ASSERT( - gpr_thd_new(&m->threads[i], "grpc_create_threads", body, m, &opt)); + m->threads[i] = grpc_core::Thread("grpc_create_threads", body, m); + m->threads[i].Start(); } } @@ -77,7 +77,7 @@ 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(); } } diff --git a/test/core/gpr/sync_test.cc b/test/core/gpr/sync_test.cc index bafd91020b..24b4562819 100644 --- a/test/core/gpr/sync_test.cc +++ b/test/core/gpr/sync_test.cc @@ -18,14 +18,16 @@ /* 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 <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,7 +135,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 */ + int nthreads; /* number of threads */ + grpc_core::Thread* threads; int64_t iterations; /* number of iterations per thread */ int64_t counter; @@ -157,13 +160,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->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); @@ -171,7 +176,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; } @@ -182,15 +187,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->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)) { - gpr_thd_id id; int i; - for (i = 0; i != m->threads; i++) { - GPR_ASSERT(gpr_thd_new(&id, "grpc_create_threads", body, m, nullptr)); + for (i = 0; i != m->nthreads; i++) { + m->threads[i] = grpc_core::Thread("grpc_create_threads", body, m); + m->threads[i].Start(); } } @@ -201,9 +207,12 @@ 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->nthreads; i++) { + m->threads[i].Join(); + } } -/* 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); @@ -245,16 +254,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); + grpc_core::Thread extra_thd; if (extra != nullptr) { - gpr_thd_id id; - GPR_ASSERT(gpr_thd_new(&id, name, extra, m, nullptr)); + 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 (m->counter != m->threads * m->iterations * m->incr_step) { + if (extra != nullptr) { + extra_thd.Join(); + } + 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); @@ -296,7 +309,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); @@ -304,7 +317,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++; @@ -369,12 +382,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++) { @@ -424,11 +437,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); diff --git a/test/core/gpr/time_test.cc b/test/core/gpr/time_test.cc index e6bcc1247d..c80aac649d 100644 --- a/test/core/gpr/time_test.cc +++ b/test/core/gpr/time_test.cc @@ -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) { diff --git a/test/core/gpr/tls_test.cc b/test/core/gpr/tls_test.cc index 1e4534dc5a..0502fc7ef4 100644 --- a/test/core/gpr/tls_test.cc +++ b/test/core/gpr/tls_test.cc @@ -18,13 +18,15 @@ /* 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 <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,21 +48,18 @@ static void thd_body(void* arg) { /* ------------------------------------------------- */ int main(int argc, char* argv[]) { - gpr_thd_options opt = gpr_thd_options_default(); - int i; - gpr_thd_id threads[NUM_THREADS]; + grpc_core::Thread threads[NUM_THREADS]; grpc_test_init(argc, argv); gpr_tls_init(&test_var); - gpr_thd_options_set_joinable(&opt); - - for (i = 0; i < NUM_THREADS; i++) { - gpr_thd_new(&threads[i], "grpc_tls_test", thd_body, nullptr, &opt); + for (auto& th : threads) { + 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); diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD index 1c11e0bdb5..a8a5739552 100644 --- a/test/core/gprpp/BUILD +++ b/test/core/gprpp/BUILD @@ -24,7 +24,6 @@ grpc_cc_test( language = "C++", deps = [ "//:gpr", - "//:gpr++_base", "//test/core/util:gpr_test_util", ], ) @@ -37,7 +36,7 @@ grpc_cc_test( ], language = "C++", deps = [ - "//:gpr++_base", + "//:gpr_base", "//test/core/util:gpr_test_util", ], ) @@ -58,39 +57,49 @@ grpc_cc_test( grpc_cc_test( name = "orphanable_test", srcs = ["orphanable_test.cc"], + external_deps = [ + "gtest", + ], language = "C++", deps = [ "//:orphanable", "//test/core/util:gpr_test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "ref_counted_test", srcs = ["ref_counted_test.cc"], + external_deps = [ + "gtest", + ], language = "C++", deps = [ "//:ref_counted", "//test/core/util:gpr_test_util", ], - external_deps = [ - "gtest", - ], ) grpc_cc_test( name = "ref_counted_ptr_test", srcs = ["ref_counted_ptr_test.cc"], + external_deps = [ + "gtest", + ], language = "C++", deps = [ "//:ref_counted", "//:ref_counted_ptr", "//test/core/util:gpr_test_util", ], - external_deps = [ - "gtest", +) + +grpc_cc_test( + name = "thd_test", + srcs = ["thd_test.cc"], + language = "C++", + deps = [ + "//:gpr", + "//test/core/util:gpr_test_util", ], ) diff --git a/test/core/gprpp/manual_constructor_test.cc b/test/core/gprpp/manual_constructor_test.cc index 74777fe11c..af162ae8e8 100644 --- a/test/core/gprpp/manual_constructor_test.cc +++ b/test/core/gprpp/manual_constructor_test.cc @@ -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" diff --git a/test/core/gpr/thd_test.cc b/test/core/gprpp/thd_test.cc index 18bbaae6c9..82dd681049 100644 --- a/test/core/gpr/thd_test.cc +++ b/test/core/gprpp/thd_test.cc @@ -18,17 +18,18 @@ /* Test of gpr thread support. */ -#include "src/core/lib/gpr/thd.h" +#include "src/core/lib/gprpp/thd.h" + +#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" -#define NUM_THREADS 300 +#define NUM_THREADS 100 struct test { gpr_mu mu; @@ -38,7 +39,7 @@ struct test { }; /* A Thread body. Decrement t->n, and if is becomes zero, set t->done. */ -static void thd_body(void* v) { +static void thd_body1(void* v) { struct test* t = static_cast<struct test*>(v); gpr_mu_lock(&t->mu); t->n--; @@ -49,48 +50,42 @@ static void thd_body(void* v) { gpr_mu_unlock(&t->mu); } -static void thd_body_joinable(void* v) {} - -/* Test thread options work as expected */ -static void test_options(void) { - gpr_thd_options options = gpr_thd_options_default(); - GPR_ASSERT(!gpr_thd_options_is_joinable(&options)); - GPR_ASSERT(gpr_thd_options_is_detached(&options)); - gpr_thd_options_set_joinable(&options); - GPR_ASSERT(gpr_thd_options_is_joinable(&options)); - GPR_ASSERT(!gpr_thd_options_is_detached(&options)); - gpr_thd_options_set_detached(&options); - GPR_ASSERT(!gpr_thd_options_is_joinable(&options)); - GPR_ASSERT(gpr_thd_options_is_detached(&options)); -} - -/* Test that we can create a number of threads and wait for them. */ -static void test(void) { - int i; - gpr_thd_id thd; - gpr_thd_id thds[NUM_THREADS]; +/* Test that we can create a number of threads, wait for them, and join them. */ +static void test1(void) { + grpc_core::Thread thds[NUM_THREADS]; struct test t; - gpr_thd_options options = gpr_thd_options_default(); 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(&thd, "grpc_thread_test", &thd_body, &t, nullptr)); + for (auto& th : thds) { + 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 (auto& th : thds) { + th.Join(); + } GPR_ASSERT(t.n == 0); - gpr_thd_options_set_joinable(&options); - for (i = 0; i < NUM_THREADS; i++) { - GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_joinable_thread_test", - &thd_body_joinable, nullptr, &options)); +} + +static void thd_body2(void* v) {} + +/* Test that we can create a number of threads and join them. */ +static void test2(void) { + grpc_core::Thread thds[NUM_THREADS]; + for (auto& th : thds) { + bool ok; + 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(); } } @@ -98,7 +93,7 @@ static void test(void) { int main(int argc, char* argv[]) { grpc_test_init(argc, argv); - test_options(); - test(); + test1(); + test2(); return 0; } diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index fe2ab251e3..8ac763ac4b 100644 --- a/test/core/handshake/client_ssl.cc +++ b/test/core/handshake/client_ssl.cc @@ -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,12 +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_options thdopt = gpr_thd_options_default(); - gpr_thd_id thdid; - gpr_thd_options_set_joinable(&thdopt); server_args args = {server_socket, server_alpn_preferred}; - GPR_ASSERT(gpr_thd_new(&thdid, "grpc_client_ssl_test", server_thread, &args, - &thdopt)); + 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; @@ -303,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(); diff --git a/test/core/handshake/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc index 80000ca8d3..9788320e0d 100644 --- a/test/core/handshake/readahead_handshaker_server_ssl.cc +++ b/test/core/handshake/readahead_handshaker_server_ssl.cc @@ -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" diff --git a/test/core/handshake/server_ssl.cc b/test/core/handshake/server_ssl.cc index f0465c8e3e..8fa5f7fb35 100644 --- a/test/core/handshake/server_ssl.cc +++ b/test/core/handshake/server_ssl.cc @@ -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" diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index d202a7cfd6..41b2829d8b 100644 --- a/test/core/handshake/server_ssl_common.cc +++ b/test/core/handshake/server_ssl_common.cc @@ -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,11 +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_options thdopt = gpr_thd_options_default(); - gpr_thd_id thdid; - gpr_thd_options_set_joinable(&thdopt); - GPR_ASSERT( - gpr_thd_new(&thdid, "grpc_ssl_test", server_thread, &port, &thdopt)); + 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(); @@ -235,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(); diff --git a/test/core/handshake/server_ssl_common.h b/test/core/handshake/server_ssl_common.h index f726a1cd3a..32bc6f9897 100644 --- a/test/core/handshake/server_ssl_common.h +++ b/test/core/handshake/server_ssl_common.h @@ -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" diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 8426b3d233..cf2c7db846 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -22,8 +22,8 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/thd.h" #include "test/core/util/test_config.h" static void test_no_op(void) { @@ -97,21 +97,19 @@ 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++) { - gpr_thd_options options = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&options); 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], &options)); + 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"); diff --git a/test/core/iomgr/error_test.cc b/test/core/iomgr/error_test.cc index f6292b72a9..a1628a1f71 100644 --- a/test/core/iomgr/error_test.cc +++ b/test/core/iomgr/error_test.cc @@ -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() { diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index 02d11271ec..c3ba6d7c14 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -30,8 +30,8 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/iomgr.h" #include "test/core/util/test_config.h" @@ -259,11 +259,10 @@ static void test_threading(void) { shared.pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(shared.pollset, &shared.mu); - gpr_thd_id thds[10]; - for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { - gpr_thd_options opt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&thds[i], "test_thread", test_threading_loop, &shared, &opt); + grpc_core::Thread thds[10]; + for (auto& th : thds) { + th = grpc_core::Thread("test_thread", test_threading_loop, &shared); + th.Start(); } grpc_wakeup_fd fd; GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&fd))); @@ -280,8 +279,8 @@ static void test_threading(void) { } GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_first", grpc_wakeup_fd_wakeup(shared.wakeup_fd))); - for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { - gpr_thd_join(thds[i]); + for (auto& th : thds) { + th.Join(); } fd.read_fd = 0; grpc_wakeup_fd_destroy(&fd); diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index 341579f178..79b2b50e70 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -27,8 +27,8 @@ #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 "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/iomgr.h" #include "test/core/util/test_config.h" @@ -38,6 +38,7 @@ static gpr_timespec test_deadline(void) { } typedef struct args_struct { + grpc_core::Thread thd; gpr_event ev; grpc_resolved_addresses* addrs; gpr_atm done_atm; @@ -59,6 +60,9 @@ void args_init(args_struct* args) { void args_finish(args_struct* args) { GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline())); + 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); @@ -101,8 +105,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_id id; - gpr_thd_new(&id, "grpc_poll_pollset", actually_poll, args, nullptr); + args->thd = grpc_core::Thread("grpc_poll_pollset", actually_poll, args); + args->thd.Start(); } static void must_succeed(void* argsp, grpc_error* err) { diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc index 68dcb50aa6..9bd7c6e47e 100644 --- a/test/core/iomgr/wakeup_fd_cv_test.cc +++ b/test/core/iomgr/wakeup_fd_cv_test.cc @@ -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,8 +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_thd_options opt; GPR_ASSERT(grpc_wakeup_fd_init(&cvfd1) == GRPC_ERROR_NONE); GPR_ASSERT(grpc_wakeup_fd_init(&cvfd2) == GRPC_ERROR_NONE); @@ -135,79 +133,91 @@ void test_poll_cv_trigger(void) { pargs.timeout = 1000; pargs.result = -2; - opt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt); - - // Wakeup wakeup_fd not listening for events - GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd1) == GRPC_ERROR_NONE); - gpr_thd_join(t_id); - GPR_ASSERT(pargs.result == 0); - GPR_ASSERT(pfds[0].revents == 0); - GPR_ASSERT(pfds[1].revents == 0); - GPR_ASSERT(pfds[2].revents == 0); - 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, &opt); - trigger_socket_event(); - gpr_thd_join(t_id); - GPR_ASSERT(pargs.result == 1); - GPR_ASSERT(pfds[0].revents == 0); - GPR_ASSERT(pfds[1].revents == 0); - GPR_ASSERT(pfds[2].revents == POLLIN); - 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, &opt); - GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd2) == GRPC_ERROR_NONE); - gpr_thd_join(t_id); - - GPR_ASSERT(pargs.result == 1); - GPR_ASSERT(pfds[0].revents == 0); - GPR_ASSERT(pfds[1].revents == POLLIN); - GPR_ASSERT(pfds[2].revents == 0); - 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, &opt); - gpr_thd_join(t_id); - - GPR_ASSERT(pargs.result == 1); - GPR_ASSERT(pfds[0].revents == 0); - GPR_ASSERT(pfds[1].revents == POLLIN); - GPR_ASSERT(pfds[2].revents == 0); - 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, &opt); - gpr_thd_join(t_id); - - GPR_ASSERT(pargs.result == 0); - GPR_ASSERT(pfds[0].revents == 0); - GPR_ASSERT(pfds[1].revents == 0); - GPR_ASSERT(pfds[2].revents == 0); - GPR_ASSERT(pfds[3].revents == 0); - GPR_ASSERT(pfds[4].revents == 0); - GPR_ASSERT(pfds[5].revents == 0); + { + 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); + thd.Join(); + GPR_ASSERT(pargs.result == 0); + GPR_ASSERT(pfds[0].revents == 0); + GPR_ASSERT(pfds[1].revents == 0); + GPR_ASSERT(pfds[2].revents == 0); + 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; + grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs); + thd.Start(); + trigger_socket_event(); + thd.Join(); + GPR_ASSERT(pargs.result == 1); + GPR_ASSERT(pfds[0].revents == 0); + GPR_ASSERT(pfds[1].revents == 0); + GPR_ASSERT(pfds[2].revents == POLLIN); + 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; + grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs); + thd.Start(); + GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd2) == GRPC_ERROR_NONE); + thd.Join(); + + GPR_ASSERT(pargs.result == 1); + GPR_ASSERT(pfds[0].revents == 0); + GPR_ASSERT(pfds[1].revents == POLLIN); + GPR_ASSERT(pfds[2].revents == 0); + 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; + 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); + GPR_ASSERT(pfds[1].revents == POLLIN); + GPR_ASSERT(pfds[2].revents == 0); + 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); + 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); + GPR_ASSERT(pfds[1].revents == 0); + GPR_ASSERT(pfds[2].revents == 0); + GPR_ASSERT(pfds[3].revents == 0); + GPR_ASSERT(pfds[4].revents == 0); + GPR_ASSERT(pfds[5].revents == 0); + } } int main(int argc, char** argv) { diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc index 33716b9d4a..a983b1876d 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.cc +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -38,8 +38,8 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/socket_utils_posix.h" #include "test/core/util/cmdline.h" @@ -575,7 +575,6 @@ int create_socket(const char* socket_type, fd_pair* client_fds, static int run_benchmark(const char* socket_type, thread_args* client_args, thread_args* server_args) { - gpr_thd_id tid; int rv = 0; rv = create_socket(socket_type, &client_args->fds, &server_args->fds); @@ -586,8 +585,11 @@ static int run_benchmark(const char* socket_type, thread_args* client_args, gpr_log(GPR_INFO, "Starting test %s %s %zu", client_args->strategy_name, socket_type, client_args->msg_size); - gpr_thd_new(&tid, "server_thread", server_thread_wrap, server_args, nullptr); + grpc_core::Thread server("server_thread", server_thread_wrap, server_args); + server.Start(); client_thread(client_args); + server.Join(); + return 0; } diff --git a/test/core/statistics/rpc_stats_test.cc b/test/core/statistics/rpc_stats_test.cc index ff48075365..a2a648e2ad 100644 --- a/test/core/statistics/rpc_stats_test.cc +++ b/test/core/statistics/rpc_stats_test.cc @@ -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 */ diff --git a/test/core/surface/byte_buffer_reader_test.cc b/test/core/surface/byte_buffer_reader_test.cc index 861ed5d1a8..cff05caec1 100644 --- a/test/core/surface/byte_buffer_reader_test.cc +++ b/test/core/surface/byte_buffer_reader_test.cc @@ -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" diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 81319f4df4..9c8d8d8395 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -22,8 +22,8 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> -#include "src/core/lib/gpr/thd.h" #include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/iomgr.h" #include "test/core/util/test_config.h" @@ -78,16 +78,14 @@ 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)]; - gpr_thd_options thread_options = gpr_thd_options_default(); grpc_core::ExecCtx exec_ctx; unsigned i, j; LOG_TEST("test_too_many_plucks"); cc = grpc_completion_queue_create_for_pluck(nullptr); - gpr_thd_options_set_joinable(&thread_options); for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) { tags[i] = create_test_tag(); @@ -96,8 +94,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, - &thread_options); + threads[i] = + grpc_core::Thread("grpc_pluck_test", pluck_one, thread_states + i); + threads[i].Start(); } /* wait until all other threads are plucking */ @@ -113,8 +112,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); @@ -220,8 +219,9 @@ static void test_threading(size_t producers, size_t consumers) { "test_threading", producers, consumers); /* start all threads: they will wait for phase1 */ + grpc_core::Thread* threads = reinterpret_cast<grpc_core::Thread*>( + gpr_malloc(sizeof(*threads) * (producers + consumers))); for (i = 0; i < producers + consumers; i++) { - gpr_thd_id id; gpr_event_init(&options[i].on_started); gpr_event_init(&options[i].on_phase1_done); gpr_event_init(&options[i].on_finished); @@ -230,10 +230,13 @@ 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(&id, - i < producers ? "grpc_producer" : "grpc_consumer", - i < producers ? producer_thread : consumer_thread, - options + i, nullptr)); + + bool ok; + 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()); } @@ -266,6 +269,11 @@ static void test_threading(size_t producers, size_t consumers) { /* destroy the completion channel */ grpc_completion_queue_destroy(cc); + for (i = 0; i < producers + consumers; i++) { + threads[i].Join(); + } + gpr_free(threads); + /* verify that everything was produced and consumed */ for (i = 0; i < producers + consumers; i++) { if (i < producers) { diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 95af4abd48..c1298b6636 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -30,7 +30,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,73 +172,77 @@ int run_concurrent_connectivity_test() { grpc_init(); - gpr_thd_id threads[NUM_THREADS]; - gpr_thd_id server; - - char* localhost = gpr_strdup("localhost:54321"); - gpr_thd_options options = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&options); - /* 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, - &options); - } - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_join(threads[i]); + { + gpr_log(GPR_DEBUG, "Wave 1"); + char* localhost = gpr_strdup("localhost:54321"); + grpc_core::Thread threads[NUM_THREADS]; + for (auto& th : threads) { + th = grpc_core::Thread("grpc_wave_1", create_loop_destroy, localhost); + th.Start(); + } + for (auto& th : threads) { + th.Join(); + } + gpr_free(localhost); } - gpr_free(localhost); - /* Second round, actual grpc server */ - gpr_log(GPR_DEBUG, "Wave 2"); - int port = grpc_pick_unused_port_or_die(); - gpr_asprintf(&args.addr, "localhost:%d", port); - args.server = grpc_server_create(nullptr, nullptr); - grpc_server_add_insecure_http2_port(args.server, args.addr); - 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, &options); - - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "grpc_wave_2", create_loop_destroy, args.addr, - &options); - } - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_join(threads[i]); - } - grpc_server_shutdown_and_notify(args.server, args.cq, tag(0xd1e)); - - gpr_thd_join(server); - 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, - &options); - 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, - &options); - } - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_join(threads[i]); + { + /* Second round, actual grpc server */ + gpr_log(GPR_DEBUG, "Wave 2"); + int port = grpc_pick_unused_port_or_die(); + gpr_asprintf(&args.addr, "localhost:%d", port); + args.server = grpc_server_create(nullptr, nullptr); + grpc_server_add_insecure_http2_port(args.server, args.addr); + args.cq = grpc_completion_queue_create_for_next(nullptr); + grpc_server_register_completion_queue(args.server, args.cq, nullptr); + grpc_server_start(args.server); + grpc_core::Thread server2("grpc_wave_2_server", server_thread, &args); + server2.Start(); + + grpc_core::Thread threads[NUM_THREADS]; + for (auto& th : threads) { + 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)); + + server2.Join(); + grpc_server_destroy(args.server); + grpc_completion_queue_destroy(args.cq); + gpr_free(args.addr); } - gpr_atm_rel_store(&args.stop, 1); - gpr_thd_join(server); { - grpc_core::ExecCtx exec_ctx; - grpc_pollset_shutdown( - args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset, - grpc_schedule_on_exec_ctx)); + /* 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); + 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)); + + grpc_core::Thread threads[NUM_THREADS]; + for (auto& th : threads) { + th = grpc_core::Thread("grpc_wave_3", create_loop_destroy, args.addr); + th.Start(); + } + for (auto& th : threads) { + th.Join(); + } + + gpr_atm_rel_store(&args.stop, 1); + 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(); @@ -278,18 +282,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"); - gpr_thd_options options = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&options); - for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "grpc_short_watches", watches_with_short_timeouts, - localhost, &options); + for (auto& th : threads) { + 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); diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc index 49d28ad1c7..467deeeaec 100644 --- a/test/core/surface/num_external_connectivity_watchers_test.cc +++ b/test/core/surface/num_external_connectivity_watchers_test.cc @@ -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" diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index 428d17ff1b..9aba4c499e 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -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,10 +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_options thdopt = gpr_thd_options_default(); - gpr_thd_options_set_joinable(&thdopt); - gpr_thd_new(&server_thread, "grpc_server", server_thread_func, &sta, &thdopt); + 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]; @@ -95,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); diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc index 7af6431c66..8ea83f7088 100644 --- a/test/core/tsi/transport_security_test_lib.cc +++ b/test/core/tsi/transport_security_test_lib.cc @@ -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" diff --git a/test/cpp/client/client_channel_stress_test.cc b/test/cpp/client/client_channel_stress_test.cc index 1d2dcae94b..ee6958dfcf 100644 --- a/test/cpp/client/client_channel_stress_test.cc +++ b/test/cpp/client/client_channel_stress_test.cc @@ -35,8 +35,8 @@ #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/ref_counted_ptr.h" +#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/sockaddr.h" #include "test/core/util/port.h" diff --git a/test/cpp/cocoapods/generic/generic.mm b/test/cpp/cocoapods/generic/generic.mm index 5ca34f195c..26f09b0af0 100644 --- a/test/cpp/cocoapods/generic/generic.mm +++ b/test/cpp/cocoapods/generic/generic.mm @@ -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" diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index df706a2237..d3620584a9 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -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" diff --git a/test/cpp/end2end/client_crash_test.cc b/test/cpp/end2end/client_crash_test.cc index c28ffea79c..6bde6641b7 100644 --- a/test/cpp/end2end/client_crash_test.cc +++ b/test/cpp/end2end/client_crash_test.cc @@ -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" diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 16600d12b0..96a855c30e 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -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" diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 38fdde990f..1e2cdb8b62 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -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" diff --git a/test/cpp/end2end/filter_end2end_test.cc b/test/cpp/end2end/filter_end2end_test.cc index ae6c6c7d11..20804bc19e 100644 --- a/test/cpp/end2end/filter_end2end_test.cc +++ b/test/cpp/end2end/filter_end2end_test.cc @@ -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" diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 86a41fc585..42b15a06e9 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -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" diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index ce06ac83e9..33f485be93 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -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" #include "src/core/lib/security/credentials/fake/fake_credentials.h" diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index fe530432ea..e3976a4838 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -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" diff --git a/test/cpp/end2end/server_crash_test.cc b/test/cpp/end2end/server_crash_test.cc index 574d357bef..108dcd29e7 100644 --- a/test/cpp/end2end/server_crash_test.cc +++ b/test/cpp/end2end/server_crash_test.cc @@ -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" diff --git a/test/cpp/end2end/server_early_return_test.cc b/test/cpp/end2end/server_early_return_test.cc index 38f9b6755c..a0349fdc4c 100644 --- a/test/cpp/end2end/server_early_return_test.cc +++ b/test/cpp/end2end/server_early_return_test.cc @@ -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" diff --git a/test/cpp/end2end/streaming_throughput_test.cc b/test/cpp/end2end/streaming_throughput_test.cc index 2c8928151a..4dc1d1f1d9 100644 --- a/test/cpp/end2end/streaming_throughput_test.cc +++ b/test/cpp/end2end/streaming_throughput_test.cc @@ -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" diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 0842d8e64a..828beefea3 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -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" diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 5d67e35d40..ff5abc679d 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -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 \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index bf3de8ab22..57f9147f44 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1097,10 +1097,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.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 \ @@ -1129,6 +1125,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 \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 06aa989788..6b8b26f41b 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -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" @@ -8358,9 +8358,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.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", @@ -8370,6 +8367,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" ], @@ -8407,7 +8406,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", @@ -8421,6 +8419,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, @@ -8453,7 +8452,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", @@ -8467,6 +8465,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, |