Modify Node allocate/deallocate

pull/19358/head
Yunjia Wang 6 years ago
parent 2fbd77aee4
commit a3a5685d29
  1. 7
      src/core/lib/iomgr/executor/mpmcqueue.cc
  2. 5
      src/core/lib/iomgr/executor/mpmcqueue.h
  3. 1
      test/core/iomgr/mpmcqueue_test.cc

@ -45,7 +45,7 @@ inline void* MPMCQueue::PopFront() {
gpr_timespec wait_time =
gpr_time_sub(gpr_now(GPR_CLOCK_PRECISE), head_to_remove->insert_time);
delete head_to_remove;
gpr_free(head_to_remove);
// Update Stats info
stats_.num_completed++;
@ -86,7 +86,10 @@ MPMCQueue::~MPMCQueue() {
void MPMCQueue::Put(void* elem) {
MutexLock l(&mu_);
Node* new_node = static_cast<Node*>(new Node(elem));
Node* new_node = static_cast<Node*>(gpr_malloc(sizeof(Node)));
new_node->next = nullptr;
new_node->content = elem;
new_node->insert_time = gpr_now(GPR_CLOCK_PRECISE);
if (count_.Load(MemoryOrder::RELAXED) == 0) {
busy_time = gpr_now(GPR_CLOCK_PRECISE);
queue_head_ = queue_tail_ = new_node;

@ -47,9 +47,7 @@ class MPMCQueueInterface {
virtual void* Get() GRPC_ABSTRACT;
// Return number of elements in the queue currently
virtual int count() const GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
virtual int count() const GRPC_ABSTRACT;
};
class MPMCQueue : public MPMCQueueInterface {
@ -92,7 +90,6 @@ class MPMCQueue : public MPMCQueueInterface {
next = nullptr;
insert_time = gpr_now(GPR_CLOCK_PRECISE);
}
GRPC_ABSTRACT_BASE_CLASS
};
struct Stats { // Stats of queue

@ -58,6 +58,7 @@ static void test_small_queue(void) {
GPR_ASSERT(i == item->index);
delete item;
}
gpr_log(GPR_DEBUG, "Done.");
}
static void test_get_thd(void* args) {

Loading…
Cancel
Save