Modify locality

pull/19544/head
Yunjia Wang 6 years ago
parent 34c76f527d
commit 603054a29a
  1. 2
      src/core/lib/iomgr/executor/threadpool.cc
  2. 2
      src/core/lib/iomgr/executor/threadpool.h
  3. 40
      test/core/iomgr/threadpool_test.cc

@ -51,7 +51,7 @@ void ThreadPool::SharedThreadPoolConstructor() {
// All worker threads in thread pool must be joinable.
thread_options_.set_joinable(true);
// Create at least 1 worker threads.
// Create at least 1 worker thread.
if (num_threads_ <= 0) num_threads_ = 1;
queue_ = New<InfLenFIFOQueue>();

@ -102,7 +102,7 @@ class ThreadPool : public ThreadPoolInterface {
public:
// Creates a thread pool with size of "num_threads", with default thread name
// "ThreadPoolWorker" and all thread options set to default. If the given size
// is 0 or less, there will be 1 worker threads created inside pool.
// is 0 or less, there will be 1 worker thread created inside pool.
ThreadPool(int num_threads);
// Same as ThreadPool(int num_threads) constructor, except

@ -66,26 +66,6 @@ class SimpleFunctorForAdd : public grpc_experimental_completion_queue_functor {
grpc_core::Atomic<int> count_{0};
};
// Checks the given SimpleFunctorForAdd's count with a given number.
class SimpleFunctorCheckForAdd
: public grpc_experimental_completion_queue_functor {
public:
SimpleFunctorCheckForAdd(int ok, int* count) : count_(count) {
functor_run = &SimpleFunctorCheckForAdd::Run;
internal_success = ok;
}
~SimpleFunctorCheckForAdd() {}
static void Run(struct grpc_experimental_completion_queue_functor* cb,
int ok) {
auto* callback = static_cast<SimpleFunctorCheckForAdd*>(cb);
(*callback->count_)++;
GPR_ASSERT(*callback->count_ == callback->internal_success);
}
private:
int* count_;
};
static void test_add(void) {
gpr_log(GPR_INFO, "test_add");
grpc_core::ThreadPool* pool =
@ -157,6 +137,26 @@ static void test_multi_add(void) {
gpr_log(GPR_DEBUG, "Done.");
}
// Checks the current count with a given number.
class SimpleFunctorCheckForAdd
: public grpc_experimental_completion_queue_functor {
public:
SimpleFunctorCheckForAdd(int ok, int* count) : count_(count) {
functor_run = &SimpleFunctorCheckForAdd::Run;
internal_success = ok;
}
~SimpleFunctorCheckForAdd() {}
static void Run(struct grpc_experimental_completion_queue_functor* cb,
int ok) {
auto* callback = static_cast<SimpleFunctorCheckForAdd*>(cb);
(*callback->count_)++;
GPR_ASSERT(*callback->count_ == callback->internal_success);
}
private:
int* count_;
};
static void test_one_thread_FIFO(void) {
gpr_log(GPR_INFO, "test_one_thread_FIFO");
int counter = 0;

Loading…
Cancel
Save