diff --git a/src/lasp/device/lasp_streammgr.h b/src/lasp/device/lasp_streammgr.h index 8955cc6..d5e1e4c 100644 --- a/src/lasp/device/lasp_streammgr.h +++ b/src/lasp/device/lasp_streammgr.h @@ -31,7 +31,7 @@ class StreamMgr { */ std::unique_ptr _inputStream, _outputStream; - ThreadSafeThreadPool _pool; + GlobalThreadPool _pool; /** * @brief All indata handlers are called when input data is available. Note diff --git a/src/lasp/dsp/lasp_biquadbank.h b/src/lasp/dsp/lasp_biquadbank.h index 0328cea..cc4833d 100644 --- a/src/lasp/dsp/lasp_biquadbank.h +++ b/src/lasp/dsp/lasp_biquadbank.h @@ -61,7 +61,7 @@ public: class BiquadBank : public Filter { std::vector _filters; vd _gains; - ThreadSafeThreadPool _pool; + GlobalThreadPool _pool; mutable std::mutex _mtx; public: diff --git a/src/lasp/dsp/lasp_slm.h b/src/lasp/dsp/lasp_slm.h index 1c2d871..297ff8f 100644 --- a/src/lasp/dsp/lasp_slm.h +++ b/src/lasp/dsp/lasp_slm.h @@ -15,7 +15,7 @@ * channel. A channel is the result of a filtered signal */ class SLM { - ThreadSafeThreadPool _pool; + GlobalThreadPool _pool; /** * @brief A, C or Z weighting, depending on the pre-filter installed. */ diff --git a/src/lasp/dsp/lasp_thread.cpp b/src/lasp/dsp/lasp_thread.cpp index a04e051..af3cde9 100644 --- a/src/lasp/dsp/lasp_thread.cpp +++ b/src/lasp/dsp/lasp_thread.cpp @@ -12,14 +12,15 @@ std::weak_ptr _global_weak_pool; /** - * @brief Static storage for the mutex. + * @brief Global mutex, used to restrict the pool creation to a single thread + * at once. */ -std::mutex ThreadSafeThreadPool::_mtx; +std::mutex _mtx; using Lck = std::scoped_lock; using rte = std::runtime_error; -ThreadSafeThreadPool::ThreadSafeThreadPool() { +GlobalThreadPool::GlobalThreadPool() { DEBUGTRACE_ENTER; Lck lck(_mtx); /// See if we can get it from the global ptr. If not, time to allocate it. diff --git a/src/lasp/dsp/lasp_thread.h b/src/lasp/dsp/lasp_thread.h index c28805e..396f1b2 100644 --- a/src/lasp/dsp/lasp_thread.h +++ b/src/lasp/dsp/lasp_thread.h @@ -7,30 +7,21 @@ * safely spawn threads also from other threads. Only wraps a submit() and * push_task for now. */ -class ThreadSafeThreadPool { +class GlobalThreadPool { /** * @brief Shared access to the thread pool. */ std::shared_ptr _pool; - /** - * @brief Global mutex, used to restrict pool access to a single thread at - * once. - */ - static std::mutex _mtx; - - using Lck = std::scoped_lock; - ThreadSafeThreadPool(const ThreadSafeThreadPool&) = delete; - ThreadSafeThreadPool & - operator=(const ThreadSafeThreadPool&) = delete; public: /** * @brief Instantiate handle to the thread pool. */ - ThreadSafeThreadPool(); + GlobalThreadPool(); + GlobalThreadPool(const GlobalThreadPool &) = default; + GlobalThreadPool &operator=(const GlobalThreadPool &) = default; - /** * @brief Wrapper around BS::thread_pool::submit(...) */ @@ -38,8 +29,6 @@ public: typename F, typename... A, typename R = std::invoke_result_t, std::decay_t...>> [[nodiscard]] std::future submit(F &&task, A &&...args) { - /// Lock access to pool - Lck lck(_mtx); return _pool->submit(task, args...); } @@ -47,9 +36,6 @@ public: * @brief Wrapper around BS::thread_pool::push_task(...) */ template void push_task(F &&task, A &&...args) { - /// Lock access to pool - Lck lck(_mtx); _pool->push_task(task, args...); } }; - diff --git a/src/lasp/dsp/lasp_threadedindatahandler.h b/src/lasp/dsp/lasp_threadedindatahandler.h index b769ad1..0d7f030 100644 --- a/src/lasp/dsp/lasp_threadedindatahandler.h +++ b/src/lasp/dsp/lasp_threadedindatahandler.h @@ -37,7 +37,7 @@ class ThreadedInDataHandlerBase { std::atomic _thread_running{false}; std::atomic _thread_can_safely_run{false}; - ThreadSafeThreadPool _pool; + GlobalThreadPool _pool; /** * @brief Function pointer that is called when new DaqData arrives.