David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2016 gRPC authors. |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -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 |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -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 |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -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. |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <grpc/support/alloc.h> |
| 20 | #include <grpc/support/log.h> |
| 21 | |
| 22 | #include "src/core/lib/iomgr/polling_entity.h" |
| 23 | |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 24 | grpc_polling_entity grpc_polling_entity_create_from_pollset_set( |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 25 | grpc_pollset_set *pollset_set) { |
| 26 | grpc_polling_entity pollent; |
| 27 | pollent.pollent.pollset_set = pollset_set; |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame^] | 28 | pollent.tag = GRPC_POLLS_POLLSET_SET; |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 29 | return pollent; |
| 30 | } |
| 31 | |
David Garcia Quintas | 69ff63d | 2016-06-06 16:39:47 -0700 | [diff] [blame] | 32 | grpc_polling_entity grpc_polling_entity_create_from_pollset( |
| 33 | grpc_pollset *pollset) { |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 34 | grpc_polling_entity pollent; |
| 35 | pollent.pollent.pollset = pollset; |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame^] | 36 | pollent.tag = GRPC_POLLS_POLLSET; |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 37 | return pollent; |
| 38 | } |
| 39 | |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 40 | grpc_pollset *grpc_polling_entity_pollset(grpc_polling_entity *pollent) { |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame^] | 41 | if (pollent->tag == GRPC_POLLS_POLLSET) { |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 42 | return pollent->pollent.pollset; |
| 43 | } |
| 44 | return NULL; |
| 45 | } |
| 46 | |
David Garcia Quintas | 69ff63d | 2016-06-06 16:39:47 -0700 | [diff] [blame] | 47 | grpc_pollset_set *grpc_polling_entity_pollset_set( |
| 48 | grpc_polling_entity *pollent) { |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame^] | 49 | if (pollent->tag == GRPC_POLLS_POLLSET_SET) { |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 50 | return pollent->pollent.pollset_set; |
| 51 | } |
| 52 | return NULL; |
| 53 | } |
| 54 | |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 55 | bool grpc_polling_entity_is_empty(const grpc_polling_entity *pollent) { |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame^] | 56 | return pollent->tag == GRPC_POLLS_NONE; |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 57 | } |
| 58 | |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 59 | void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx *exec_ctx, |
David Garcia Quintas | 69ff63d | 2016-06-06 16:39:47 -0700 | [diff] [blame] | 60 | grpc_polling_entity *pollent, |
| 61 | grpc_pollset_set *pss_dst) { |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame^] | 62 | if (pollent->tag == GRPC_POLLS_POLLSET) { |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 63 | GPR_ASSERT(pollent->pollent.pollset != NULL); |
| 64 | grpc_pollset_set_add_pollset(exec_ctx, pss_dst, pollent->pollent.pollset); |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame^] | 65 | } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 66 | GPR_ASSERT(pollent->pollent.pollset_set != NULL); |
| 67 | grpc_pollset_set_add_pollset_set(exec_ctx, pss_dst, |
| 68 | pollent->pollent.pollset_set); |
| 69 | } else { |
| 70 | gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag); |
| 71 | abort(); |
| 72 | } |
| 73 | } |
| 74 | |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 75 | void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx *exec_ctx, |
David Garcia Quintas | 69ff63d | 2016-06-06 16:39:47 -0700 | [diff] [blame] | 76 | grpc_polling_entity *pollent, |
| 77 | grpc_pollset_set *pss_dst) { |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame^] | 78 | if (pollent->tag == GRPC_POLLS_POLLSET) { |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 79 | GPR_ASSERT(pollent->pollent.pollset != NULL); |
| 80 | grpc_pollset_set_del_pollset(exec_ctx, pss_dst, pollent->pollent.pollset); |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame^] | 81 | } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 82 | GPR_ASSERT(pollent->pollent.pollset_set != NULL); |
| 83 | grpc_pollset_set_del_pollset_set(exec_ctx, pss_dst, |
| 84 | pollent->pollent.pollset_set); |
| 85 | } else { |
| 86 | gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag); |
| 87 | abort(); |
| 88 | } |
| 89 | } |