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
16 #include <mutex>
17
18 #include "ffrt_inner.h"
19
20 #include "utils/task_pool.h"
21
22 namespace OHOS {
23 namespace Ace {
24 namespace Drawable {
25 class TaskPoolImpl final : public TaskPool {
26 public:
27 TaskPoolImpl();
28 ~TaskPoolImpl() = default;
29
30 void PostTask(Task&& task, const std::string& name) override;
31
32 private:
33 std::unique_ptr<ffrt::queue> queue_ = nullptr;
34 };
35
36 std::unique_ptr<TaskPool> TaskPool::instance_;
37 std::once_flag TaskPool::initFlag;
38
GetInstance()39 TaskPool* TaskPool::GetInstance()
40 {
41 std::call_once(initFlag, []() { instance_.reset(new TaskPoolImpl); });
42 return instance_.get();
43 }
44
TaskPoolImpl()45 TaskPoolImpl::TaskPoolImpl()
46 {
47 queue_ = std::make_unique<ffrt::queue>(ffrt::queue_concurrent, "ImageTaskPool",
48 ffrt::queue_attr().qos(ffrt::qos_default).max_concurrency(defaultMaxConcurrency_));
49 }
50
PostTask(Task && task,const std::string & name)51 void TaskPoolImpl::PostTask(Task&& task, const std::string& name)
52 {
53 queue_->submit_h(task);
54 }
55
56 } // namespace Drawable
57 } // namespace Ace
58 } // namespace OHOS
59