1060ff233Sopenharmony_ci/* 2060ff233Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License. 5060ff233Sopenharmony_ci * You may obtain a copy of the License at 6060ff233Sopenharmony_ci * 7060ff233Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8060ff233Sopenharmony_ci * 9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and 13060ff233Sopenharmony_ci * limitations under the License. 14060ff233Sopenharmony_ci */ 15060ff233Sopenharmony_ci 16060ff233Sopenharmony_ci#ifndef FILLP_EPOLL_H 17060ff233Sopenharmony_ci#define FILLP_EPOLL_H 18060ff233Sopenharmony_ci#include "rb_tree.h" 19060ff233Sopenharmony_ci#include "hlist.h" 20060ff233Sopenharmony_ci 21060ff233Sopenharmony_ci#ifdef __cplusplus 22060ff233Sopenharmony_ciextern "C" { 23060ff233Sopenharmony_ci#endif 24060ff233Sopenharmony_ci 25060ff233Sopenharmony_ci/* 26060ff233Sopenharmony_ci * This structure is stored inside the "private_data" member of the file 27060ff233Sopenharmony_ci * structure and represent the main data structure for the eventpoll 28060ff233Sopenharmony_ci * interface. 29060ff233Sopenharmony_ci */ 30060ff233Sopenharmony_cistruct EventPoll { 31060ff233Sopenharmony_ci struct Hlist rdList; /* epitem(ready fd) list */ 32060ff233Sopenharmony_ci /* RB-Tree root used to store checked fd structs */ 33060ff233Sopenharmony_ci struct RbRoot rbr; /* epitem storage. epitem will be storaged here if added by epoll_ctl */ 34060ff233Sopenharmony_ci 35060ff233Sopenharmony_ci SYS_ARCH_SEM appSem; /* protect data from multiple app thread */ 36060ff233Sopenharmony_ci SYS_ARCH_SEM waitSem; /* Notify the ep_wait */ 37060ff233Sopenharmony_ci SYS_ARCH_SEM appCoreSem; /* protect data from app thread and core thread */ 38060ff233Sopenharmony_ci 39060ff233Sopenharmony_ci /** don't signal the same semaphore twice: set to 1 when signalled */ 40060ff233Sopenharmony_ci SysArchAtomic semSignalled; 41060ff233Sopenharmony_ci 42060ff233Sopenharmony_ci#ifdef FILLP_64BIT_ALIGN 43060ff233Sopenharmony_ci FILLP_UINT8 padd[4]; 44060ff233Sopenharmony_ci#endif 45060ff233Sopenharmony_ci}; 46060ff233Sopenharmony_ci 47060ff233Sopenharmony_ci/* 48060ff233Sopenharmony_ci * Each file descriptor added to the eventpoll interface will 49060ff233Sopenharmony_ci * have an entry of this type linked to the hash. 50060ff233Sopenharmony_ci */ 51060ff233Sopenharmony_cistruct EpItem { 52060ff233Sopenharmony_ci /* RB-Tree node used to link this structure to the eventpoll rb-tree */ 53060ff233Sopenharmony_ci struct RbNode rbn; /* Will be added to eventpoll->rbr */ 54060ff233Sopenharmony_ci 55060ff233Sopenharmony_ci /* List header used to link this structure to the eventpoll ready list */ 56060ff233Sopenharmony_ci struct HlistNode rdlNode; /* Will be added to eventpoll->rdllist */ 57060ff233Sopenharmony_ci 58060ff233Sopenharmony_ci struct HlistNode sockWaitNode; /* Will be added to ftSock->epoll_taskList */ 59060ff233Sopenharmony_ci 60060ff233Sopenharmony_ci /* The "container" of this item -- this is core pointer always */ 61060ff233Sopenharmony_ci struct EventPoll *ep; 62060ff233Sopenharmony_ci 63060ff233Sopenharmony_ci /* The structure that describe the interested events and the source fd */ 64060ff233Sopenharmony_ci struct SpungeEpollEvent event; 65060ff233Sopenharmony_ci FILLP_UINT32 revents; 66060ff233Sopenharmony_ci 67060ff233Sopenharmony_ci FILLP_INT fileDespcriptor; /* The file descriptor information this item refers to */ 68060ff233Sopenharmony_ci 69060ff233Sopenharmony_ci void *next; 70060ff233Sopenharmony_ci}; 71060ff233Sopenharmony_ci 72060ff233Sopenharmony_cistatic __inline struct EpItem *EpItemEntryRbNode(struct RbNode *node) 73060ff233Sopenharmony_ci{ 74060ff233Sopenharmony_ci return (struct EpItem *)((char *)(node) - (uintptr_t)(&(((struct EpItem *)0)->rbn))); 75060ff233Sopenharmony_ci} 76060ff233Sopenharmony_ci 77060ff233Sopenharmony_cistatic __inline struct EpItem *EpItemEntryRdlNode(struct HlistNode *node) 78060ff233Sopenharmony_ci{ 79060ff233Sopenharmony_ci return (struct EpItem *)((char *)(node) - (uintptr_t)(&(((struct EpItem *)0)->rdlNode))); 80060ff233Sopenharmony_ci} 81060ff233Sopenharmony_ci 82060ff233Sopenharmony_cistatic __inline struct EpItem *EpitemEntrySockWaitNode(struct HlistNode *node) 83060ff233Sopenharmony_ci{ 84060ff233Sopenharmony_ci return (struct EpItem *)((char *)(node) - (uintptr_t)(&(((struct EpItem *)0)->sockWaitNode))); 85060ff233Sopenharmony_ci} 86060ff233Sopenharmony_ci 87060ff233Sopenharmony_civoid EpSocketReady(struct EventPoll *scb, struct EpItem *epiItem); 88060ff233Sopenharmony_civoid EpDelRdlnode(struct EventPoll *ep, struct EpItem *epi); 89060ff233Sopenharmony_civoid EpollUpdateEpEvent(struct EpItem *epi); 90060ff233Sopenharmony_ci 91060ff233Sopenharmony_ci 92060ff233Sopenharmony_ci#ifdef __cplusplus 93060ff233Sopenharmony_ci} 94060ff233Sopenharmony_ci#endif 95060ff233Sopenharmony_ci 96060ff233Sopenharmony_ci#endif /* FILLP_EPOLL_H */ 97