fw4spl
TaskHandler.hpp
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_HPP__
8 #define __FWTHREAD_TASKHANDLER_HPP__
9 
10 #include <future>
11 
12 namespace fwThread
13 {
14 
18 template <typename R>
20 {
22  TaskHandler(std::packaged_task<R>& task);
23 
25  TaskHandler(const TaskHandler& that);
26 
28  void operator ()() const;
29 
30  protected:
31 
34  {
35  }
36 
37  private:
39  mutable std::packaged_task<R> m_task;
40 };
41 
43 template <typename R>
44 inline std::function< void() > moveTaskIntoFunction(std::packaged_task<R>& task);
45 
46 } //namespace fwThread
47 
48 #include <fwThread/TaskHandler.hxx>
49 
50 #endif //__FWTHREAD_TASKHANDLER_HPP__
TaskHandler & operator=(const TaskHandler &)
Copy constructor forbidden.
Definition: TaskHandler.hpp:33
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...