mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 23:25:33 +00:00
Join thread pool at exit to prevent static destruction order issue
This commit is contained in:
@ -18,15 +18,26 @@
|
||||
|
||||
#include "threadpool.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace {
|
||||
void joinThreadPoolInstance() {
|
||||
rtc::ThreadPool::Instance().join();
|
||||
}
|
||||
}
|
||||
|
||||
namespace rtc {
|
||||
|
||||
ThreadPool &ThreadPool::Instance() {
|
||||
// Init handles joining on cleanup
|
||||
static ThreadPool *instance = new ThreadPool;
|
||||
return *instance;
|
||||
}
|
||||
|
||||
ThreadPool::~ThreadPool() { join(); }
|
||||
ThreadPool::ThreadPool() {
|
||||
std::atexit(joinThreadPoolInstance);
|
||||
}
|
||||
|
||||
ThreadPool::~ThreadPool() {}
|
||||
|
||||
int ThreadPool::count() const {
|
||||
std::unique_lock lock(mWorkersMutex);
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
auto enqueue(F &&f, Args &&... args) -> invoke_future_t<F, Args...>;
|
||||
|
||||
protected:
|
||||
ThreadPool() = default;
|
||||
ThreadPool();
|
||||
~ThreadPool();
|
||||
|
||||
std::function<void()> dequeue(); // returns null function if joining
|
||||
|
Reference in New Issue
Block a user