Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2017 gRPC authors. |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include "src/core/lib/surface/completion_queue_factory.h" |
| 20 | #include "src/core/lib/surface/completion_queue.h" |
| 21 | |
| 22 | #include <grpc/support/log.h> |
| 23 | |
Sree Kuchibhotla | 2abbf8a | 2017-03-21 17:31:03 -0700 | [diff] [blame] | 24 | /* |
| 25 | * == Default completion queue factory implementation == |
| 26 | */ |
| 27 | |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 28 | static grpc_completion_queue* default_create( |
| 29 | const grpc_completion_queue_factory* factory, |
Sree Kuchibhotla | 2abbf8a | 2017-03-21 17:31:03 -0700 | [diff] [blame] | 30 | const grpc_completion_queue_attributes* attr) { |
Sree Kuchibhotla | b5b6bfd | 2017-03-22 02:32:01 -0700 | [diff] [blame] | 31 | return grpc_completion_queue_create_internal(attr->cq_completion_type, |
Sree Kuchibhotla | 2abbf8a | 2017-03-21 17:31:03 -0700 | [diff] [blame] | 32 | attr->cq_polling_type); |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static grpc_completion_queue_factory_vtable default_vtable = {default_create}; |
| 36 | |
| 37 | static const grpc_completion_queue_factory g_default_cq_factory = { |
Craig Tiller | 4782d92 | 2017-11-10 09:53:21 -0800 | [diff] [blame] | 38 | "Default Factory", nullptr, &default_vtable}; |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 39 | |
Sree Kuchibhotla | 2abbf8a | 2017-03-21 17:31:03 -0700 | [diff] [blame] | 40 | /* |
| 41 | * == Completion queue factory APIs |
| 42 | */ |
| 43 | |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 44 | const grpc_completion_queue_factory* grpc_completion_queue_factory_lookup( |
| 45 | const grpc_completion_queue_attributes* attributes) { |
Sree Kuchibhotla | 2abbf8a | 2017-03-21 17:31:03 -0700 | [diff] [blame] | 46 | GPR_ASSERT(attributes->version >= 1 && |
| 47 | attributes->version <= GRPC_CQ_CURRENT_VERSION); |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 48 | |
| 49 | /* The default factory can handle version 1 of the attributes structure. We |
| 50 | may have to change this as more fields are added to the structure */ |
| 51 | return &g_default_cq_factory; |
| 52 | } |
| 53 | |
Sree Kuchibhotla | 2abbf8a | 2017-03-21 17:31:03 -0700 | [diff] [blame] | 54 | /* |
| 55 | * == Completion queue creation APIs == |
| 56 | */ |
| 57 | |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 58 | grpc_completion_queue* grpc_completion_queue_create_for_next(void* reserved) { |
| 59 | GPR_ASSERT(!reserved); |
| 60 | grpc_completion_queue_attributes attr = {1, GRPC_CQ_NEXT, |
| 61 | GRPC_CQ_DEFAULT_POLLING}; |
| 62 | return g_default_cq_factory.vtable->create(&g_default_cq_factory, &attr); |
| 63 | } |
| 64 | |
| 65 | grpc_completion_queue* grpc_completion_queue_create_for_pluck(void* reserved) { |
| 66 | GPR_ASSERT(!reserved); |
Sree Kuchibhotla | b5b6bfd | 2017-03-22 02:32:01 -0700 | [diff] [blame] | 67 | grpc_completion_queue_attributes attr = {1, GRPC_CQ_PLUCK, |
Sree Kuchibhotla | bf18428 | 2017-03-21 15:18:58 -0700 | [diff] [blame] | 68 | GRPC_CQ_DEFAULT_POLLING}; |
| 69 | return g_default_cq_factory.vtable->create(&g_default_cq_factory, &attr); |
| 70 | } |
Sree Kuchibhotla | 2abbf8a | 2017-03-21 17:31:03 -0700 | [diff] [blame] | 71 | |
| 72 | grpc_completion_queue* grpc_completion_queue_create( |
| 73 | const grpc_completion_queue_factory* factory, |
| 74 | const grpc_completion_queue_attributes* attr, void* reserved) { |
| 75 | GPR_ASSERT(!reserved); |
| 76 | return factory->vtable->create(factory, attr); |
| 77 | } |