Merge pull request #49 from vjpai/shptr

Pour one out for shared pointer
pull/10182/head
Craig Tiller 8 years ago committed by GitHub
commit 4cbf4d8030
  1. 2
      CMakeLists.txt
  2. 18
      Makefile
  3. 3
      build.yaml
  4. 1
      grpc.def
  5. 12
      include/grpc++/impl/codegen/async_unary_call.h
  6. 49
      include/grpc++/impl/codegen/call.h
  7. 2
      src/ruby/ext/grpc/rb_grpc_imports.generated.c
  8. 3
      src/ruby/ext/grpc/rb_grpc_imports.generated.h
  9. 2
      tools/run_tests/generated/sources_and_headers.json
  10. 8
      vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj

@ -8424,6 +8424,8 @@ target_include_directories(codegen_test_minimal
target_link_libraries(codegen_test_minimal target_link_libraries(codegen_test_minimal
${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES}
grpc
gpr
${_gRPC_GFLAGS_LIBRARIES} ${_gRPC_GFLAGS_LIBRARIES}
) )

@ -13505,28 +13505,28 @@ $(BINDIR)/$(CONFIG)/codegen_test_minimal: protobuf_dep_error
else else
$(BINDIR)/$(CONFIG)/codegen_test_minimal: $(PROTOBUF_DEP) $(CODEGEN_TEST_MINIMAL_OBJS) $(BINDIR)/$(CONFIG)/codegen_test_minimal: $(PROTOBUF_DEP) $(CODEGEN_TEST_MINIMAL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@" $(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@` $(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(CODEGEN_TEST_MINIMAL_OBJS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/codegen_test_minimal $(Q) $(LDXX) $(LDFLAGS) $(CODEGEN_TEST_MINIMAL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/codegen_test_minimal
endif endif
endif endif
$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/control.o: $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/control.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/messages.o: $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/messages.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/payloads.o: $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/payloads.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/services.o: $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/services.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/stats.o: $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/stats.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/test/cpp/codegen/codegen_test_minimal.o: $(OBJDIR)/$(CONFIG)/test/cpp/codegen/codegen_test_minimal.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_codegen_test_minimal: $(CODEGEN_TEST_MINIMAL_OBJS:.o=.dep) deps_codegen_test_minimal: $(CODEGEN_TEST_MINIMAL_OBJS:.o=.dep)

@ -3413,6 +3413,9 @@ targets:
- src/proto/grpc/testing/services.proto - src/proto/grpc/testing/services.proto
- src/proto/grpc/testing/stats.proto - src/proto/grpc/testing/stats.proto
- test/cpp/codegen/codegen_test_minimal.cc - test/cpp/codegen/codegen_test_minimal.cc
deps:
- grpc
- gpr
filegroups: filegroups:
- grpc++_codegen_base - grpc++_codegen_base
- grpc++_codegen_base_src - grpc++_codegen_base_src

@ -67,6 +67,7 @@ EXPORTS
grpc_channel_ping grpc_channel_ping
grpc_channel_register_call grpc_channel_register_call
grpc_channel_create_registered_call grpc_channel_create_registered_call
grpc_call_arena_alloc
grpc_call_start_batch grpc_call_start_batch
grpc_call_get_peer grpc_call_get_peer
grpc_call_set_load_reporting_cost_context grpc_call_set_load_reporting_cost_context

@ -61,6 +61,11 @@ template <class R>
class ClientAsyncResponseReader final class ClientAsyncResponseReader final
: public ClientAsyncResponseReaderInterface<R> { : public ClientAsyncResponseReaderInterface<R> {
public: public:
~ClientAsyncResponseReader() {
if (collection_ != nullptr && collection_->Unref()) {
delete collection_;
}
}
template <class W> template <class W>
static ClientAsyncResponseReader* Create(ChannelInterface* channel, static ClientAsyncResponseReader* Create(ChannelInterface* channel,
CompletionQueue* cq, CompletionQueue* cq,
@ -72,9 +77,10 @@ class ClientAsyncResponseReader final
grpc_call_arena_alloc(call.call(), sizeof(*reader))); grpc_call_arena_alloc(call.call(), sizeof(*reader)));
new (&reader->call_) Call(std::move(call)); new (&reader->call_) Call(std::move(call));
reader->context_ = context; reader->context_ = context;
new (&reader->collection_) std::shared_ptr<CallOpSetCollection>( reader->collection_ =
new (grpc_call_arena_alloc(call.call(), sizeof(CallOpSetCollection))) new (grpc_call_arena_alloc(call.call(), sizeof(CallOpSetCollection)))
CallOpSetCollection()); CallOpSetCollection();
reader->collection_->init_buf_.SetCollection(reader->collection_); reader->collection_->init_buf_.SetCollection(reader->collection_);
reader->collection_->init_buf_.SendInitialMetadata( reader->collection_->init_buf_.SendInitialMetadata(
context->send_initial_metadata_, context->initial_metadata_flags()); context->send_initial_metadata_, context->initial_metadata_flags());
@ -138,7 +144,7 @@ class ClientAsyncResponseReader final
// disable operator new // disable operator new
static void* operator new(std::size_t size); static void* operator new(std::size_t size);
}; };
std::shared_ptr<CallOpSetCollection> collection_; CallOpSetCollection* collection_;
}; };
template <class W> template <class W>

