blob: 0ee4ea1255b1c49067850bdb7d1d21b30a4d9835 [file] [log] [blame]
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2016 gRPC authors.
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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 Quintas2a50dfe2016-05-31 15:09:12 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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 Quintas2a50dfe2016-05-31 15:09:12 -070016 *
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 Quintasc4d51122016-06-06 14:56:02 -070024grpc_polling_entity grpc_polling_entity_create_from_pollset_set(
Craig Tillerbaa14a92017-11-03 09:09:36 -070025 grpc_pollset_set* pollset_set) {
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070026 grpc_polling_entity pollent;
27 pollent.pollent.pollset_set = pollset_set;
Yash Tibrewal97dab512017-09-12 14:27:46 -070028 pollent.tag = GRPC_POLLS_POLLSET_SET;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070029 return pollent;
30}
31
David Garcia Quintas69ff63d2016-06-06 16:39:47 -070032grpc_polling_entity grpc_polling_entity_create_from_pollset(
Craig Tillerbaa14a92017-11-03 09:09:36 -070033 grpc_pollset* pollset) {
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070034 grpc_polling_entity pollent;
35 pollent.pollent.pollset = pollset;
Yash Tibrewal97dab512017-09-12 14:27:46 -070036 pollent.tag = GRPC_POLLS_POLLSET;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070037 return pollent;
38}
39
Craig Tillerbaa14a92017-11-03 09:09:36 -070040grpc_pollset* grpc_polling_entity_pollset(grpc_polling_entity* pollent) {
Yash Tibrewal97dab512017-09-12 14:27:46 -070041 if (pollent->tag == GRPC_POLLS_POLLSET) {
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070042 return pollent->pollent.pollset;
43 }
Craig Tiller4782d922017-11-10 09:53:21 -080044 return nullptr;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070045}
46
Craig Tillerbaa14a92017-11-03 09:09:36 -070047grpc_pollset_set* grpc_polling_entity_pollset_set(
48 grpc_polling_entity* pollent) {
Yash Tibrewal97dab512017-09-12 14:27:46 -070049 if (pollent->tag == GRPC_POLLS_POLLSET_SET) {
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070050 return pollent->pollent.pollset_set;
51 }
Craig Tiller4782d922017-11-10 09:53:21 -080052 return nullptr;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070053}
54
Craig Tillerbaa14a92017-11-03 09:09:36 -070055bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent) {
Yash Tibrewal97dab512017-09-12 14:27:46 -070056 return pollent->tag == GRPC_POLLS_NONE;
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070057}
58
Craig Tillerbaa14a92017-11-03 09:09:36 -070059void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx* exec_ctx,
60 grpc_polling_entity* pollent,
61 grpc_pollset_set* pss_dst) {
Yash Tibrewal97dab512017-09-12 14:27:46 -070062 if (pollent->tag == GRPC_POLLS_POLLSET) {
Craig Tiller4782d922017-11-10 09:53:21 -080063 GPR_ASSERT(pollent->pollent.pollset != nullptr);
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070064 grpc_pollset_set_add_pollset(exec_ctx, pss_dst, pollent->pollent.pollset);
Yash Tibrewal97dab512017-09-12 14:27:46 -070065 } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) {
Craig Tiller4782d922017-11-10 09:53:21 -080066 GPR_ASSERT(pollent->pollent.pollset_set != nullptr);
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070067 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
Craig Tillerbaa14a92017-11-03 09:09:36 -070075void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx* exec_ctx,
76 grpc_polling_entity* pollent,
77 grpc_pollset_set* pss_dst) {
Yash Tibrewal97dab512017-09-12 14:27:46 -070078 if (pollent->tag == GRPC_POLLS_POLLSET) {
Craig Tiller4782d922017-11-10 09:53:21 -080079 GPR_ASSERT(pollent->pollent.pollset != nullptr);
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070080 grpc_pollset_set_del_pollset(exec_ctx, pss_dst, pollent->pollent.pollset);
Yash Tibrewal97dab512017-09-12 14:27:46 -070081 } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) {
Craig Tiller4782d922017-11-10 09:53:21 -080082 GPR_ASSERT(pollent->pollent.pollset_set != nullptr);
David Garcia Quintas2a50dfe2016-05-31 15:09:12 -070083 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}