Home | History | Annotate | Download | only in iomgr
      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 
     27 typedef enum grpc_pollset_tag {
     28   GRPC_POLLS_NONE,
     29   GRPC_POLLS_POLLSET,
     30   GRPC_POLLS_POLLSET_SET
     31 } grpc_pollset_tag;
     32 
     33 /* A grpc_polling_entity is a pollset-or-pollset_set container. It allows
     34  * functions that accept a pollset XOR a pollset_set to do so through an
     35  * abstract interface. No ownership is taken. */
     36 
     37 typedef struct grpc_polling_entity {
     38   union {
     39     grpc_pollset* pollset;
     40     grpc_pollset_set* pollset_set;
     41   } pollent;
     42   grpc_pollset_tag tag;
     43 } grpc_polling_entity;
     44 
     45 grpc_polling_entity grpc_polling_entity_create_from_pollset_set(
     46     grpc_pollset_set* pollset_set);
     47 grpc_polling_entity grpc_polling_entity_create_from_pollset(
     48     grpc_pollset* pollset);
     49 
     50 /** If \a pollent contains a pollset, return it. Otherwise, return NULL */
     51 grpc_pollset* grpc_polling_entity_pollset(grpc_polling_entity* pollent);
     52 
     53 /** If \a pollent contains a pollset_set, return it. Otherwise, return NULL */
     54 grpc_pollset_set* grpc_polling_entity_pollset_set(grpc_polling_entity* pollent);
     55 
     56 bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent);
     57 
     58 /** Add the pollset or pollset_set in \a pollent to the destination pollset_set
     59  * \a * pss_dst */
     60 void grpc_polling_entity_add_to_pollset_set(grpc_polling_entity* pollent,
     61                                             grpc_pollset_set* pss_dst);
     62 
     63 /** Delete the pollset or pollset_set in \a pollent from the destination
     64  * pollset_set \a * pss_dst */
     65 void grpc_polling_entity_del_from_pollset_set(grpc_polling_entity* pollent,
     66                                               grpc_pollset_set* pss_dst);
     67 
     68 #endif /* GRPC_CORE_LIB_IOMGR_POLLING_ENTITY_H */
     69