@ -34,6 +34,7 @@
#ifndef GRPCXX_IMPL_CODEGEN_CALL_H #ifndef GRPCXX_IMPL_CODEGEN_CALL_H
#define GRPCXX_IMPL_CODEGEN_CALL_H #define GRPCXX_IMPL_CODEGEN_CALL_H
#include <assert.h>
#include <cstring> #include <cstring>
#include <functional> #include <functional>
#include <map> #include <map>
@ -50,6 +51,7 @@
#include <grpc++/impl/codegen/status_helper.h> #include <grpc++/impl/codegen/status_helper.h>
#include <grpc++/impl/codegen/string_ref.h> #include <grpc++/impl/codegen/string_ref.h>
#include <grpc/impl/codegen/atm.h>
#include <grpc/impl/codegen/compression_types.h> #include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/grpc_types.h> #include <grpc/impl/codegen/grpc_types.h>
@ -523,14 +525,29 @@ class CallOpClientRecvStatus {
/// An abstract collection of CallOpSet's, to be used whenever /// An abstract collection of CallOpSet's, to be used whenever
/// CallOpSet objects must be thought of as a group. Each member /// CallOpSet objects must be thought of as a group. Each member
/// of the group should have a shared_ptr back to the collection, /// of the group should reference the collection, as will the object
/// as will the object that instantiates the collection, allowing /// that instantiates the collection, allowing for ref-counting.
/// for automatic ref-counting. In practice, any actual use should /// Any actual use should derive from this base class. This is specifically
/// derive from this base class. This is specifically necessary if /// necessary if some of the CallOpSet's in the collection are "Sneaky" and
/// some of the CallOpSet's in the collection are "Sneaky" and don't /// don't report back to the C++ layer CQ operations
/// report back to the C++ layer CQ operations class CallOpSetCollectionInterface {
class CallOpSetCollectionInterface public:
: public std::enable_shared_from_this<CallOpSetCollectionInterface> {}; CallOpSetCollectionInterface() {
gpr_atm_rel_store(&refs_, static_cast<gpr_atm>(1));
}
// always allocated against a call arena, no memory free required
static void operator delete(void* ptr, std::size_t size) {
}
void Ref() { gpr_atm_no_barrier_fetch_add(&refs_, static_cast<gpr_atm>(1)); }
bool Unref() {
gpr_atm old =
gpr_atm_full_fetch_add(&refs_, static_cast<gpr_atm>(-1));
return (old == static_cast<gpr_atm>(1));
}
private:
gpr_atm refs_;
};
/// An abstract collection of call ops, used to generate the /// An abstract collection of call ops, used to generate the
/// grpc_call_op structure to pass down to the lower layers, /// grpc_call_op structure to pass down to the lower layers,
@ -539,18 +556,26 @@ class CallOpSetCollectionInterface
/// API. /// API.
class CallOpSetInterface : public CompletionQueueTag { class CallOpSetInterface : public CompletionQueueTag {
public: public:
CallOpSetInterface() {} CallOpSetInterface() : collection_(nullptr) {}
~CallOpSetInterface() { ResetCollection(); }
/// Fills in grpc_op, starting from ops[*nops] and moving /// Fills in grpc_op, starting from ops[*nops] and moving
/// upwards. /// upwards.
virtual void FillOps(grpc_op* ops, size_t* nops) = 0; virtual void FillOps(grpc_op* ops, size_t* nops) = 0;
/// Mark this as belonging to a collection if needed /// Mark this as belonging to a collection if needed
void SetCollection(std::shared_ptr<CallOpSetCollectionInterface> collection) { void SetCollection(CallOpSetCollectionInterface* collection) {
collection_ = collection; collection_ = collection;
collection->Ref();
}
void ResetCollection() {
if (collection_ != nullptr && collection_->Unref()) {
delete collection_;
}
collection_ = nullptr;
} }
protected: protected:
std::shared_ptr<CallOpSetCollectionInterface> collection_; CallOpSetCollectionInterface* collection_;
}; };
/// Primary implementaiton of CallOpSetInterface. /// Primary implementaiton of CallOpSetInterface.
@ -588,7 +613,7 @@ class CallOpSet : public CallOpSetInterface,
this->Op5::FinishOp(status); this->Op5::FinishOp(status);
this->Op6::FinishOp(status); this->Op6::FinishOp(status);
*tag = return_tag_; *tag = return_tag_;
collection_.reset(); // drop the ref at this point ResetCollection(); // drop the ref at this point
return true; return true;
} }

