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 #ifndef FFRT_EVENTHANDLER_INTERACTIVE_QUEUE_H 16 #define FFRT_EVENTHANDLER_INTERACTIVE_QUEUE_H 17 18 #include "base_queue.h" 19 #include "tm/queue_task.h" 20 #include "util/event_handler_adapter.h" 21 22 namespace ffrt { 23 class EventHandlerInteractiveQueue : public BaseQueue { 24 public: EventHandlerInteractiveQueue()25 explicit EventHandlerInteractiveQueue() {} 26 ~EventHandlerInteractiveQueue() override; 27 28 int Push(QueueTask* task) override; 29 Pull()30 QueueTask* Pull() override 31 { 32 return nullptr; 33 } 34 GetActiveStatus()35 bool GetActiveStatus() override 36 { 37 return false; 38 } 39 GetQueueType()40 int GetQueueType() const override 41 { 42 return ffrt_queue_eventhandler_interactive; 43 } 44 Remove(const QueueTask * task)45 int Remove(const QueueTask* task) override 46 { 47 uintptr_t taskId = static_cast<uintptr_t>(task->gid); 48 int ret = EventHandlerAdapter::Instance()->RemoveTask(eventHandler_, taskId); 49 return ret; 50 } 51 Stop()52 void Stop() override 53 { 54 std::unique_lock lock(mutex_); 55 isExit_ = true; 56 } 57 SetEventHandler(void * eventHandler)58 inline void SetEventHandler(void* eventHandler) 59 { 60 eventHandler_ = eventHandler; 61 } 62 GetEventHandler()63 inline void* GetEventHandler() 64 { 65 return eventHandler_; 66 } 67 68 protected: 69 void* eventHandler_ = nullptr; 70 }; 71 72 std::unique_ptr<BaseQueue> CreateEventHandlerInteractiveQueue(const ffrt_queue_attr_t* attr); 73 } // namespace ffrt 74 75 #endif // FFRT_EVENTHANDLER_INTERACTIVE_QUEUE_H 76