| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2015 gRPC authors. |
| 4 |
* |
| 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 |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 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. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H |
| 20 |
#define GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H |
| 21 |
|
| 22 |
#include <grpc/support/port_platform.h> |
| 23 |
|
| 24 |
#include "src/core/lib/iomgr/pollset.h" |
| 25 |
#include "src/core/lib/iomgr/pollset_set.h" |
| 26 |
#include "src/core/lib/promise/context.h" |
| 27 |
|
| 28 |
typedef enum grpc_pollset_tag { |
| 29 |
GRPC_POLLS_NONE, |
| 30 |
GRPC_POLLS_POLLSET, |
| 31 |
GRPC_POLLS_POLLSET_SET |
| 32 |
} grpc_pollset_tag; |
| 33 |
|
| 34 |
/* A grpc_polling_entity is a pollset-or-pollset_set container. It allows |
| 35 |
* functions that accept a pollset XOR a pollset_set to do so through an |
| 36 |
* abstract interface. No ownership is taken. */ |
| 37 |
|
| 38 |
struct grpc_polling_entity { |
| 39 |
union { |
| 40 |
grpc_pollset* pollset = nullptr; |
| 41 |
grpc_pollset_set* pollset_set; |
| 42 |
} pollent; |
| 43 |
grpc_pollset_tag tag = GRPC_POLLS_NONE; |
| 44 |
}; |
| 45 |
|
| 46 |
grpc_polling_entity grpc_polling_entity_create_from_pollset_set( |
| 47 |
grpc_pollset_set* pollset_set); |
| 48 |
grpc_polling_entity grpc_polling_entity_create_from_pollset( |
| 49 |
grpc_pollset* pollset); |
| 50 |
|
| 51 |
/** If \a pollent contains a pollset, return it. Otherwise, return NULL */ |
| 52 |
grpc_pollset* grpc_polling_entity_pollset(grpc_polling_entity* pollent); |
| 53 |
|
| 54 |
/** If \a pollent contains a pollset_set, return it. Otherwise, return NULL */ |
| 55 |
grpc_pollset_set* grpc_polling_entity_pollset_set(grpc_polling_entity* pollent); |
| 56 |
|
| 57 |
bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent); |
| 58 |
|
| 59 |
/** Add the pollset or pollset_set in \a pollent to the destination pollset_set |
| 60 |
* \a * pss_dst */ |
| 61 |
void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent, |
| 62 |
grpc_pollset_set* pss_dst); |
| 63 |
|
| 64 |
/** Delete the pollset or pollset_set in \a pollent from the destination |
| 65 |
* pollset_set \a * pss_dst */ |
| 66 |
void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent, |
| 67 |
grpc_pollset_set* pss_dst); |
| 68 |
|
| 69 |
namespace grpc_core { |
| 70 |
template <> |
| 71 |
struct ContextType<grpc_polling_entity> {}; |
| 72 |
} // namespace grpc_core |
| 73 |
|
| 74 |
#endif /* GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H */ |