From 5474e92292a37ea9017db02da1e8e6aea621b156 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 30 Aug 2018 17:21:07 -0700 Subject: Allocate using call arenas --- include/grpcpp/impl/codegen/callback_common.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'include/grpcpp/impl/codegen/callback_common.h') diff --git a/include/grpcpp/impl/codegen/callback_common.h b/include/grpcpp/impl/codegen/callback_common.h index b14ed0c24f..3481460c76 100644 --- a/include/grpcpp/impl/codegen/callback_common.h +++ b/include/grpcpp/impl/codegen/callback_common.h @@ -37,11 +37,14 @@ namespace internal { class CallbackWithStatusTag { public: - // TODO(vjpai): make impl and ops part of this structure to avoid allocation, - // ownership transfer, and delete - CallbackWithStatusTag(std::function f, bool self_delete, + // always allocated against a call arena, no memory free required + static void operator delete(void* ptr, std::size_t size) { + assert(size == sizeof(CallbackWithStatusTag)); + } + + CallbackWithStatusTag(grpc_call* call, std::function f, CompletionQueueTag* ops); - ~CallbackWithStatusTag() { delete ops_; } + ~CallbackWithStatusTag() {} void* tag() { return static_cast(impl_); } Status* status_ptr() { return status_; } CompletionQueueTag* ops() { return ops_; } @@ -57,11 +60,14 @@ class CallbackWithStatusTag { class CallbackWithSuccessTag { public: - // TODO(vjpai): make impl and ops part of this structure to avoid allocation, - // ownership transfer, and delete - CallbackWithSuccessTag(std::function f, bool self_delete, + // always allocated against a call arena, no memory free required + static void operator delete(void* ptr, std::size_t size) { + assert(size == sizeof(CallbackWithSuccessTag)); + } + + CallbackWithSuccessTag(grpc_call* call, std::function f, CompletionQueueTag* ops); - ~CallbackWithSuccessTag() { delete ops_; } + void* tag() { return static_cast(impl_); } CompletionQueueTag* ops() { return ops_; } -- cgit v1.2.3