@ -105,6 +105,7 @@ grpc_channel_create_call_type grpc_channel_create_call_import;
grpc_channel_ping_type grpc_channel_ping_import; grpc_channel_ping_type grpc_channel_ping_import;
grpc_channel_register_call_type grpc_channel_register_call_import; grpc_channel_register_call_type grpc_channel_register_call_import;
grpc_channel_create_registered_call_type grpc_channel_create_registered_call_import; grpc_channel_create_registered_call_type grpc_channel_create_registered_call_import;
grpc_call_arena_alloc_type grpc_call_arena_alloc_import;
grpc_call_start_batch_type grpc_call_start_batch_import; grpc_call_start_batch_type grpc_call_start_batch_import;
grpc_call_get_peer_type grpc_call_get_peer_import; grpc_call_get_peer_type grpc_call_get_peer_import;
grpc_call_set_load_reporting_cost_context_type grpc_call_set_load_reporting_cost_context_import; grpc_call_set_load_reporting_cost_context_type grpc_call_set_load_reporting_cost_context_import;
@ -399,6 +400,7 @@ void grpc_rb_load_imports(HMODULE library) {
grpc_channel_ping_import = (grpc_channel_ping_type) GetProcAddress(library, "grpc_channel_ping"); grpc_channel_ping_import = (grpc_channel_ping_type) GetProcAddress(library, "grpc_channel_ping");
grpc_channel_register_call_import = (grpc_channel_register_call_type) GetProcAddress(library, "grpc_channel_register_call"); grpc_channel_register_call_import = (grpc_channel_register_call_type) GetProcAddress(library, "grpc_channel_register_call");
grpc_channel_create_registered_call_import = (grpc_channel_create_registered_call_type) GetProcAddress(library, "grpc_channel_create_registered_call"); grpc_channel_create_registered_call_import = (grpc_channel_create_registered_call_type) GetProcAddress(library, "grpc_channel_create_registered_call");
grpc_call_arena_alloc_import = (grpc_call_arena_alloc_type) GetProcAddress(library, "grpc_call_arena_alloc");
grpc_call_start_batch_import = (grpc_call_start_batch_type) GetProcAddress(library, "grpc_call_start_batch"); grpc_call_start_batch_import = (grpc_call_start_batch_type) GetProcAddress(library, "grpc_call_start_batch");
grpc_call_get_peer_import = (grpc_call_get_peer_type) GetProcAddress(library, "grpc_call_get_peer"); grpc_call_get_peer_import = (grpc_call_get_peer_type) GetProcAddress(library, "grpc_call_get_peer");
grpc_call_set_load_reporting_cost_context_import = (grpc_call_set_load_reporting_cost_context_type) GetProcAddress(library, "grpc_call_set_load_reporting_cost_context"); grpc_call_set_load_reporting_cost_context_import = (grpc_call_set_load_reporting_cost_context_type) GetProcAddress(library, "grpc_call_set_load_reporting_cost_context");

@ -266,6 +266,9 @@ extern grpc_channel_register_call_type grpc_channel_register_call_import;
typedef grpc_call *(*grpc_channel_create_registered_call_type)(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, void *registered_call_handle, gpr_timespec deadline, void *reserved); typedef grpc_call *(*grpc_channel_create_registered_call_type)(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, void *registered_call_handle, gpr_timespec deadline, void *reserved);
extern grpc_channel_create_registered_call_type grpc_channel_create_registered_call_import; extern grpc_channel_create_registered_call_type grpc_channel_create_registered_call_import;
#define grpc_channel_create_registered_call grpc_channel_create_registered_call_import #define grpc_channel_create_registered_call grpc_channel_create_registered_call_import
typedef void *(*grpc_call_arena_alloc_type)(grpc_call *call, size_t size);
extern grpc_call_arena_alloc_type grpc_call_arena_alloc_import;
#define grpc_call_arena_alloc grpc_call_arena_alloc_import
typedef grpc_call_error(*grpc_call_start_batch_type)(grpc_call *call, const grpc_op *ops, size_t nops, void *tag, void *reserved); typedef grpc_call_error(*grpc_call_start_batch_type)(grpc_call *call, const grpc_op *ops, size_t nops, void *tag, void *reserved);
extern grpc_call_start_batch_type grpc_call_start_batch_import; extern grpc_call_start_batch_type grpc_call_start_batch_import;
#define grpc_call_start_batch grpc_call_start_batch_import #define grpc_call_start_batch grpc_call_start_batch_import

@ -2816,6 +2816,8 @@
}, },
{ {
"deps": [ "deps": [
"gpr",
"grpc",
"grpc++_codegen_base", "grpc++_codegen_base",
"grpc++_codegen_base_src" "grpc++_codegen_base_src"
], ],

@ -256,6 +256,14 @@
<ClCompile Include="$(SolutionDir)\..\src\cpp\codegen\codegen_init.cc"> <ClCompile Include="$(SolutionDir)\..\src\cpp\codegen\codegen_init.cc">
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\..\vsprojects\vcxproj\.\grpc\grpc.vcxproj">
<Project>{29D16885-7228-4C31-81ED-5F9187C7F2A9}</Project>
</ProjectReference>
<ProjectReference Include="$(SolutionDir)\..\vsprojects\vcxproj\.\gpr\gpr.vcxproj">
<Project>{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save