forked from LeenkxTeam/LNXRNT
Here comes he RunT!
This commit is contained in:
25
Sources/global_thread_pool.h
Normal file
25
Sources/global_thread_pool.h
Normal file
@ -0,0 +1,25 @@
|
||||
#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();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user