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 22namespace ffrt { 23class EventHandlerInteractiveQueue : public BaseQueue { 24public: 25 explicit EventHandlerInteractiveQueue() {} 26 ~EventHandlerInteractiveQueue() override; 27 28 int Push(QueueTask* task) override; 29 30 QueueTask* Pull() override 31 { 32 return nullptr; 33 } 34 35 bool GetActiveStatus() override 36 { 37 return false; 38 } 39 40 int GetQueueType() const override 41 { 42 return ffrt_queue_eventhandler_interactive; 43 } 44 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 52 void Stop() override 53 { 54 std::unique_lock lock(mutex_); 55 isExit_ = true; 56 } 57 58 inline void SetEventHandler(void* eventHandler) 59 { 60 eventHandler_ = eventHandler; 61 } 62 63 inline void* GetEventHandler() 64 { 65 return eventHandler_; 66 } 67 68protected: 69 void* eventHandler_ = nullptr; 70}; 71 72std::unique_ptr<BaseQueue> CreateEventHandlerInteractiveQueue(const ffrt_queue_attr_t* attr); 73} // namespace ffrt 74 75#endif // FFRT_EVENTHANDLER_INTERACTIVE_QUEUE_H 76