future.hpp
Go to the documentation of this file.
1 
16 #ifndef THREADPOOL_FUTURE_HPP_INCLUDED
17 #define THREADPOOL_FUTURE_HPP_INCLUDED
18 
19 
20 
21 #include "./detail/future.hpp"
22 #include <boost/utility/enable_if.hpp>
23 
24 //#include "pool.hpp"
25 //#include <boost/utility.hpp>
26 
27 //#include <boost/thread/mutex.hpp>
28 
29 
30 namespace boost { namespace threadpool
31 {
32 
42 template<class Result>
43 class future
44 {
45 private:
47 
48 public:
49  typedef Result const & result_type;
50  typedef Result future_result_type;
51 
52 
53 public:
54 
56  : m_impl(new detail::future_impl<future_result_type>()) // TODO remove this
57  {
58  }
59 
60  // only for internal usage
62  : m_impl(impl)
63  {
64  }
65 
66  bool ready() const
67  {
68  return m_impl->ready();
69  }
70 
71  void wait() const
72  {
73  m_impl->wait();
74  }
75 
76  bool timed_wait(boost::xtime const & timestamp) const
77  {
78  return m_impl->timed_wait(timestamp);
79  }
80 
81  result_type operator()() // throw( thread::cancelation_exception, ... )
82  {
83  return (*m_impl)();
84  }
85 
86  result_type get() // throw( thread::cancelation_exception, ... )
87  {
88  return (*m_impl)();
89  }
90 
91  bool cancel()
92  {
93  return m_impl->cancel();
94  }
95 
96  bool is_cancelled() const
97  {
98  return m_impl->is_cancelled();
99  }
100 };
101 
102 
103 
104 
105 
106 template<class Pool, class Function>
107 typename disable_if <
108  is_void< typename result_of< Function() >::type >,
110 >::type
111 schedule(Pool& pool, const Function& task)
112 {
113  typedef typename result_of< Function() >::type future_result_type;
114 
115  // create future impl and future
117  future <future_result_type> res(impl);
118 
119  // schedule future impl
121 
122  // return future
123  return res;
124 
125 /*
126  TODO
127  if(pool->schedule(bind(&Future::run, future)))
128  {
129  return future;
130  }
131  else
132  {
133  // construct empty future
134  return error_future;
135  }
136  */
137 }
138 
139 
140 
141 } } // namespace boost::threadpool
142 
143 #endif // THREADPOOL_FUTURE_HPP_INCLUDED
144 
bool ready() const
Definition: future.hpp:66
future(shared_ptr< detail::future_impl< Result > > const &impl)
Definition: future.hpp:61
The namespace threadpool contains a thread pool and related utility classes.
void wait() const
Definition: future.hpp:71
Experimental. Do not use in production code. TODO.
Definition: future.hpp:43
result_type operator()()
Definition: future.hpp:81
shared_ptr< detail::future_impl< Result > > m_impl
Definition: future.hpp:46
disable_if< is_void< typename result_of< Function() >::type >, future< typename result_of< Function() >::type >>::type schedule(Pool &pool, const Function &task)
Definition: future.hpp:111
Result future_result_type
Indicates the future&#39;s result type.
Definition: future.hpp:50
bool timed_wait(boost::xtime const &timestamp) const
Definition: future.hpp:76
Result const & result_type
Indicates the functor&#39;s result type.
Definition: future.hpp:49
bool is_cancelled() const
Definition: future.hpp:96


asr_descriptor_surface_based_recognition
Author(s): Allgeyer Tobias, Hutmacher Robin, Meißner Pascal
autogenerated on Mon Dec 16 2019 03:31:15