cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
thread_pool_singleton.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <future>
4#include <type_traits>
5
6#include <cpp-toolbox/cpp-toolbox_export.hpp>
8
10
11namespace toolbox::base
12{
13
18{
19public:
24 {
26 return inst;
27 }
28
32 template<class F, class... Args>
33 auto submit(F&& f, Args&&... args)
34 -> std::future<typename std::invoke_result_t<F, Args...>>
35 {
36 return pool_.submit(std::forward<F>(f), std::forward<Args>(args)...);
37 }
38
42 size_t get_thread_count() const { return pool_.get_thread_count(); }
43
44private:
45 thread_pool_singleton_t() = default;
46 ~thread_pool_singleton_t() = default;
47
50
51 thread_pool_t pool_{};
52};
53
54} // namespace toolbox::base
#define CPP_TOOLBOX_DISABLE_COPY(ClassType)
禁用类的拷贝操作 / Disable copy operations for a class
Definition class.hpp:15
#define CPP_TOOLBOX_DISABLE_MOVE(ClassType)
禁用类的移动操作 / Disable move operations for a class
Definition class.hpp:31
Definition object_pool.hpp:100
简单的线程池单例封装/A simple singleton wrapper around thread_pool_t
Definition thread_pool_singleton.hpp:18
static thread_pool_singleton_t & instance()
获取单例实例/Get the singleton instance
Definition thread_pool_singleton.hpp:23
auto submit(F &&f, Args &&... args) -> std::future< typename std::invoke_result_t< F, Args... > >
提交任务/Submit a task
Definition thread_pool_singleton.hpp:33
size_t get_thread_count() const
获取线程数量/Get underlying worker count
Definition thread_pool_singleton.hpp:42
Definition thread_pool.hpp:60
通用的编译器、平台、架构检测和实用宏定义 / Common macros for compiler, platform, architecture detection and utility macro...
提供基础 C++ 工具和组件。 Provides fundamental C++ utilities and components.