changed inplace_task file name

master
Francisco Paisana 5 years ago committed by Francisco Paisana
parent a6b7c5d1d2
commit ef834b3c60

@ -19,8 +19,8 @@
* *
*/ */
#ifndef SRSLTE_TASK_H #ifndef SRSLTE_INPLACE_TASK_H
#define SRSLTE_TASK_H #define SRSLTE_INPLACE_TASK_H
#include <cstddef> #include <cstddef>
#include <functional> #include <functional>
@ -104,6 +104,12 @@ struct is_inplace_task : std::false_type {};
template <class Sig, size_t Capacity> template <class Sig, size_t Capacity>
struct is_inplace_task<inplace_task<Sig, Capacity> > : std::true_type {}; struct is_inplace_task<inplace_task<Sig, Capacity> > : std::true_type {};
template <typename T, size_t Cap, typename FunT = typename std::decay<T>::type>
using enable_small_capture =
typename std::enable_if<sizeof(FunT) <= Cap and not is_inplace_task<FunT>::value, bool>::type;
template <typename T, size_t Cap, typename FunT = typename std::decay<T>::type>
using enable_big_capture = typename std::enable_if < Cap<sizeof(FunT) and not is_inplace_task<FunT>::value, bool>::type;
} // namespace task_details } // namespace task_details
template <class R, class... Args, size_t Capacity> template <class R, class... Args, size_t Capacity>
@ -116,24 +122,20 @@ class inplace_task<R(Args...), Capacity>
public: public:
inplace_task() noexcept { oper_ptr = oper_table_t::get_empty(); } inplace_task() noexcept { oper_ptr = oper_table_t::get_empty(); }
template <typename T, template <typename T, task_details::enable_small_capture<T, capacity> = true>
typename FunT = typename std::decay<T>::type,
typename = typename std::enable_if<sizeof(FunT) <= capacity>::type,
typename = typename std::enable_if<not task_details::is_inplace_task<FunT>::value>::type>
inplace_task(T&& function) inplace_task(T&& function)
{ {
oper_ptr = oper_table_t::template get_small<FunT>(); using FunT = typename std::decay<T>::type;
oper_ptr = oper_table_t::template get_small<FunT>();
::new (&buffer) FunT{std::forward<T>(function)}; ::new (&buffer) FunT{std::forward<T>(function)};
} }
template <typename T, template <typename T, task_details::enable_big_capture<T, capacity> = true>
typename FunT = typename std::decay<T>::type,
typename = typename std::enable_if<not task_details::is_inplace_task<FunT>::value and
(sizeof(FunT) > capacity)>::type>
inplace_task(T&& function) inplace_task(T&& function)
{ {
oper_ptr = oper_table_t::template get_big<FunT>(); using FunT = typename std::decay<T>::type;
ptr = static_cast<void*>(new FunT{std::forward<T>(function)}); oper_ptr = oper_table_t::template get_big<FunT>();
ptr = static_cast<void*>(new FunT{std::forward<T>(function)});
} }
inplace_task(inplace_task&& other) noexcept inplace_task(inplace_task&& other) noexcept
@ -205,4 +207,4 @@ private:
} // namespace srslte } // namespace srslte
#endif // SRSLTE_TASK_H #endif // SRSLTE_INPLACE_TASK_H

@ -28,7 +28,7 @@
#ifndef SRSLTE_MULTIQUEUE_H #ifndef SRSLTE_MULTIQUEUE_H
#define SRSLTE_MULTIQUEUE_H #define SRSLTE_MULTIQUEUE_H
#include "task.h" #include "inplace_task.h"
#include <algorithm> #include <algorithm>
#include <condition_variable> #include <condition_variable>
#include <functional> #include <functional>

@ -19,8 +19,8 @@
* *
*/ */
#include "srslte/common/inplace_task.h"
#include "srslte/common/multiqueue.h" #include "srslte/common/multiqueue.h"
#include "srslte/common/task.h"
#include "srslte/common/thread_pool.h" #include "srslte/common/thread_pool.h"
#include <iostream> #include <iostream>
#include <thread> #include <thread>
@ -334,8 +334,14 @@ int test_inplace_task()
std::cout << "\n======= TEST inplace task: start =======\n"; std::cout << "\n======= TEST inplace task: start =======\n";
int v = 0; int v = 0;
srslte::inplace_task<void()> t{[&v]() { v = 1; }}; auto l0 = [&v]() { v = 1; };
srslte::inplace_task<void()> t{l0};
srslte::inplace_task<void()> t2{[v]() mutable { v = 2; }}; srslte::inplace_task<void()> t2{[v]() mutable { v = 2; }};
// sanity static checks
static_assert(task_details::is_inplace_task<std::decay<decltype(t)>::type>::value, "failed check\n");
static_assert(std::is_base_of<std::false_type, task_details::is_inplace_task<std::decay<decltype(l0)>::type> >::value,
"failed check\n");
t(); t();
t2(); t2();

Loading…
Cancel
Save