From bf18428740ebf0f36b68fcf9b7d427538e074a31 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Tue, 21 Mar 2017 15:18:58 -0700 Subject: [PATCH 1/6] Introduce grpc_completion_queue_factory API Just the API and a bare-bone implementation --- CMakeLists.txt | 5 ++ Makefile | 5 ++ binding.gyp | 1 + build.yaml | 2 + config.m4 | 1 + gRPC-Core.podspec | 3 + grpc.def | 3 + grpc.gemspec | 2 + include/grpc/grpc.h | 64 ++++++++++++++++ package.xml | 2 + .../lib/surface/completion_queue_factory.c | 75 +++++++++++++++++++ .../lib/surface/completion_queue_factory.h | 51 +++++++++++++ src/python/grpcio/grpc_core_dependencies.py | 1 + src/ruby/ext/grpc/rb_grpc_imports.generated.c | 6 ++ src/ruby/ext/grpc/rb_grpc_imports.generated.h | 9 +++ tools/doxygen/Doxyfile.core.internal | 2 + .../generated/sources_and_headers.json | 3 + tools/run_tests/generated/tests.json | 1 + vsprojects/vcxproj/grpc/grpc.vcxproj | 3 + vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 6 ++ .../grpc_test_util/grpc_test_util.vcxproj | 3 + .../grpc_test_util.vcxproj.filters | 6 ++ .../grpc_unsecure/grpc_unsecure.vcxproj | 3 + .../grpc_unsecure.vcxproj.filters | 6 ++ 24 files changed, 263 insertions(+) create mode 100644 src/core/lib/surface/completion_queue_factory.c create mode 100644 src/core/lib/surface/completion_queue_factory.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 851aeb8401b..950b8b62e7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -965,6 +965,7 @@ add_library(grpc src/core/lib/surface/channel_ping.c src/core/lib/surface/channel_stack_type.c src/core/lib/surface/completion_queue.c + src/core/lib/surface/completion_queue_factory.c src/core/lib/surface/event_string.c src/core/lib/surface/lame_client.c src/core/lib/surface/metadata_array.c @@ -1277,6 +1278,7 @@ add_library(grpc_cronet src/core/lib/surface/channel_ping.c src/core/lib/surface/channel_stack_type.c src/core/lib/surface/completion_queue.c + src/core/lib/surface/completion_queue_factory.c src/core/lib/surface/event_string.c src/core/lib/surface/lame_client.c src/core/lib/surface/metadata_array.c @@ -1580,6 +1582,7 @@ add_library(grpc_test_util src/core/lib/surface/channel_ping.c src/core/lib/surface/channel_stack_type.c src/core/lib/surface/completion_queue.c + src/core/lib/surface/completion_queue_factory.c src/core/lib/surface/event_string.c src/core/lib/surface/lame_client.c src/core/lib/surface/metadata_array.c @@ -1829,6 +1832,7 @@ add_library(grpc_unsecure src/core/lib/surface/channel_ping.c src/core/lib/surface/channel_stack_type.c src/core/lib/surface/completion_queue.c + src/core/lib/surface/completion_queue_factory.c src/core/lib/surface/event_string.c src/core/lib/surface/lame_client.c src/core/lib/surface/metadata_array.c @@ -2439,6 +2443,7 @@ add_library(grpc++_cronet src/core/lib/surface/channel_ping.c src/core/lib/surface/channel_stack_type.c src/core/lib/surface/completion_queue.c + src/core/lib/surface/completion_queue_factory.c src/core/lib/surface/event_string.c src/core/lib/surface/lame_client.c src/core/lib/surface/metadata_array.c diff --git a/Makefile b/Makefile index d2104e973c8..9a8a44b7d1b 100644 --- a/Makefile +++ b/Makefile @@ -2857,6 +2857,7 @@ LIBGRPC_SRC = \ src/core/lib/surface/channel_ping.c \ src/core/lib/surface/channel_stack_type.c \ src/core/lib/surface/completion_queue.c \ + src/core/lib/surface/completion_queue_factory.c \ src/core/lib/surface/event_string.c \ src/core/lib/surface/lame_client.c \ src/core/lib/surface/metadata_array.c \ @@ -3172,6 +3173,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/surface/channel_ping.c \ src/core/lib/surface/channel_stack_type.c \ src/core/lib/surface/completion_queue.c \ + src/core/lib/surface/completion_queue_factory.c \ src/core/lib/surface/event_string.c \ src/core/lib/surface/lame_client.c \ src/core/lib/surface/metadata_array.c \ @@ -3478,6 +3480,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/surface/channel_ping.c \ src/core/lib/surface/channel_stack_type.c \ src/core/lib/surface/completion_queue.c \ + src/core/lib/surface/completion_queue_factory.c \ src/core/lib/surface/event_string.c \ src/core/lib/surface/lame_client.c \ src/core/lib/surface/metadata_array.c \ @@ -3707,6 +3710,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/surface/channel_ping.c \ src/core/lib/surface/channel_stack_type.c \ src/core/lib/surface/completion_queue.c \ + src/core/lib/surface/completion_queue_factory.c \ src/core/lib/surface/event_string.c \ src/core/lib/surface/lame_client.c \ src/core/lib/surface/metadata_array.c \ @@ -4319,6 +4323,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/surface/channel_ping.c \ src/core/lib/surface/channel_stack_type.c \ src/core/lib/surface/completion_queue.c \ + src/core/lib/surface/completion_queue_factory.c \ src/core/lib/surface/event_string.c \ src/core/lib/surface/lame_client.c \ src/core/lib/surface/metadata_array.c \ diff --git a/binding.gyp b/binding.gyp index f79374a4469..957c343e4f1 100644 --- a/binding.gyp +++ b/binding.gyp @@ -711,6 +711,7 @@ 'src/core/lib/surface/channel_ping.c', 'src/core/lib/surface/channel_stack_type.c', 'src/core/lib/surface/completion_queue.c', + 'src/core/lib/surface/completion_queue_factory.c', 'src/core/lib/surface/event_string.c', 'src/core/lib/surface/lame_client.c', 'src/core/lib/surface/metadata_array.c', diff --git a/build.yaml b/build.yaml index 80c9849ca4a..8f339bdd08c 100644 --- a/build.yaml +++ b/build.yaml @@ -261,6 +261,7 @@ filegroups: - src/core/lib/surface/channel_init.h - src/core/lib/surface/channel_stack_type.h - src/core/lib/surface/completion_queue.h + - src/core/lib/surface/completion_queue_factory.h - src/core/lib/surface/event_string.h - src/core/lib/surface/init.h - src/core/lib/surface/lame_client.h @@ -383,6 +384,7 @@ filegroups: - src/core/lib/surface/channel_ping.c - src/core/lib/surface/channel_stack_type.c - src/core/lib/surface/completion_queue.c + - src/core/lib/surface/completion_queue_factory.c - src/core/lib/surface/event_string.c - src/core/lib/surface/lame_client.c - src/core/lib/surface/metadata_array.c diff --git a/config.m4 b/config.m4 index 3194b266690..0ca8c499f9e 100644 --- a/config.m4 +++ b/config.m4 @@ -184,6 +184,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/surface/channel_ping.c \ src/core/lib/surface/channel_stack_type.c \ src/core/lib/surface/completion_queue.c \ + src/core/lib/surface/completion_queue_factory.c \ src/core/lib/surface/event_string.c \ src/core/lib/surface/lame_client.c \ src/core/lib/surface/metadata_array.c \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 2444ffa57ab..b5ff7a51c7d 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -342,6 +342,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/channel_init.h', 'src/core/lib/surface/channel_stack_type.h', 'src/core/lib/surface/completion_queue.h', + 'src/core/lib/surface/completion_queue_factory.h', 'src/core/lib/surface/event_string.h', 'src/core/lib/surface/init.h', 'src/core/lib/surface/lame_client.h', @@ -554,6 +555,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/channel_ping.c', 'src/core/lib/surface/channel_stack_type.c', 'src/core/lib/surface/completion_queue.c', + 'src/core/lib/surface/completion_queue_factory.c', 'src/core/lib/surface/event_string.c', 'src/core/lib/surface/lame_client.c', 'src/core/lib/surface/metadata_array.c', @@ -782,6 +784,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/channel_init.h', 'src/core/lib/surface/channel_stack_type.h', 'src/core/lib/surface/completion_queue.h', + 'src/core/lib/surface/completion_queue_factory.h', 'src/core/lib/surface/event_string.h', 'src/core/lib/surface/init.h', 'src/core/lib/surface/lame_client.h', diff --git a/grpc.def b/grpc.def index 30d60b0d06d..1589316a588 100644 --- a/grpc.def +++ b/grpc.def @@ -53,6 +53,9 @@ EXPORTS grpc_shutdown grpc_version_string grpc_g_stands_for + grpc_completion_queue_factory_lookup + grpc_completion_queue_create_for_next + grpc_completion_queue_create_for_pluck grpc_completion_queue_create grpc_completion_queue_next grpc_completion_queue_pluck diff --git a/grpc.gemspec b/grpc.gemspec index 81e8733052b..d85cc5ebacb 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -259,6 +259,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/channel_init.h ) s.files += %w( src/core/lib/surface/channel_stack_type.h ) s.files += %w( src/core/lib/surface/completion_queue.h ) + s.files += %w( src/core/lib/surface/completion_queue_factory.h ) s.files += %w( src/core/lib/surface/event_string.h ) s.files += %w( src/core/lib/surface/init.h ) s.files += %w( src/core/lib/surface/lame_client.h ) @@ -471,6 +472,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/channel_ping.c ) s.files += %w( src/core/lib/surface/channel_stack_type.c ) s.files += %w( src/core/lib/surface/completion_queue.c ) + s.files += %w( src/core/lib/surface/completion_queue_factory.c ) s.files += %w( src/core/lib/surface/event_string.c ) s.files += %w( src/core/lib/surface/lame_client.c ) s.files += %w( src/core/lib/surface/metadata_array.c ) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 1b33d48c023..bcf64a6081a 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -93,6 +93,70 @@ GRPCAPI const char *grpc_version_string(void); /** Return a string specifying what the 'g' in gRPC stands for */ GRPCAPI const char *grpc_g_stands_for(void); +/** Specifies the type of APIs to use to pop events from the completion queue */ +typedef enum { + /* Events are popped out by calling grpc_completion_queue_next() API ONLY */ + GRPC_CQ_NEXT = 0, + + /* Events are popped out by calling grpc_completion_queue_pluck() API ONLY */ + GRPC_CQ_PLUCK +} grpc_cq_completion_type; + +/** Completion queues internally MAY maintain a set of file descriptors in a + structure called 'pollset'. This enum specifies if a completion queue has an + associated pollset and any restrictions on the type of file descriptors that + can be present in the pollset. + + I/O progress can only be made when grpc_completion_queue_next() or + grpc_completion_queue_pluck() are called on the completion queue (unless the + grpc_cq_polling_type is GRPC_CQ_NON_POLLING) and hence it is very important + to actively call these APIs */ +typedef enum { + /** The completion queue will have an associated pollset and there is no + restriction on the type of file descriptors the pollset may contain */ + GRPC_CQ_DEFAULT_POLLING, + + /* Similar to GRPC_CQ_DEFAULT_POLLING except that the completion queues will + not contain any 'listening file descriptors' (i.e file descriptors used to + listen to incoming channels) */ + GRPC_CQ_NON_LISTENING, + + /* The completion queue will not have an associated pollset. Note that + grpc_completion_queue_next() or grpc_completion_queue_pluck() MUST still be + called to pop events from the completion queue; it is not required to call + them actively to make I/O progress */ + GRPC_CQ_NON_POLLING +} grpc_cq_polling_type; + +typedef struct grpc_completion_queue_attributes { + /* The version number of this structure. More fields might be added to this + structure in future. */ + int version; /* Current version is 1 */ + + grpc_cq_completion_type cq_type; + + grpc_cq_polling_type cq_polling_type; +} grpc_completion_queue_attributes; + +/** The completion queue factory structure is opaque to the callers of grpc */ +typedef struct grpc_completion_queue_factory grpc_completion_queue_factory; + +/** Returns the completion queue factory based on the attributes. MAY return a + NULL if no factory can be found */ +GRPCAPI const grpc_completion_queue_factory * +grpc_completion_queue_factory_lookup( + const grpc_completion_queue_attributes *attributes); + +/** Helper function to create a completion queue with grpc_cq_completion_type + of GRPC_CQ_NEXT and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING */ +GRPCAPI grpc_completion_queue *grpc_completion_queue_create_for_next( + void *reserved); + +/** Helper function to create a completion queue with grpc_cq_completion_type + of GRPC_CQ_PLUCK and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING */ +GRPCAPI grpc_completion_queue *grpc_completion_queue_create_for_pluck( + void *reserved); + /** Create a completion queue */ GRPCAPI grpc_completion_queue *grpc_completion_queue_create(void *reserved); diff --git a/package.xml b/package.xml index c66706cfde7..a405c1f0434 100644 --- a/package.xml +++ b/package.xml @@ -268,6 +268,7 @@ + @@ -480,6 +481,7 @@ + diff --git a/src/core/lib/surface/completion_queue_factory.c b/src/core/lib/surface/completion_queue_factory.c new file mode 100644 index 00000000000..879b456ed5d --- /dev/null +++ b/src/core/lib/surface/completion_queue_factory.c @@ -0,0 +1,75 @@ +/* + * + * Copyright 2017, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/lib/surface/completion_queue_factory.h" +#include "src/core/lib/surface/completion_queue.h" + +#include + +/* TODO (sreek) - Currently this does not use the attributes arg. This will be + added in a future PR */ +static grpc_completion_queue* default_create( + const grpc_completion_queue_factory* factory, + const grpc_completion_queue_attributes* attributes) { + return grpc_completion_queue_create(NULL); +} + +static grpc_completion_queue_factory_vtable default_vtable = {default_create}; + +static const grpc_completion_queue_factory g_default_cq_factory = { + "Default Factory", NULL, &default_vtable}; + +const grpc_completion_queue_factory* grpc_completion_queue_factory_lookup( + const grpc_completion_queue_attributes* attributes) { + /* As we add more fields to grpc_completion_queue_attributes, we may have to + change this assert */ + GPR_ASSERT(attributes->version == 1); + + /* The default factory can handle version 1 of the attributes structure. We + may have to change this as more fields are added to the structure */ + return &g_default_cq_factory; +} + +grpc_completion_queue* grpc_completion_queue_create_for_next(void* reserved) { + GPR_ASSERT(!reserved); + grpc_completion_queue_attributes attr = {1, GRPC_CQ_NEXT, + GRPC_CQ_DEFAULT_POLLING}; + return g_default_cq_factory.vtable->create(&g_default_cq_factory, &attr); +} + +grpc_completion_queue* grpc_completion_queue_create_for_pluck(void* reserved) { + GPR_ASSERT(!reserved); + grpc_completion_queue_attributes attr = {1, GRPC_CQ_NEXT, + GRPC_CQ_DEFAULT_POLLING}; + return g_default_cq_factory.vtable->create(&g_default_cq_factory, &attr); +} diff --git a/src/core/lib/surface/completion_queue_factory.h b/src/core/lib/surface/completion_queue_factory.h new file mode 100644 index 00000000000..57e90b50907 --- /dev/null +++ b/src/core/lib/surface/completion_queue_factory.h @@ -0,0 +1,51 @@ +/* + * + * Copyright 2017, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_FACTORY_H +#define GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_FACTORY_H + +#include +#include "src/core/lib/surface/completion_queue.h" + +typedef struct grpc_completion_queue_factory_vtable { + grpc_completion_queue* (*create)(const grpc_completion_queue_factory*, + const grpc_completion_queue_attributes*); +} grpc_completion_queue_factory_vtable; + +struct grpc_completion_queue_factory { + const char* name; + void* data; /* Factory specific data */ + grpc_completion_queue_factory_vtable* vtable; +}; + +#endif /* GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_FACTORY_H */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 5fc748483a7..a9469046d4a 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -178,6 +178,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/surface/channel_ping.c', 'src/core/lib/surface/channel_stack_type.c', 'src/core/lib/surface/completion_queue.c', + 'src/core/lib/surface/completion_queue_factory.c', 'src/core/lib/surface/event_string.c', 'src/core/lib/surface/lame_client.c', 'src/core/lib/surface/metadata_array.c', diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 3ef6f0eb299..063f92114c0 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -91,6 +91,9 @@ grpc_init_type grpc_init_import; grpc_shutdown_type grpc_shutdown_import; grpc_version_string_type grpc_version_string_import; grpc_g_stands_for_type grpc_g_stands_for_import; +grpc_completion_queue_factory_lookup_type grpc_completion_queue_factory_lookup_import; +grpc_completion_queue_create_for_next_type grpc_completion_queue_create_for_next_import; +grpc_completion_queue_create_for_pluck_type grpc_completion_queue_create_for_pluck_import; grpc_completion_queue_create_type grpc_completion_queue_create_import; grpc_completion_queue_next_type grpc_completion_queue_next_import; grpc_completion_queue_pluck_type grpc_completion_queue_pluck_import; @@ -385,6 +388,9 @@ void grpc_rb_load_imports(HMODULE library) { grpc_shutdown_import = (grpc_shutdown_type) GetProcAddress(library, "grpc_shutdown"); grpc_version_string_import = (grpc_version_string_type) GetProcAddress(library, "grpc_version_string"); grpc_g_stands_for_import = (grpc_g_stands_for_type) GetProcAddress(library, "grpc_g_stands_for"); + grpc_completion_queue_factory_lookup_import = (grpc_completion_queue_factory_lookup_type) GetProcAddress(library, "grpc_completion_queue_factory_lookup"); + grpc_completion_queue_create_for_next_import = (grpc_completion_queue_create_for_next_type) GetProcAddress(library, "grpc_completion_queue_create_for_next"); + grpc_completion_queue_create_for_pluck_import = (grpc_completion_queue_create_for_pluck_type) GetProcAddress(library, "grpc_completion_queue_create_for_pluck"); grpc_completion_queue_create_import = (grpc_completion_queue_create_type) GetProcAddress(library, "grpc_completion_queue_create"); grpc_completion_queue_next_import = (grpc_completion_queue_next_type) GetProcAddress(library, "grpc_completion_queue_next"); grpc_completion_queue_pluck_import = (grpc_completion_queue_pluck_type) GetProcAddress(library, "grpc_completion_queue_pluck"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index ef9845dfe06..f5dcd68a8e9 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -224,6 +224,15 @@ extern grpc_version_string_type grpc_version_string_import; typedef const char *(*grpc_g_stands_for_type)(void); extern grpc_g_stands_for_type grpc_g_stands_for_import; #define grpc_g_stands_for grpc_g_stands_for_import +typedef const grpc_completion_queue_factory *(*grpc_completion_queue_factory_lookup_type)(const grpc_completion_queue_attributes *attributes); +extern grpc_completion_queue_factory_lookup_type grpc_completion_queue_factory_lookup_import; +#define grpc_completion_queue_factory_lookup grpc_completion_queue_factory_lookup_import +typedef grpc_completion_queue *(*grpc_completion_queue_create_for_next_type)(void *reserved); +extern grpc_completion_queue_create_for_next_type grpc_completion_queue_create_for_next_import; +#define grpc_completion_queue_create_for_next grpc_completion_queue_create_for_next_import +typedef grpc_completion_queue *(*grpc_completion_queue_create_for_pluck_type)(void *reserved); +extern grpc_completion_queue_create_for_pluck_type grpc_completion_queue_create_for_pluck_import; +#define grpc_completion_queue_create_for_pluck grpc_completion_queue_create_for_pluck_import typedef grpc_completion_queue *(*grpc_completion_queue_create_type)(void *reserved); extern grpc_completion_queue_create_type grpc_completion_queue_create_import; #define grpc_completion_queue_create grpc_completion_queue_create_import diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 89223630980..d9690a07ede 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1308,6 +1308,8 @@ src/core/lib/surface/channel_stack_type.c \ src/core/lib/surface/channel_stack_type.h \ src/core/lib/surface/completion_queue.c \ src/core/lib/surface/completion_queue.h \ +src/core/lib/surface/completion_queue_factory.c \ +src/core/lib/surface/completion_queue_factory.h \ src/core/lib/surface/event_string.c \ src/core/lib/surface/event_string.h \ src/core/lib/surface/init.c \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 9160b0d9d67..e6e9c7c933d 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -7547,6 +7547,7 @@ "src/core/lib/surface/channel_init.h", "src/core/lib/surface/channel_stack_type.h", "src/core/lib/surface/completion_queue.h", + "src/core/lib/surface/completion_queue_factory.h", "src/core/lib/surface/event_string.h", "src/core/lib/surface/init.h", "src/core/lib/surface/lame_client.h", @@ -7771,6 +7772,8 @@ "src/core/lib/surface/channel_stack_type.h", "src/core/lib/surface/completion_queue.c", "src/core/lib/surface/completion_queue.h", + "src/core/lib/surface/completion_queue_factory.c", + "src/core/lib/surface/completion_queue_factory.h", "src/core/lib/surface/event_string.c", "src/core/lib/surface/event_string.h", "src/core/lib/surface/init.h", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 1af05162b4f..8c708f09ee3 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -117505,6 +117505,7 @@ "language": "c", "name": "hpack_parser_fuzzer_test_one_entry", "platforms": [ + "mac", "linux" ], "uses_polling": false diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index 5e3b027663d..0123f3eb821 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -388,6 +388,7 @@ + @@ -705,6 +706,8 @@ + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index d75ca766c0d..f54379f0eef 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -310,6 +310,9 @@ src\core\lib\surface + + src\core\lib\surface + src\core\lib\surface @@ -1046,6 +1049,9 @@ src\core\lib\surface + + src\core\lib\surface + src\core\lib\surface diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index 62969e31acf..70a6d1806a1 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -283,6 +283,7 @@ + @@ -548,6 +549,8 @@ + + diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters index 30088101f5f..b4de56e564e 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -367,6 +367,9 @@ src\core\lib\surface + + src\core\lib\surface + src\core\lib\surface @@ -830,6 +833,9 @@ src\core\lib\surface + + src\core\lib\surface + src\core\lib\surface diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index 11ac8bd4b2b..8c2dcebfa26 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -378,6 +378,7 @@ + @@ -672,6 +673,8 @@ + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 414e2a50b89..b8ad369a5fc 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -313,6 +313,9 @@ src\core\lib\surface + + src\core\lib\surface + src\core\lib\surface @@ -956,6 +959,9 @@ src\core\lib\surface + + src\core\lib\surface + src\core\lib\surface From add6962d7af2fd3943c2f2d739bd13b3ce4b91d8 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Tue, 21 Mar 2017 16:12:39 -0700 Subject: [PATCH 2/6] Add version macro --- include/grpc/grpc.h | 4 +++- src/core/lib/surface/completion_queue_factory.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index bcf64a6081a..fa4fd6d49d0 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -128,10 +128,12 @@ typedef enum { GRPC_CQ_NON_POLLING } grpc_cq_polling_type; + +#define GRPC_CQ_CURRENT_VERSION 1 typedef struct grpc_completion_queue_attributes { /* The version number of this structure. More fields might be added to this structure in future. */ - int version; /* Current version is 1 */ + int version; /* Set to GRPC_CQ_CURRENT_VERSION */ grpc_cq_completion_type cq_type; diff --git a/src/core/lib/surface/completion_queue_factory.c b/src/core/lib/surface/completion_queue_factory.c index 879b456ed5d..138dfeff484 100644 --- a/src/core/lib/surface/completion_queue_factory.c +++ b/src/core/lib/surface/completion_queue_factory.c @@ -52,7 +52,9 @@ static const grpc_completion_queue_factory g_default_cq_factory = { const grpc_completion_queue_factory* grpc_completion_queue_factory_lookup( const grpc_completion_queue_attributes* attributes) { /* As we add more fields to grpc_completion_queue_attributes, we may have to - change this assert */ + change this assert to: + GPR_ASSERT (attributes->version >= 1 && + attributes->version <= GRPC_CQ_CURRENT_VERSION) */ GPR_ASSERT(attributes->version == 1); /* The default factory can handle version 1 of the attributes structure. We From 48ed124138d5a6c58710fd6d89d2568733987959 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Tue, 21 Mar 2017 16:43:38 -0700 Subject: [PATCH 3/6] minor enum change --- include/grpc/grpc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index fa4fd6d49d0..68c277cd086 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -96,7 +96,7 @@ GRPCAPI const char *grpc_g_stands_for(void); /** Specifies the type of APIs to use to pop events from the completion queue */ typedef enum { /* Events are popped out by calling grpc_completion_queue_next() API ONLY */ - GRPC_CQ_NEXT = 0, + GRPC_CQ_NEXT = 1, /* Events are popped out by calling grpc_completion_queue_pluck() API ONLY */ GRPC_CQ_PLUCK From f6c202670c89b9dd540a21d9d412f544dee69fe1 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Tue, 21 Mar 2017 18:52:19 -0700 Subject: [PATCH 4/6] Add the new file to bazel BUILD file --- BUILD | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BUILD b/BUILD index 2bcd81a7c88..4dc57f97f33 100644 --- a/BUILD +++ b/BUILD @@ -308,8 +308,8 @@ grpc_cc_library( srcs = [ "src/core/lib/profiling/basic_timers.c", "src/core/lib/profiling/stap_timers.c", - "src/core/lib/support/arena.c", "src/core/lib/support/alloc.c", + "src/core/lib/support/arena.c", "src/core/lib/support/atm.c", "src/core/lib/support/avl.c", "src/core/lib/support/backoff.c", @@ -354,8 +354,8 @@ grpc_cc_library( "src/core/lib/support/wrap_memcpy.c", ], hdrs = [ - "src/core/lib/support/arena.h", "src/core/lib/profiling/timers.h", + "src/core/lib/support/arena.h", "src/core/lib/support/backoff.h", "src/core/lib/support/block_annotate.h", "src/core/lib/support/env.h", @@ -527,6 +527,7 @@ grpc_cc_library( "src/core/lib/surface/channel_ping.c", "src/core/lib/surface/channel_stack_type.c", "src/core/lib/surface/completion_queue.c", + "src/core/lib/surface/completion_queue_factory.c", "src/core/lib/surface/event_string.c", "src/core/lib/surface/lame_client.c", "src/core/lib/surface/metadata_array.c", @@ -636,6 +637,7 @@ grpc_cc_library( "src/core/lib/surface/channel_init.h", "src/core/lib/surface/channel_stack_type.h", "src/core/lib/surface/completion_queue.h", + "src/core/lib/surface/completion_queue_factory.h", "src/core/lib/surface/event_string.h", "src/core/lib/surface/init.h", "src/core/lib/surface/lame_client.h", From 995ed1c3c6abd81f6b9dad71491da986e0e6f01e Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Wed, 22 Mar 2017 02:34:39 -0700 Subject: [PATCH 5/6] Fix bug --- include/grpc/grpc.h | 2 +- src/core/lib/surface/completion_queue_factory.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 68c277cd086..fecb7845703 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -135,7 +135,7 @@ typedef struct grpc_completion_queue_attributes { structure in future. */ int version; /* Set to GRPC_CQ_CURRENT_VERSION */ - grpc_cq_completion_type cq_type; + grpc_cq_completion_type cq_completion_type; grpc_cq_polling_type cq_polling_type; } grpc_completion_queue_attributes; diff --git a/src/core/lib/surface/completion_queue_factory.c b/src/core/lib/surface/completion_queue_factory.c index 138dfeff484..db67a5192be 100644 --- a/src/core/lib/surface/completion_queue_factory.c +++ b/src/core/lib/surface/completion_queue_factory.c @@ -71,7 +71,7 @@ grpc_completion_queue* grpc_completion_queue_create_for_next(void* reserved) { grpc_completion_queue* grpc_completion_queue_create_for_pluck(void* reserved) { GPR_ASSERT(!reserved); - grpc_completion_queue_attributes attr = {1, GRPC_CQ_NEXT, + grpc_completion_queue_attributes attr = {1, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING}; return g_default_cq_factory.vtable->create(&g_default_cq_factory, &attr); } From 3a632c4a71da3c9a3ddfbefefdb160b53db1e0b8 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Wed, 22 Mar 2017 11:49:43 -0700 Subject: [PATCH 6/6] clang format fix --- include/grpc/grpc.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index fecb7845703..e088435d6cc 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -128,7 +128,6 @@ typedef enum { GRPC_CQ_NON_POLLING } grpc_cq_polling_type; - #define GRPC_CQ_CURRENT_VERSION 1 typedef struct grpc_completion_queue_attributes { /* The version number of this structure. More fields might be added to this