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 FFRT_LOOP_HPP 17 #define FFRT_LOOP_HPP 18 #include "queue/queue_handler.h" 19 #include "sync/poller.h" 20 21 namespace ffrt { 22 class Loop { 23 public: 24 explicit Loop(QueueHandler* handler); 25 ~Loop(); 26 27 void Run(); 28 void Stop(); 29 30 int EpollCtl(int op, int fd, uint32_t events, void *data, ffrt_poller_cb cb); 31 ffrt_timer_t TimerStart(uint64_t timeout, void* data, ffrt_timer_cb cb, bool repeat); 32 int TimerStop(ffrt_timer_t handle); 33 void WakeUp(); 34 int GetQueueType(); 35 36 private: 37 QueueHandler* handler_ = nullptr; 38 Poller poller_; 39 std::atomic<bool> stopFlag_ { false }; 40 }; 41 } 42 #endif 43