05-thread.patch 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. diff --git a/src/core/lib/gprpp/posix/thd.cc b/src/core/lib/gprpp/posix/thd.cc
  2. index 2751b22..23598df 100644
  3. --- a/src/core/lib/gprpp/posix/thd.cc
  4. +++ b/src/core/lib/gprpp/posix/thd.cc
  5. @@ -19,6 +19,7 @@
  6. // Posix implementation for gpr threads.
  7. #include <grpc/support/port_platform.h>
  8. +#include <util/system/thread.h>
  9. #include <util/generic/string.h>
  10. #include <util/string/cast.h>
  11. @@ -118,19 +118,7 @@
  12. thd_arg arg = *static_cast<thd_arg*>(v);
  13. free(v);
  14. if (arg.name != nullptr) {
  15. -#if GPR_APPLE_PTHREAD_NAME
  16. - // Apple supports 64 characters, and will
  17. - // truncate if it's longer.
  18. - pthread_setname_np(arg.name);
  19. -#elif GPR_LINUX_PTHREAD_NAME
  20. - // Linux supports 16 characters max, and will
  21. - // error if it's longer.
  22. - char buf[16];
  23. - size_t buf_len = GPR_ARRAY_SIZE(buf) - 1;
  24. - strncpy(buf, arg.name, buf_len);
  25. - buf[buf_len] = '\0';
  26. - pthread_setname_np(pthread_self(), buf);
  27. -#endif // GPR_APPLE_PTHREAD_NAME
  28. + TThread::SetCurrentThreadName(arg.name);
  29. }
  30. gpr_mu_lock(&arg.thread->mu_);
  31. diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc
  32. index 2ad8972..26bfae0 100644
  33. --- a/src/core/lib/iomgr/executor.cc
  34. +++ b/src/core/lib/iomgr/executor.cc
  35. @@ -95,6 +95,8 @@ grpc_closure_scheduler
  36. {{default_enqueue_short, default_enqueue_long},
  37. {resolver_enqueue_short, resolver_enqueue_long}};
  38. +size_t threads_limit_ = 0;
  39. +
  40. } // namespace
  41. TraceFlag executor_trace(false, "executor");
  42. @@ -94,6 +94,15 @@ Executor::Executor(const char* name) : name_(name) {
  43. adding_thread_lock_ = GPR_SPINLOCK_STATIC_INITIALIZER;
  44. gpr_atm_rel_store(&num_threads_, 0);
  45. max_threads_ = std::max(1u, 2 * gpr_cpu_num_cores());
  46. + if (threads_limit_) {
  47. + max_threads_ = std::min(max_threads_, threads_limit_);
  48. + }
  49. +}
  50. +
  51. +size_t Executor::SetThreadsLimit(size_t count) {
  52. + size_t prev = threads_limit_;
  53. + threads_limit_ = count;
  54. + return prev;
  55. }
  56. void Executor::Init() { SetThreading(true); }
  57. diff --git a/src/core/lib/iomgr/executor.h b/src/core/lib/iomgr/executor.h
  58. index 9e47227..40d4817 100644
  59. --- a/src/core/lib/iomgr/executor.h
  60. +++ b/src/core/lib/iomgr/executor.h
  61. @@ -105,6 +105,9 @@ class Executor {
  62. // Return if the DEFAULT executor is threaded
  63. static bool IsThreadedDefault();
  64. + // Set the maximum numbers of executor treads
  65. + static size_t SetThreadsLimit(size_t count);
  66. +
  67. private:
  68. static size_t RunClosures(const char* executor_name, grpc_closure_list list);
  69. static void ThreadMain(void* arg);