mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-09-01 14:49:25 +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 "threadpool.hpp"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
void joinThreadPoolInstance() {
|
||||||
|
rtc::ThreadPool::Instance().join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
ThreadPool &ThreadPool::Instance() {
|
ThreadPool &ThreadPool::Instance() {
|
||||||
// Init handles joining on cleanup
|
|
||||||
static ThreadPool *instance = new ThreadPool;
|
static ThreadPool *instance = new ThreadPool;
|
||||||
return *instance;
|
return *instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool::~ThreadPool() { join(); }
|
ThreadPool::ThreadPool() {
|
||||||
|
std::atexit(joinThreadPoolInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadPool::~ThreadPool() {}
|
||||||
|
|
||||||
int ThreadPool::count() const {
|
int ThreadPool::count() const {
|
||||||
std::unique_lock lock(mWorkersMutex);
|
std::unique_lock lock(mWorkersMutex);
|
||||||
|
@ -56,7 +56,7 @@ public:
|
|||||||
auto enqueue(F &&f, Args &&... args) -> invoke_future_t<F, Args...>;
|
auto enqueue(F &&f, Args &&... args) -> invoke_future_t<F, Args...>;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ThreadPool() = default;
|
ThreadPool();
|
||||||
~ThreadPool();
|
~ThreadPool();
|
||||||
|
|
||||||
std::function<void()> dequeue(); // returns null function if joining
|
std::function<void()> dequeue(); // returns null function if joining
|
||||||
|
Reference in New Issue
Block a user