blob: e81531053cf847f8d865552291ee2472f64503e2 [file] [log] [blame]
David Garcia Quintasf72eb972016-05-03 18:28:09 -07001/*
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 Quintas2a50dfe2016-05-31 15:09:12 -070034#ifndef GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H
35#define GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H
David Garcia Quintasf72eb972016-05-03 18:28:09 -070036
37#include "src/core/lib/iomgr/pollset.h"
38#include "src/core/lib/iomgr/pollset_set.h"
39
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070040/* A grpc_polling_entity is a pollset-or-pollset_set container. It allows
41 * functions that
David Garcia Quintasf72eb972016-05-03 18:28:09 -070042 * accept a pollset XOR a pollset_set to do so through an abstract interface.
43 * No ownership is taken. */
44
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070045typedef struct grpc_polling_entity {
David Garcia Quintas60449092016-05-04 20:20:04 -070046 union {
47 grpc_pollset *pollset;
48 grpc_pollset_set *pollset_set;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070049 } pollent;
David Garcia Quintas60449092016-05-04 20:20:04 -070050 enum pops_tag { POPS_NONE, POPS_POLLSET, POPS_POLLSET_SET } tag;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070051} grpc_polling_entity;
David Garcia Quintasf72eb972016-05-03 18:28:09 -070052
David Garcia Quintasc4d51122016-06-06 14:56:02 -070053grpc_polling_entity grpc_polling_entity_create_from_pollset_set(
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070054 grpc_pollset_set *pollset_set);
David Garcia Quintas69ff63d2016-06-06 16:39:47 -070055grpc_polling_entity grpc_polling_entity_create_from_pollset(
56 grpc_pollset *pollset);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070057
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070058/** If \a pollent contains a pollset, return it. Otherwise, return NULL */
David Garcia Quintasc4d51122016-06-06 14:56:02 -070059grpc_pollset *grpc_polling_entity_pollset(grpc_polling_entity *pollent);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070060
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070061/** If \a pollent contains a pollset_set, return it. Otherwise, return NULL */
David Garcia Quintasc4d51122016-06-06 14:56:02 -070062grpc_pollset_set *grpc_polling_entity_pollset_set(grpc_polling_entity *pollent);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070063
David Garcia Quintasc4d51122016-06-06 14:56:02 -070064bool grpc_polling_entity_is_empty(const grpc_polling_entity *pollent);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070065
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070066/** Add the pollset or pollset_set in \a pollent to the destination pollset_set
67 * \a
David Garcia Quintasf72eb972016-05-03 18:28:09 -070068 * pss_dst */
David Garcia Quintasc4d51122016-06-06 14:56:02 -070069void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx *exec_ctx,
David Garcia Quintas69ff63d2016-06-06 16:39:47 -070070 grpc_polling_entity *pollent,
71 grpc_pollset_set *pss_dst);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070072
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070073/** Delete the pollset or pollset_set in \a pollent from the destination
David Garcia Quintasf72eb972016-05-03 18:28:09 -070074 * pollset_set \a
75 * pss_dst */
David Garcia Quintasc4d51122016-06-06 14:56:02 -070076void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx *exec_ctx,
David Garcia Quintas69ff63d2016-06-06 16:39:47 -070077 grpc_polling_entity *pollent,
78 grpc_pollset_set *pss_dst);
David Garcia Quintasf72eb972016-05-03 18:28:09 -070079/* pollset_set specific */
80
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070081#endif /* GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H */