1 /* 2 * Copyright (c) 2021-2024 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 HIVIEW_BASE_EVENT_DISPATCH_QUEUE_IMPL_H 16 #define HIVIEW_BASE_EVENT_DISPATCH_QUEUE_IMPL_H 17 #include <memory> 18 #include <string> 19 20 #include "event.h" 21 #include "ffrt.h" 22 #include "plugin.h" 23 24 namespace OHOS { 25 namespace HiviewDFX { 26 class EventDispatchQueue : public std::enable_shared_from_this<EventDispatchQueue> { 27 public: 28 EventDispatchQueue(const std::string& name, Event::ManageType type, HiviewContext* context_); 29 ~EventDispatchQueue(); 30 31 void Stop(); 32 void Start(); 33 void Enqueue(std::shared_ptr<Event> event); IsRunning()34 bool IsRunning() const 35 { 36 std::unique_lock<ffrt::mutex> lock(mutexLock_); 37 return isRunning_; 38 } 39 40 private: 41 void ProcessUnorderedEvent(const Event &event); 42 43 bool isRunning_ = false; 44 std::string threadName_; 45 Event::ManageType type_; 46 HiviewContext* context_; 47 mutable ffrt::mutex mutexLock_; 48 std::unique_ptr<ffrt::queue> ffrtQueue_; 49 }; 50 } // namespace HiviewDFX 51 } // namespace OHOS 52 #endif // HIVIEW_BASE_EVENT_DISPATCH_QUEUE_IMPL_H