Remove a small allocation, at the cost of a little uglier header file.

This commit may or may not be a great tradeoff.
pull/5193/head
Vijay Pai 9 years ago
parent 29e1d95a21
commit 810a13e2d3
  1. 14
      include/grpc++/alarm.h
  2. 18
      src/cpp/common/alarm.cc

@ -36,6 +36,7 @@
#ifndef GRPCXX_ALARM_H
#define GRPCXX_ALARM_H
#include <grpc++/impl/codegen/completion_queue_tag.h>
#include <grpc++/impl/codegen/grpc_library.h>
#include <grpc++/impl/codegen/time.h>
@ -63,6 +64,19 @@ class Alarm : private GrpcLibrary {
void Cancel();
private:
class AlarmEntry : public CompletionQueueTag {
public:
AlarmEntry(void* tag) : tag_(tag) {}
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE {
*tag = tag_;
return true;
}
private:
void* tag_;
};
AlarmEntry tag_;
grpc_alarm* const alarm_; // owned
};

@ -32,29 +32,15 @@
#include <grpc++/alarm.h>
#include <grpc++/completion_queue.h>
#include <grpc++/impl/codegen/completion_queue_tag.h>
#include <grpc++/impl/grpc_library.h>
#include <grpc/grpc.h>
namespace grpc {
class AlarmEntry : public CompletionQueueTag {
public:
AlarmEntry(void* tag) : tag_(tag) {}
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE {
*tag = tag_;
delete this;
return true;
}
private:
void* tag_;
};
static internal::GrpcLibraryInitializer g_gli_initializer;
Alarm::Alarm(CompletionQueue* cq, gpr_timespec deadline, void* tag)
: alarm_(grpc_alarm_create(cq->cq(), deadline,
static_cast<void*>(new AlarmEntry(tag)))) {
: tag_(tag),
alarm_(grpc_alarm_create(cq->cq(), deadline, static_cast<void*>(&tag_))) {
g_gli_initializer.summon();
}

Loading…
Cancel
Save