fw4spl
TaskHandler.hxx
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWTHREAD_TASKHANDLER_HXX__
8 #define __FWTHREAD_TASKHANDLER_HXX__
9 
10 namespace fwThread
11 {
12 template <typename R>
13 TaskHandler<R>::TaskHandler(std::packaged_task<R>& task) :
14  m_task(std::move(task))
15 {
16 }
17 
18 template <typename R>
20  m_task(std::move(that.m_task))
21 {
22 }
23 
24 //------------------------------------------------------------------------------
25 
26 template <typename R>
28 {
29  this->m_task();
30 }
31 
32 //------------------------------------------------------------------------------
33 
34 template <typename R>
35 inline std::function< void() > moveTaskIntoFunction(std::packaged_task<R>& task)
36 {
37  return TaskHandler<R>(task);
38 }
39 
40 } //namespace fwThread
41 
42 #endif //__FWTHREAD_TASKHANDLER_HXX__
STL namespace.
TaskHandler(std::packaged_task< R > &task)
Constructor, moves task.
Definition: TaskHandler.hxx:13
void operator()() const
Executes intern packaged task.
Definition: TaskHandler.hxx:27
This class encapsulates packaged task and provides a copy constructor.
Definition: TaskHandler.hpp:19
std::function< void() > moveTaskIntoFunction(std::packaged_task< R > &task)
Encapsulate a packaged_task into a boost function to be easily posted on a worker.
Definition: TaskHandler.hxx:35
This namespace fwThread provides few tools to execute asynchronous tasks on different threads...