1 /* 2 * Copyright (c) 2025-2025 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 HKS_HA_EVENT_QUEUE_H 17 #define HKS_HA_EVENT_QUEUE_H 18 19 #ifdef __cplusplus 20 21 #include <queue> 22 #include <mutex> 23 #include <condition_variable> 24 #include <memory> 25 #include <cstdint> 26 27 constexpr uint32_t MAX_CAPACITY = 2048; 28 29 typedef struct { 30 uint32_t eventId; 31 struct HksParamSet *paramSet; 32 } HksEventQueueItem; 33 34 class HksEventQueue { 35 public: 36 explicit HksEventQueue(uint32_t capacity = MAX_CAPACITY) 37 : queueCapacity_(capacity > MAX_CAPACITY ? MAX_CAPACITY : capacity), stopped_(false) {} 38 39 bool Enqueue(uint32_t eventId, struct HksParamSet *paramSet); 40 41 bool Dequeue(HksEventQueueItem& item); 42 43 uint32_t Size() const; 44 45 bool IsEmpty() const; 46 47 void Stop(); 48 49 private: 50 std::queue<HksEventQueueItem> queueItem_; 51 uint32_t queueCapacity_; 52 mutable std::mutex queueMutex_; 53 std::condition_variable notEmpty; 54 bool stopped_; 55 }; 56 #endif 57 58 #endif