olp-cpp-sdk  1.22.0
ThreadPoolTaskScheduler.h
1 /*
2  * Copyright (C) 2019-2021 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <thread>
23 #include <vector>
24 
25 #include <olp/core/thread/TaskScheduler.h>
26 
27 namespace olp {
28 namespace thread {
29 
35 class CORE_API ThreadPoolTaskScheduler final : public TaskScheduler {
36  public:
42  explicit ThreadPoolTaskScheduler(size_t thread_count = 1u);
43 
48 
57 
58  protected:
70 
82  uint32_t priority) override;
83 
84  private:
85  class QueueImpl;
86 
88  std::vector<std::thread> thread_pool_;
90  std::unique_ptr<QueueImpl> queue_;
91 };
92 
93 } // namespace thread
94 } // namespace olp
An abstract interface that is used as a base for the custom thread scheduling strategy.
Definition: TaskScheduler.h:45
std::function< void()> CallFuncType
An alias for the abstract interface input.
Definition: TaskScheduler.h:48
An implementation of the TaskScheduler instance that uses a thread pool.
Definition: ThreadPoolTaskScheduler.h:35
ThreadPoolTaskScheduler(size_t thread_count=1u)
Creates the ThreadPoolTaskScheduler object with one thread.
void EnqueueTask(TaskScheduler::CallFuncType &&func, uint32_t priority) override
Overrides the base class method to enqueue tasks and execute them on the next free thread from the th...
void EnqueueTask(TaskScheduler::CallFuncType &&func) override
Overrides the base class method to enqueue tasks and execute them on the next free thread from the th...
ThreadPoolTaskScheduler(ThreadPoolTaskScheduler &&)=delete
Non-copyable, non-movable.
~ThreadPoolTaskScheduler() override
Closes the SyncQueue instance and joins threads.
ThreadPoolTaskScheduler & operator=(ThreadPoolTaskScheduler &&)=delete
Non-copyable, non-movable.
ThreadPoolTaskScheduler(const ThreadPoolTaskScheduler &)=delete
Non-copyable, non-movable.
ThreadPoolTaskScheduler & operator=(const ThreadPoolTaskScheduler &)=delete
Non-copyable, non-movable.
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24