1 /*
2  * Copyright (c) 2024 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 "threading/dispatcher_impl.h"
17 
18 #include <base/containers/array_view.h>
19 #include <core/namespace.h>
20 
21 CORE_BEGIN_NAMESPACE()
22 using BASE_NS::array_view;
23 using BASE_NS::vector;
24 
25 DispatcherImpl::~DispatcherImpl() = default;
26 
DispatcherImpl(const IThreadPool::Ptr & threads)27 DispatcherImpl::DispatcherImpl(const IThreadPool::Ptr& threads) : queue_(threads) {}
28 
CollectFinishedTasks()29 vector<uint64_t> DispatcherImpl::CollectFinishedTasks()
30 {
31     return queue_.CollectFinishedTasks();
32 }
33 
Submit(uint64_t taskIdentifier,IThreadPool::ITask::Ptr && task)34 void DispatcherImpl::Submit(uint64_t taskIdentifier, IThreadPool::ITask::Ptr&& task)
35 {
36     queue_.Submit(taskIdentifier, move(task));
37 }
38 
SubmitAfter(uint64_t afterIdentifier,uint64_t taskIdentifier,IThreadPool::ITask::Ptr && task)39 void DispatcherImpl::SubmitAfter(uint64_t afterIdentifier, uint64_t taskIdentifier, IThreadPool::ITask::Ptr&& task)
40 {
41     queue_.SubmitAfter(afterIdentifier, taskIdentifier, move(task));
42 }
43 
SubmitAfter(array_view<const uint64_t> afterIdentifiers,uint64_t taskIdentifier,IThreadPool::ITask::Ptr && task)44 void DispatcherImpl::SubmitAfter(
45     array_view<const uint64_t> afterIdentifiers, uint64_t taskIdentifier, IThreadPool::ITask::Ptr&& task)
46 {
47     queue_.SubmitAfter(afterIdentifiers, taskIdentifier, move(task));
48 }
49 
Execute()50 void DispatcherImpl::Execute()
51 {
52     queue_.Execute();
53 }
54 
Clear()55 void DispatcherImpl::Clear()
56 {
57     queue_.Clear();
58 }
59 
Destroy()60 void DispatcherImpl::Destroy()
61 {
62     delete this;
63 }
64 CORE_END_NAMESPACE()
65