From 437db3af03ae98a39bd0e35fa6e3aeb6ed7ecb42 Mon Sep 17 00:00:00 2001 From: Francisco Date: Fri, 9 Apr 2021 13:00:31 +0100 Subject: [PATCH] forbid allocations when dispatching task to thread pool --- lib/include/srsran/adt/move_callback.h | 15 +++++++++------ lib/include/srsran/common/thread_pool.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/include/srsran/adt/move_callback.h b/lib/include/srsran/adt/move_callback.h index 8e8538347..fbeef74b6 100644 --- a/lib/include/srsran/adt/move_callback.h +++ b/lib/include/srsran/adt/move_callback.h @@ -33,9 +33,9 @@ namespace srsran { //! Size of the buffer used by "move_callback" to store functors without calling "new" -constexpr size_t default_buffer_size = 32; +constexpr size_t default_move_callback_buffer_size = 32; -template +template class move_callback; namespace task_details { @@ -115,8 +115,8 @@ using enable_if_big_capture = } // namespace task_details -template -class move_callback +template +class move_callback { static constexpr size_t capacity = Capacity >= sizeof(void*) ? Capacity : sizeof(void*); ///< size of buffer using storage_t = typename std::aligned_storage::type; @@ -140,6 +140,9 @@ public: template = true> move_callback(T&& function) { + static_assert( + not ForbidAlloc, + "Failed to store provided callback in std::move_callback specialization that forbids heap allocations."); using FunT = typename std::decay::type; static const task_details::heap_table_t heap_oper_table{}; oper_ptr = &heap_oper_table; @@ -176,8 +179,8 @@ private: const oper_table_t* oper_ptr; }; -template -constexpr task_details::empty_table_t move_callback::empty_table; +template +constexpr task_details::empty_table_t move_callback::empty_table; //! Generic move task using move_task_t = move_callback; diff --git a/lib/include/srsran/common/thread_pool.h b/lib/include/srsran/common/thread_pool.h index 17e97c4f8..efed3f953 100644 --- a/lib/include/srsran/common/thread_pool.h +++ b/lib/include/srsran/common/thread_pool.h @@ -89,7 +89,7 @@ private: class task_thread_pool { - using task_t = srsran::move_callback; + using task_t = srsran::move_callback; public: task_thread_pool(uint32_t nof_workers = 1, bool start_deferred = false, int32_t prio_ = -1, uint32_t mask_ = 255);