LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_thread.cpp
Go to the documentation of this file.
1/* #define DEBUGTRACE_ENABLED */
2#include "lasp_thread.h"
3#include "BS_thread_pool.hpp"
4#include "debugtrace.hpp"
5#include <memory>
6
12std::weak_ptr<BS::thread_pool> _global_weak_pool;
13
18std::mutex _mtx;
19
20using Lck = std::scoped_lock<std::mutex>;
21using rte = std::runtime_error;
22
24 DEBUGTRACE_ENTER;
25 Lck lck(_mtx);
27 _pool = _global_weak_pool.lock();
28 if (!_pool) {
29 _pool = std::make_shared<BS::thread_pool>();
30 if (!_pool) {
31 throw rte("Fatal: could not allocate thread pool!");
32 }
33 // Update global weak pointer
34 _global_weak_pool = _pool;
35 }
36}
GlobalThreadPool()
Instantiate handle to the thread pool.
std::runtime_error rte
Definition lasp_daq.cpp:16
std::scoped_lock< std::mutex > Lck
std::weak_ptr< BS::thread_pool > _global_weak_pool
Store a global weak_ptr, that is used to create new shared pointers if any other shared pointers are ...
std::mutex _mtx
Global mutex, used to restrict the pool creation to a single thread at once.
std::scoped_lock< std::mutex > lck