David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -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 | f72eb97 | 2016-05-03 18:28:09 -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 | f72eb97 | 2016-05-03 18:28:09 -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 | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 19 | #ifndef GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H |
| 20 | #define GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 21 | |
| 22 | #include "src/core/lib/iomgr/pollset.h" |
| 23 | #include "src/core/lib/iomgr/pollset_set.h" |
| 24 | |
Yash Tibrewal | a7e6d65 | 2017-09-20 18:56:37 -0700 | [diff] [blame] | 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame] | 29 | typedef enum grpc_pollset_tag { |
| 30 | GRPC_POLLS_NONE, |
| 31 | GRPC_POLLS_POLLSET, |
| 32 | GRPC_POLLS_POLLSET_SET |
| 33 | } grpc_pollset_tag; |
Yash Tibrewal | 52778c4 | 2017-09-11 15:00:11 -0700 | [diff] [blame] | 34 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 35 | /* A grpc_polling_entity is a pollset-or-pollset_set container. It allows |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 36 | * functions that accept a pollset XOR a pollset_set to do so through an |
| 37 | * abstract interface. No ownership is taken. */ |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 38 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 39 | typedef struct grpc_polling_entity { |
David Garcia Quintas | 6044909 | 2016-05-04 20:20:04 -0700 | [diff] [blame] | 40 | union { |
| 41 | grpc_pollset *pollset; |
| 42 | grpc_pollset_set *pollset_set; |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 43 | } pollent; |
Yash Tibrewal | 97dab51 | 2017-09-12 14:27:46 -0700 | [diff] [blame] | 44 | grpc_pollset_tag tag; |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 45 | } grpc_polling_entity; |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 46 | |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 47 | grpc_polling_entity grpc_polling_entity_create_from_pollset_set( |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 48 | grpc_pollset_set *pollset_set); |
David Garcia Quintas | 69ff63d | 2016-06-06 16:39:47 -0700 | [diff] [blame] | 49 | grpc_polling_entity grpc_polling_entity_create_from_pollset( |
| 50 | grpc_pollset *pollset); |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 51 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 52 | /** If \a pollent contains a pollset, return it. Otherwise, return NULL */ |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 53 | grpc_pollset *grpc_polling_entity_pollset(grpc_polling_entity *pollent); |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 54 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 55 | /** If \a pollent contains a pollset_set, return it. Otherwise, return NULL */ |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 56 | grpc_pollset_set *grpc_polling_entity_pollset_set(grpc_polling_entity *pollent); |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 57 | |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 58 | bool grpc_polling_entity_is_empty(const grpc_polling_entity *pollent); |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 59 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 60 | /** Add the pollset or pollset_set in \a pollent to the destination pollset_set |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 61 | * \a * pss_dst */ |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 62 | 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] | 63 | grpc_polling_entity *pollent, |
| 64 | grpc_pollset_set *pss_dst); |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 65 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 66 | /** Delete the pollset or pollset_set in \a pollent from the destination |
David Garcia Quintas | 87d5a31 | 2017-06-06 19:45:58 -0700 | [diff] [blame] | 67 | * pollset_set \a * pss_dst */ |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 68 | 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] | 69 | grpc_polling_entity *pollent, |
| 70 | grpc_pollset_set *pss_dst); |
Yash Tibrewal | a7e6d65 | 2017-09-20 18:56:37 -0700 | [diff] [blame] | 71 | #ifdef __cplusplus |
| 72 | } |
| 73 | #endif |
| 74 | |
Yash Tibrewal | 12fc6d4 | 2017-10-09 16:43:34 -0700 | [diff] [blame] | 75 | #endif /* GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H */ |