blob: effe1a33ee7d306b3423d4572d96ebbc6a09766a [file] [log] [blame]
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -07001/*
2 *
3 * Copyright 2016, 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
34#include <grpc/support/alloc.h>
35#include <grpc/support/log.h>
36
37#include "src/core/lib/iomgr/polling_entity.h"
38
39grpc_polling_entity grpc_pops_create_from_pollset_set(
40 grpc_pollset_set *pollset_set) {
41 grpc_polling_entity pollent;
42 pollent.pollent.pollset_set = pollset_set;
43 pollent.tag = POPS_POLLSET_SET;
44 return pollent;
45}
46
47grpc_polling_entity grpc_pops_create_from_pollset(grpc_pollset *pollset) {
48 grpc_polling_entity pollent;
49 pollent.pollent.pollset = pollset;
50 pollent.tag = POPS_POLLSET;
51 return pollent;
52}
53
54grpc_pollset *grpc_pops_pollset(grpc_polling_entity *pollent) {
55 if (pollent->tag == POPS_POLLSET) {
56 return pollent->pollent.pollset;
57 }
58 return NULL;
59}
60
61grpc_pollset_set *grpc_pops_pollset_set(grpc_polling_entity *pollent) {
62 if (pollent->tag == POPS_POLLSET_SET) {
63 return pollent->pollent.pollset_set;
64 }
65 return NULL;
66}
67
68bool grpc_pops_is_empty(const grpc_polling_entity *pollent) {
69 return pollent->tag == POPS_NONE;
70}
71
72void grpc_pops_add_to_pollset_set(grpc_exec_ctx *exec_ctx,
73 grpc_polling_entity *pollent,
74 grpc_pollset_set *pss_dst) {
75 if (pollent->tag == POPS_POLLSET) {
76 GPR_ASSERT(pollent->pollent.pollset != NULL);
77 grpc_pollset_set_add_pollset(exec_ctx, pss_dst, pollent->pollent.pollset);
78 } else if (pollent->tag == POPS_POLLSET_SET) {
79 GPR_ASSERT(pollent->pollent.pollset_set != NULL);
80 grpc_pollset_set_add_pollset_set(exec_ctx, pss_dst,
81 pollent->pollent.pollset_set);
82 } else {
83 gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag);
84 abort();
85 }
86}
87
88void grpc_pops_del_to_pollset_set(grpc_exec_ctx *exec_ctx,
89 grpc_polling_entity *pollent,
90 grpc_pollset_set *pss_dst) {
91 if (pollent->tag == POPS_POLLSET) {
92 GPR_ASSERT(pollent->pollent.pollset != NULL);
93 grpc_pollset_set_del_pollset(exec_ctx, pss_dst, pollent->pollent.pollset);
94 } else if (pollent->tag == POPS_POLLSET_SET) {
95 GPR_ASSERT(pollent->pollent.pollset_set != NULL);
96 grpc_pollset_set_del_pollset_set(exec_ctx, pss_dst,
97 pollent->pollent.pollset_set);
98 } else {
99 gpr_log(GPR_ERROR, "Invalid grpc_polling_entity tag '%d'", pollent->tag);
100 abort();
101 }
102}