diff --git a/lib/include/srslte/common/move_callback.h b/lib/include/srslte/common/move_callback.h index 46c9194d1..d7d06d520 100644 --- a/lib/include/srslte/common/move_callback.h +++ b/lib/include/srslte/common/move_callback.h @@ -28,6 +28,7 @@ namespace srslte { +//! Size of the buffer used by "move_callback" to store functors without calling "new" constexpr size_t default_buffer_size = 32; template @@ -35,6 +36,7 @@ class move_callback; namespace task_details { +//! Base vtable for move/call/destroy operations over the functor stored in "move_callback class oper_table_t { @@ -46,6 +48,7 @@ public: virtual bool is_in_small_buffer() const = 0; }; +//! specialization of move/call/destroy operations for when the "move_callback" is empty template class empty_table_t : public oper_table_t { @@ -57,6 +60,7 @@ public: bool is_in_small_buffer() const final { return true; } }; +//! specialization of move/call/destroy operations for when the functor is stored in "move_callback" buffer template class smallbuffer_table_t : public oper_table_t { @@ -72,6 +76,7 @@ public: bool is_in_small_buffer() const final { return true; } }; +//! move/call/destroy operations for when the functor is stored outside of "move_callback" buffer template class heap_table_t : public oper_table_t { @@ -87,13 +92,13 @@ public: bool is_in_small_buffer() const final { return false; } }; -//! Metafunction to check if object is move_callback<> type +//! Metafunction to check if a type is an instantiation of move_callback template struct is_move_callback : std::false_type {}; template struct is_move_callback > : std::true_type {}; -//! metafunctions to enable/disable functions based on whether the callback fits small buffer or not +//! metafunctions to enable different ctor implementations depending on whether the callback fits the small buffer template ::type> using enable_if_small_capture = typename std::enable_if::value, bool>::type; @@ -106,7 +111,7 @@ using enable_if_big_capture = template class move_callback { - static constexpr size_t capacity = Capacity >= sizeof(void*) ? Capacity : sizeof(void*); + static constexpr size_t capacity = Capacity >= sizeof(void*) ? Capacity : sizeof(void*); ///< size of buffer using storage_t = typename std::aligned_storage::type; using oper_table_t = task_details::oper_table_t; static constexpr task_details::empty_table_t empty_table{}; @@ -114,6 +119,7 @@ class move_callback public: move_callback() noexcept : oper_ptr(&empty_table) {} + //! Called when T capture fits the move_callback buffer template = true> move_callback(T&& function) noexcept { @@ -123,6 +129,7 @@ public: ::new (&buffer) FunT{std::forward(function)}; } + //! Called when T capture does not fit the move_callback buffer template = true> move_callback(T&& function) {