1 /* 2 * Copyright (c) 2021 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 <condition_variable> 18 #include <list> 19 #include <memory> 20 #include <mutex> 21 #include <string> 22 #include <thread> 23 #include <unordered_map> 24 25 #include "event.h" 26 #include "plugin.h" 27 28 namespace OHOS { 29 namespace HiviewDFX { 30 class EventDispatchQueue { 31 public: 32 EventDispatchQueue(const std::string& name, Event::ManageType type, HiviewContext* context_); 33 ~EventDispatchQueue(); 34 35 void Stop(); 36 void Start(); 37 void Enqueue(std::shared_ptr<Event> event); 38 int GetWaitQueueSize() const; IsRunning()39 bool IsRunning() const 40 { 41 return isRunning_; 42 } 43 44 private: 45 void Run(); 46 void ProcessUnorderedEvent(const Event &event); 47 48 volatile bool stop_; 49 bool isRunning_ = false; 50 std::string threadName_; 51 Event::ManageType type_; 52 HiviewContext* context_; 53 mutable std::mutex mutexLock_; 54 std::condition_variable condition_; 55 std::list<std::shared_ptr<Event>> pendingEvents_; 56 std::unique_ptr<std::thread> thread_; 57 }; 58 } // namespace HiviewDFX 59 } // namespace OHOS 60 #endif // HIVIEW_BASE_EVENT_DISPATCH_QUEUE_IMPL_H