Skip to content
Snippets Groups Projects
Commit 810a13e2 authored by Vijay Pai's avatar Vijay Pai
Browse files

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

This commit may or may not be a great tradeoff.
parent 29e1d95a
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#ifndef GRPCXX_ALARM_H #ifndef GRPCXX_ALARM_H
#define 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/grpc_library.h>
#include <grpc++/impl/codegen/time.h> #include <grpc++/impl/codegen/time.h>
...@@ -63,6 +64,19 @@ class Alarm : private GrpcLibrary { ...@@ -63,6 +64,19 @@ class Alarm : private GrpcLibrary {
void Cancel(); void Cancel();
private: 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 grpc_alarm* const alarm_; // owned
}; };
......
...@@ -32,29 +32,15 @@ ...@@ -32,29 +32,15 @@
#include <grpc++/alarm.h> #include <grpc++/alarm.h>
#include <grpc++/completion_queue.h> #include <grpc++/completion_queue.h>
#include <grpc++/impl/codegen/completion_queue_tag.h>
#include <grpc++/impl/grpc_library.h> #include <grpc++/impl/grpc_library.h>
#include <grpc/grpc.h> #include <grpc/grpc.h>
namespace grpc { 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; static internal::GrpcLibraryInitializer g_gli_initializer;
Alarm::Alarm(CompletionQueue* cq, gpr_timespec deadline, void* tag) Alarm::Alarm(CompletionQueue* cq, gpr_timespec deadline, void* tag)
: alarm_(grpc_alarm_create(cq->cq(), deadline, : tag_(tag),
static_cast<void*>(new AlarmEntry(tag)))) { alarm_(grpc_alarm_create(cq->cq(), deadline, static_cast<void*>(&tag_))) {
g_gli_initializer.summon(); g_gli_initializer.summon();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment