diff --git a/lib/include/srslte/common/task.h b/lib/include/srslte/common/inplace_task.h similarity index 86% rename from lib/include/srslte/common/task.h rename to lib/include/srslte/common/inplace_task.h index ecdba51de..c6b421fcf 100644 --- a/lib/include/srslte/common/task.h +++ b/lib/include/srslte/common/inplace_task.h @@ -19,8 +19,8 @@ * */ -#ifndef SRSLTE_TASK_H -#define SRSLTE_TASK_H +#ifndef SRSLTE_INPLACE_TASK_H +#define SRSLTE_INPLACE_TASK_H #include #include @@ -104,6 +104,12 @@ struct is_inplace_task : std::false_type {}; template struct is_inplace_task > : std::true_type {}; +template ::type> +using enable_small_capture = + typename std::enable_if::value, bool>::type; +template ::type> +using enable_big_capture = typename std::enable_if < Cap::value, bool>::type; + } // namespace task_details template @@ -116,24 +122,20 @@ class inplace_task public: inplace_task() noexcept { oper_ptr = oper_table_t::get_empty(); } - template ::type, - typename = typename std::enable_if::type, - typename = typename std::enable_if::value>::type> + template = true> inplace_task(T&& function) { - oper_ptr = oper_table_t::template get_small(); + using FunT = typename std::decay::type; + oper_ptr = oper_table_t::template get_small(); ::new (&buffer) FunT{std::forward(function)}; } - template ::type, - typename = typename std::enable_if::value and - (sizeof(FunT) > capacity)>::type> + template = true> inplace_task(T&& function) { - oper_ptr = oper_table_t::template get_big(); - ptr = static_cast(new FunT{std::forward(function)}); + using FunT = typename std::decay::type; + oper_ptr = oper_table_t::template get_big(); + ptr = static_cast(new FunT{std::forward(function)}); } inplace_task(inplace_task&& other) noexcept @@ -205,4 +207,4 @@ private: } // namespace srslte -#endif // SRSLTE_TASK_H +#endif // SRSLTE_INPLACE_TASK_H diff --git a/lib/include/srslte/common/multiqueue.h b/lib/include/srslte/common/multiqueue.h index 1550618fb..edad196ad 100644 --- a/lib/include/srslte/common/multiqueue.h +++ b/lib/include/srslte/common/multiqueue.h @@ -28,7 +28,7 @@ #ifndef SRSLTE_MULTIQUEUE_H #define SRSLTE_MULTIQUEUE_H -#include "task.h" +#include "inplace_task.h" #include #include #include diff --git a/lib/test/common/queue_test.cc b/lib/test/common/queue_test.cc index f38ff8e0e..25000fe5a 100644 --- a/lib/test/common/queue_test.cc +++ b/lib/test/common/queue_test.cc @@ -19,8 +19,8 @@ * */ +#include "srslte/common/inplace_task.h" #include "srslte/common/multiqueue.h" -#include "srslte/common/task.h" #include "srslte/common/thread_pool.h" #include #include @@ -334,8 +334,14 @@ int test_inplace_task() std::cout << "\n======= TEST inplace task: start =======\n"; int v = 0; - srslte::inplace_task t{[&v]() { v = 1; }}; + auto l0 = [&v]() { v = 1; }; + + srslte::inplace_task t{l0}; srslte::inplace_task t2{[v]() mutable { v = 2; }}; + // sanity static checks + static_assert(task_details::is_inplace_task::type>::value, "failed check\n"); + static_assert(std::is_base_of::type> >::value, + "failed check\n"); t(); t2();