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 #ifndef MOCK_FFRT_API_CPP_QUEUE_H 16 #define MOCK_FFRT_API_CPP_QUEUE_H 17 18 #include "c/queue.h" 19 #include "task.h" 20 21 namespace ffrt { 22 23 enum queue_type { 24 queue_serial = ffrt_queue_serial, 25 queue_concurrent = ffrt_queue_concurrent, 26 queue_max = ffrt_queue_max, 27 }; 28 29 class queue_attr : public ffrt_queue_attr_t { 30 public: queue_attr()31 queue_attr() 32 {} 33 ~queue_attr()34 ~queue_attr() 35 {} 36 37 queue_attr(const queue_attr &) = delete; 38 39 queue_attr &operator=(const queue_attr &) = delete; 40 qos(qos qos_)41 inline queue_attr &qos(qos qos_) 42 { 43 return *this; 44 } 45 qos()46 inline int qos() const 47 { 48 return 0; 49 } 50 timeout(uint64_t timeout_us)51 inline queue_attr &timeout(uint64_t timeout_us) 52 { 53 return *this; 54 } 55 timeout()56 inline uint64_t timeout() const 57 { 58 return 0; 59 } 60 callback(const std::function<void ()> & func)61 inline queue_attr &callback(const std::function<void()> &func) 62 { 63 return *this; 64 } 65 callback()66 inline ffrt_function_header_t *callback() const 67 { 68 return nullptr; 69 } 70 max_concurrency(const int max_concurrency)71 inline queue_attr &max_concurrency(const int max_concurrency) 72 { 73 return *this; 74 } 75 max_concurrency()76 inline int max_concurrency() const 77 { 78 return 0; 79 } 80 thread_mode(bool mode)81 inline queue_attr &thread_mode(bool mode) 82 { 83 return *this; 84 } 85 thread_mode()86 inline bool thread_mode() const 87 { 88 return true; 89 } 90 }; 91 92 class queue { 93 public: 94 queue(const queue_type type, const char *name, const queue_attr &attr = {}) 95 {} 96 97 queue(const char *name, const queue_attr &attr = {}) 98 {} 99 ~queue()100 ~queue() 101 {} 102 103 queue(const queue &) = delete; 104 105 void operator=(const queue &) = delete; 106 107 inline void submit(const std::function<void()> &func, const task_attr &attr = {}) 108 {} 109 110 inline void submit(std::function<void()> &&func, const task_attr &attr = {}) 111 {} 112 113 inline task_handle submit_h(const std::function<void()> &func, const task_attr &attr = {}) 114 { 115 return {}; 116 } 117 118 inline task_handle submit_h(std::function<void()> &&func, const task_attr &attr = {}) 119 { 120 return {}; 121 } 122 123 inline void submit_head(const std::function<void()> &func, const task_attr &attr = {}) 124 {} 125 126 inline void submit_head(std::function<void()> &&func, const task_attr &attr = {}) 127 {} 128 129 inline task_handle submit_head_h(const std::function<void()> &func, const task_attr &attr = {}) 130 { 131 return {}; 132 } 133 134 inline task_handle submit_head_h(std::function<void()> &&func, const task_attr &attr = {}) 135 { 136 return {}; 137 } 138 cancel(const task_handle & handle)139 inline int cancel(const task_handle &handle) 140 { 141 return 0; 142 } 143 wait(const task_handle & handle)144 inline void wait(const task_handle &handle) 145 {} 146 get_task_cnt()147 inline uint64_t get_task_cnt() 148 { 149 return 0; 150 } 151 get_main_queue()152 static inline queue *get_main_queue() 153 { 154 return nullptr; 155 } 156 157 private: 158 using QueueDeleter = void (*)(ffrt_queue_t); 159 160 queue(ffrt_queue_t queue_handle, QueueDeleter deleter = nullptr) 161 {} 162 163 [[maybe_unused]] ffrt_queue_t queue_handle = nullptr; ///< Handle to the underlying queue. 164 [[maybe_unused]] QueueDeleter deleter = nullptr; ///< Function pointer used to delete or destroy the queue. 165 }; 166 } // namespace ffrt 167 168 #endif