Fix comments

pull/19696/head
Yunjia Wang 6 years ago
parent f78f3e4d6c
commit 7c10819641
  1. 6
      src/core/lib/iomgr/executor/mpmcqueue.cc
  2. 8
      src/core/lib/iomgr/executor/mpmcqueue.h
  3. 9
      test/core/iomgr/mpmcqueue_test.cc

@ -81,11 +81,11 @@ InfLenFIFOQueue::InfLenFIFOQueue() {
delete_list_ =
static_cast<Node**>(gpr_zalloc(sizeof(Node*) * delete_list_size_));
Node* new_chunk = AllocateNodes(kDeleteListInitSize);
Node* new_chunk = AllocateNodes(kQueueInitNumNodes);
delete_list_[delete_list_count_++] = new_chunk;
queue_head_ = queue_tail_ = new_chunk;
new_chunk[0].prev = &new_chunk[1023];
new_chunk[1023].next = &new_chunk[0];
new_chunk[0].prev = &new_chunk[kQueueInitNumNodes - 1];
new_chunk[kQueueInitNumNodes - 1].next = &new_chunk[0];
waiters_.next = &waiters_;
waiters_.prev = &waiters_;

@ -88,7 +88,7 @@ class InfLenFIFOQueue : public MPMCQueueInterface {
};
// For test purpose only. Returns number of nodes allocated in queue.
// All allocated nodes will not be free until destruction of queue.
// Any allocated node will be alive until the destruction of the queue.
int num_nodes() const { return num_nodes_; }
// For test purpose only. Returns the initial number of nodes in queue.
@ -147,8 +147,10 @@ class InfLenFIFOQueue : public MPMCQueueInterface {
Mutex mu_; // Protecting lock
Waiter waiters_; // Head of waiting thread queue
const int kDeleteListInitSize = 1024; // Initial size for delete list
const int kQueueInitNumNodes = 1024; // Initial number of nodes allocated
// Initial size for delete list
static const int kDeleteListInitSize = 1024;
// Initial number of nodes allocated
static const int kQueueInitNumNodes = 1024;
Node** delete_list_ = nullptr; // Keeps track of all allocated array entries
// for deleting on destruction

@ -127,7 +127,7 @@ static void test_space_efficiency(void) {
for (int i = 0; i < queue.init_num_nodes(); ++i) {
queue.Put(static_cast<void*>(grpc_core::New<WorkItem>(i)));
}
// List should not have been expanded at this time.
// Queue should not have been expanded at this time.
GPR_ASSERT(queue.num_nodes() == queue.init_num_nodes());
for (int i = 0; i < queue.init_num_nodes(); ++i) {
WorkItem* item = static_cast<WorkItem*>(queue.Get());
@ -138,6 +138,7 @@ static void test_space_efficiency(void) {
WorkItem* item = static_cast<WorkItem*>(queue.Get());
grpc_core::Delete(item);
}
// Queue never shrinks even it is empty.
GPR_ASSERT(queue.num_nodes() == queue.init_num_nodes());
GPR_ASSERT(queue.count() == 0);
// queue empty now
@ -145,20 +146,20 @@ static void test_space_efficiency(void) {
queue.Put(static_cast<void*>(grpc_core::New<WorkItem>(i)));
}
GPR_ASSERT(queue.count() == queue.init_num_nodes() * 2);
// List should have been expanded once.
// Queue should have been expanded once.
GPR_ASSERT(queue.num_nodes() == queue.init_num_nodes() * 2);
for (int i = 0; i < queue.init_num_nodes(); ++i) {
WorkItem* item = static_cast<WorkItem*>(queue.Get());
grpc_core::Delete(item);
}
GPR_ASSERT(queue.count() == queue.init_num_nodes());
// List will never shrink, should keep same number of node as before.
// Queue will never shrink, should keep same number of node as before.
GPR_ASSERT(queue.num_nodes() == queue.init_num_nodes() * 2);
for (int i = 0; i < queue.init_num_nodes() + 1; ++i) {
queue.Put(static_cast<void*>(grpc_core::New<WorkItem>(i)));
}
GPR_ASSERT(queue.count() == queue.init_num_nodes() * 2 + 1);
// List should have been expanded twice.
// Queue should have been expanded twice.
GPR_ASSERT(queue.num_nodes() == queue.init_num_nodes() * 4);
for (int i = 0; i < queue.init_num_nodes() * 2 + 1; ++i) {
WorkItem* item = static_cast<WorkItem*>(queue.Get());

Loading…
Cancel
Save