26 lines
622 B
C++
26 lines
622 B
C++
#pragma once
|
|
|
|
#include "thread_pool.h"
|
|
#include <memory>
|
|
#include <mutex>
|
|
|
|
class GlobalThreadPool {
|
|
private:
|
|
static std::unique_ptr<ThreadPool> instance_;
|
|
static std::once_flag initialized_;
|
|
|
|
public:
|
|
static ThreadPool& getInstance() {
|
|
std::call_once(initialized_, []() {
|
|
unsigned int hw_threads = std::thread::hardware_concurrency();
|
|
size_t num_threads = hw_threads > 4 ? hw_threads / 2 : 2;
|
|
instance_ = std::make_unique<ThreadPool>(num_threads);
|
|
});
|
|
return *instance_;
|
|
}
|
|
|
|
static void shutdown() {
|
|
instance_.reset();
|
|
}
|
|
};
|