1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HICORO_IOPOLLER_H 17 #define HICORO_IOPOLLER_H 18 19 #include <sys/epoll.h> 20 #include <sys/eventfd.h> 21 #include <thread> 22 #include <vector> 23 #include <map> 24 #include <atomic> 25 #include "ffrt_inner.h" 26 #include "internal_inc/non_copyable.h" 27 28 namespace ffrt { 29 struct WakeData { 30 int fd; 31 void* data; 32 }; 33 34 struct IOPoller: private NonCopyable { 35 IOPoller() noexcept; 36 37 virtual ~IOPoller() noexcept; 38 39 void WakeUp() noexcept; 40 bool CasStrong(std::atomic<int> &a, int cmp, int exc); 41 void WaitFdEvent(int fd) noexcept; 42 void PollOnce(int timeout = -1) noexcept; 43 44 private: 45 int m_epFd; 46 struct WakeData m_wakeData; 47 std::vector<epoll_event> m_events; 48 }; 49 50 IOPoller& GetIOPoller() noexcept; 51 } 52 53 void ffrt_wait_fd(int fd); 54 #endif 55