David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015, Google Inc. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H |
| 35 | #define GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 36 | |
| 37 | #include "src/core/lib/iomgr/pollset.h" |
| 38 | #include "src/core/lib/iomgr/pollset_set.h" |
| 39 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 40 | /* A grpc_polling_entity is a pollset-or-pollset_set container. It allows |
| 41 | * functions that |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 42 | * accept a pollset XOR a pollset_set to do so through an abstract interface. |
| 43 | * No ownership is taken. */ |
| 44 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 45 | typedef struct grpc_polling_entity { |
David Garcia Quintas | 6044909 | 2016-05-04 20:20:04 -0700 | [diff] [blame] | 46 | union { |
| 47 | grpc_pollset *pollset; |
| 48 | grpc_pollset_set *pollset_set; |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 49 | } pollent; |
David Garcia Quintas | 6044909 | 2016-05-04 20:20:04 -0700 | [diff] [blame] | 50 | enum pops_tag { POPS_NONE, POPS_POLLSET, POPS_POLLSET_SET } tag; |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 51 | } grpc_polling_entity; |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 52 | |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 53 | grpc_polling_entity grpc_polling_entity_create_from_pollset_set( |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 54 | grpc_pollset_set *pollset_set); |
David Garcia Quintas | 69ff63d | 2016-06-06 16:39:47 -0700 | [diff] [blame] | 55 | grpc_polling_entity grpc_polling_entity_create_from_pollset( |
| 56 | grpc_pollset *pollset); |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 57 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 58 | /** If \a pollent contains a pollset, return it. Otherwise, return NULL */ |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 59 | grpc_pollset *grpc_polling_entity_pollset(grpc_polling_entity *pollent); |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 60 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 61 | /** 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] | 62 | 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] | 63 | |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 64 | bool grpc_polling_entity_is_empty(const grpc_polling_entity *pollent); |
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 | /** Add the pollset or pollset_set in \a pollent to the destination pollset_set |
| 67 | * \a |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 68 | * pss_dst */ |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 69 | 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] | 70 | grpc_polling_entity *pollent, |
| 71 | grpc_pollset_set *pss_dst); |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 72 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 73 | /** Delete the pollset or pollset_set in \a pollent from the destination |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 74 | * pollset_set \a |
| 75 | * pss_dst */ |
David Garcia Quintas | c4d5112 | 2016-06-06 14:56:02 -0700 | [diff] [blame] | 76 | 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] | 77 | grpc_polling_entity *pollent, |
| 78 | grpc_pollset_set *pss_dst); |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 79 | /* pollset_set specific */ |
| 80 | |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 81 | #endif /* GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H */ |