1 /* 2 * Copyright (C) 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 FOUNDATION_ACE_INTERFACE_BASE_TASK_POOL_H 16 #define FOUNDATION_ACE_INTERFACE_BASE_TASK_POOL_H 17 18 #include <cstdint> 19 #include <functional> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 24 namespace OHOS { 25 namespace Ace { 26 namespace Drawable { 27 class TaskPool { 28 public: 29 using Task = std::function<void()>; 30 31 TaskPool(const TaskPool&) = delete; 32 TaskPool& operator=(const TaskPool&) = delete; 33 virtual ~TaskPool() = default; 34 35 static TaskPool* GetInstance(); 36 37 virtual void PostTask(Task&& task, const std::string& name); 38 39 protected: 40 TaskPool() = default; 41 int32_t defaultMaxConcurrency_ = 8; 42 43 private: 44 static std::unique_ptr<TaskPool> instance_; 45 static std::once_flag initFlag; 46 }; 47 } // namespace Drawable 48 } // namespace Ace 49 } // namespace OHOS 50 51 #endif // FOUNDATION_ACE_INTERFACE_BASE_TASK_POOL_H 52