Minor changes and fixes

pull/14583/head
Vijay Pai 7 years ago
parent b357f2f548
commit 756caa7c6a
  1. 32
      BUILD
  2. 2
      src/core/lib/gprpp/thd_posix.cc
  3. 35
      src/core/lib/gprpp/thd_windows.cc
  4. 21
      test/core/gprpp/BUILD

32
BUILD

@ -527,8 +527,6 @@ grpc_cc_library(
"src/core/lib/gpr/sync.cc", "src/core/lib/gpr/sync.cc",
"src/core/lib/gpr/sync_posix.cc", "src/core/lib/gpr/sync_posix.cc",
"src/core/lib/gpr/sync_windows.cc", "src/core/lib/gpr/sync_windows.cc",
"src/core/lib/gprpp/thd_posix.cc",
"src/core/lib/gprpp/thd_windows.cc",
"src/core/lib/gpr/time.cc", "src/core/lib/gpr/time.cc",
"src/core/lib/gpr/time_posix.cc", "src/core/lib/gpr/time_posix.cc",
"src/core/lib/gpr/time_precise.cc", "src/core/lib/gpr/time_precise.cc",
@ -538,6 +536,8 @@ grpc_cc_library(
"src/core/lib/gpr/tmpfile_posix.cc", "src/core/lib/gpr/tmpfile_posix.cc",
"src/core/lib/gpr/tmpfile_windows.cc", "src/core/lib/gpr/tmpfile_windows.cc",
"src/core/lib/gpr/wrap_memcpy.cc", "src/core/lib/gpr/wrap_memcpy.cc",
"src/core/lib/gprpp/thd_posix.cc",
"src/core/lib/gprpp/thd_windows.cc",
"src/core/lib/profiling/basic_timers.cc", "src/core/lib/profiling/basic_timers.cc",
"src/core/lib/profiling/stap_timers.cc", "src/core/lib/profiling/stap_timers.cc",
], ],
@ -551,7 +551,6 @@ grpc_cc_library(
"src/core/lib/gpr/spinlock.h", "src/core/lib/gpr/spinlock.h",
"src/core/lib/gpr/string.h", "src/core/lib/gpr/string.h",
"src/core/lib/gpr/string_windows.h", "src/core/lib/gpr/string_windows.h",
"src/core/lib/gprpp/thd.h",
"src/core/lib/gpr/time_precise.h", "src/core/lib/gpr/time_precise.h",
"src/core/lib/gpr/tls.h", "src/core/lib/gpr/tls.h",
"src/core/lib/gpr/tls_gcc.h", "src/core/lib/gpr/tls_gcc.h",
@ -559,6 +558,10 @@ grpc_cc_library(
"src/core/lib/gpr/tls_pthread.h", "src/core/lib/gpr/tls_pthread.h",
"src/core/lib/gpr/tmpfile.h", "src/core/lib/gpr/tmpfile.h",
"src/core/lib/gpr/useful.h", "src/core/lib/gpr/useful.h",
"src/core/lib/gprpp/abstract.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/thd.h",
"src/core/lib/profiling/timers.h", "src/core/lib/profiling/timers.h",
], ],
language = "c++", language = "c++",
@ -600,16 +603,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( grpc_cc_library(
name = "atomic", name = "atomic",
hdrs = [ hdrs = [
@ -632,7 +625,7 @@ grpc_cc_library(
"src/core/lib/gprpp/inlined_vector.h", "src/core/lib/gprpp/inlined_vector.h",
], ],
deps = [ deps = [
"gpr++_base", "gpr_base",
], ],
) )
@ -648,7 +641,7 @@ grpc_cc_library(
public_hdrs = ["src/core/lib/gprpp/orphanable.h"], public_hdrs = ["src/core/lib/gprpp/orphanable.h"],
deps = [ deps = [
"debug_location", "debug_location",
"gpr++_base", "gpr_base",
"grpc_trace", "grpc_trace",
"ref_counted_ptr", "ref_counted_ptr",
], ],
@ -660,7 +653,7 @@ grpc_cc_library(
public_hdrs = ["src/core/lib/gprpp/ref_counted.h"], public_hdrs = ["src/core/lib/gprpp/ref_counted.h"],
deps = [ deps = [
"debug_location", "debug_location",
"gpr++_base", "gpr_base",
"grpc_trace", "grpc_trace",
"ref_counted_ptr", "ref_counted_ptr",
], ],
@ -671,7 +664,7 @@ grpc_cc_library(
language = "c++", language = "c++",
public_hdrs = ["src/core/lib/gprpp/ref_counted_ptr.h"], public_hdrs = ["src/core/lib/gprpp/ref_counted_ptr.h"],
deps = [ deps = [
"gpr++_base", "gpr_base",
], ],
) )
@ -942,13 +935,12 @@ grpc_cc_library(
language = "c++", language = "c++",
public_hdrs = GRPC_PUBLIC_HDRS, public_hdrs = GRPC_PUBLIC_HDRS,
deps = [ deps = [
"gpr++_base",
"gpr_base", "gpr_base",
"grpc_codegen", "grpc_codegen",
"grpc_trace", "grpc_trace",
"inlined_vector",
"ref_counted", "ref_counted",
"ref_counted_ptr", "ref_counted_ptr",
"inlined_vector",
], ],
) )
@ -1424,7 +1416,7 @@ grpc_cc_library(
], ],
language = "c++", language = "c++",
deps = [ deps = [
"gpr++_base", "gpr_base",
"grpc_base", "grpc_base",
"grpc_http_filters", "grpc_http_filters",
"grpc_transport_chttp2_alpn", "grpc_transport_chttp2_alpn",

@ -165,7 +165,7 @@ class ThreadInternalsPosix
Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg, Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg,
bool* success) { bool* success) {
bool outcome; bool outcome = false;
impl_ = impl_ =
grpc_core::New<ThreadInternalsPosix>(thd_name, thd_body, arg, &outcome); grpc_core::New<ThreadInternalsPosix>(thd_name, thd_body, arg, &outcome);
if (outcome) { if (outcome) {

@ -52,28 +52,22 @@ struct thd_info {
thread_local struct thd_info* g_thd_info; thread_local struct thd_info* g_thd_info;
/* Destroys a thread info */
void destroy_thread(struct thd_info* t) {
CloseHandle(t->join_event);
gpr_free(t);
}
class ThreadInternalsWindows class ThreadInternalsWindows
: public grpc_core::internal::ThreadInternalsInterface { : public grpc_core::internal::ThreadInternalsInterface {
public: public:
ThreadInternalsWindows(void (*thd_body)(void* arg), void* arg, ThreadInternalsWindows(void (*thd_body)(void* arg), void* arg, bool* success)
bool* success) { : started_(false) {
gpr_mu_init(&mu_); gpr_mu_init(&mu_);
gpr_cv_init(&ready_); gpr_cv_init(&ready_);
HANDLE handle; HANDLE handle;
info_ = (struct thd_info*)gpr_malloc(sizeof(*info_)); info_ = (struct thd_info*)gpr_malloc(sizeof(*info_));
info->thread = this; info_->thread = this;
info->body = thd_body; info_->body = thd_body;
info->arg = arg; info_->arg = arg;
info->join_event = CreateEvent(nullptr, FALSE, FALSE, nullptr); info_->join_event = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (info->join_event == nullptr) { if (info_->join_event == nullptr) {
gpr_free(info_); gpr_free(info_);
*success = false; *success = false;
} else { } else {
@ -92,10 +86,10 @@ class ThreadInternalsWindows
GPR_ASSERT(ret); GPR_ASSERT(ret);
return 0; return 0;
}, },
info, 0, nullptr); info_, 0, nullptr);
if (handle == nullptr) { if (handle == nullptr) {
destroy_thread(info_); destroy_thread();
*success_ = false; *success = false;
} else { } else {
CloseHandle(handle); CloseHandle(handle);
*success = true; *success = true;
@ -118,10 +112,15 @@ class ThreadInternalsWindows
void Join() override { void Join() override {
DWORD ret = WaitForSingleObject(info_->join_event, INFINITE); DWORD ret = WaitForSingleObject(info_->join_event, INFINITE);
GPR_ASSERT(ret == WAIT_OBJECT_0); GPR_ASSERT(ret == WAIT_OBJECT_0);
destroy_thread(info_); destroy_thread();
} }
private: private:
void destroy_thread() {
CloseHandle(info_->join_event);
gpr_free(info_);
}
gpr_mu mu_; gpr_mu mu_;
gpr_cv ready_; gpr_cv ready_;
bool started_; bool started_;
@ -141,7 +140,7 @@ bool Thread::AwaitAll(gpr_timespec deadline) {
Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg, Thread::Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg,
bool* success) { bool* success) {
bool outcome; bool outcome = false;
impl_ = grpc_core::New<ThreadInternalsWindows>(thd_body, arg, &outcome); impl_ = grpc_core::New<ThreadInternalsWindows>(thd_body, arg, &outcome);
if (outcome) { if (outcome) {
state_ = ALIVE; state_ = ALIVE;

@ -24,7 +24,6 @@ grpc_cc_test(
language = "C++", language = "C++",
deps = [ deps = [
"//:gpr", "//:gpr",
"//:gpr++_base",
"//test/core/util:gpr_test_util", "//test/core/util:gpr_test_util",
], ],
) )
@ -37,7 +36,7 @@ grpc_cc_test(
], ],
language = "C++", language = "C++",
deps = [ deps = [
"//:gpr++_base", "//:gpr_base",
"//test/core/util:gpr_test_util", "//test/core/util:gpr_test_util",
], ],
) )
@ -58,41 +57,41 @@ grpc_cc_test(
grpc_cc_test( grpc_cc_test(
name = "orphanable_test", name = "orphanable_test",
srcs = ["orphanable_test.cc"], srcs = ["orphanable_test.cc"],
external_deps = [
"gtest",
],
language = "C++", language = "C++",
deps = [ deps = [
"//:orphanable", "//:orphanable",
"//test/core/util:gpr_test_util", "//test/core/util:gpr_test_util",
], ],
external_deps = [
"gtest",
],
) )
grpc_cc_test( grpc_cc_test(
name = "ref_counted_test", name = "ref_counted_test",
srcs = ["ref_counted_test.cc"], srcs = ["ref_counted_test.cc"],
external_deps = [
"gtest",
],
language = "C++", language = "C++",
deps = [ deps = [
"//:ref_counted", "//:ref_counted",
"//test/core/util:gpr_test_util", "//test/core/util:gpr_test_util",
], ],
external_deps = [
"gtest",
],
) )
grpc_cc_test( grpc_cc_test(
name = "ref_counted_ptr_test", name = "ref_counted_ptr_test",
srcs = ["ref_counted_ptr_test.cc"], srcs = ["ref_counted_ptr_test.cc"],
external_deps = [
"gtest",
],
language = "C++", language = "C++",
deps = [ deps = [
"//:ref_counted", "//:ref_counted",
"//:ref_counted_ptr", "//:ref_counted_ptr",
"//test/core/util:gpr_test_util", "//test/core/util:gpr_test_util",
], ],
external_deps = [
"gtest",
],
) )
grpc_cc_test( grpc_cc_test(

Loading…
Cancel
Save