Go to the documentation of this file.00001
00016 #ifndef THREADPOOL_FUTURE_HPP_INCLUDED
00017 #define THREADPOOL_FUTURE_HPP_INCLUDED
00018
00019
00020
00021 #include "./detail/future.hpp"
00022 #include <boost/utility/enable_if.hpp>
00023
00024
00025
00026
00027
00028
00029
00030 namespace boost { namespace threadpool
00031 {
00032
00042 template<class Result>
00043 class future
00044 {
00045 private:
00046 shared_ptr<detail::future_impl<Result> > m_impl;
00047
00048 public:
00049 typedef Result const & result_type;
00050 typedef Result future_result_type;
00051
00052
00053 public:
00054
00055 future()
00056 : m_impl(new detail::future_impl<future_result_type>())
00057 {
00058 }
00059
00060
00061 future(shared_ptr<detail::future_impl<Result> > const & impl)
00062 : m_impl(impl)
00063 {
00064 }
00065
00066 bool ready() const
00067 {
00068 return m_impl->ready();
00069 }
00070
00071 void wait() const
00072 {
00073 m_impl->wait();
00074 }
00075
00076 bool timed_wait(boost::xtime const & timestamp) const
00077 {
00078 return m_impl->timed_wait(timestamp);
00079 }
00080
00081 result_type operator()()
00082 {
00083 return (*m_impl)();
00084 }
00085
00086 result_type get()
00087 {
00088 return (*m_impl)();
00089 }
00090
00091 bool cancel()
00092 {
00093 return m_impl->cancel();
00094 }
00095
00096 bool is_cancelled() const
00097 {
00098 return m_impl->is_cancelled();
00099 }
00100 };
00101
00102
00103
00104
00105
00106 template<class Pool, class Function>
00107 typename disable_if <
00108 is_void< typename result_of< Function() >::type >,
00109 future< typename result_of< Function() >::type >
00110 >::type
00111 schedule(Pool& pool, const Function& task)
00112 {
00113 typedef typename result_of< Function() >::type future_result_type;
00114
00115
00116 shared_ptr<detail::future_impl<future_result_type> > impl(new detail::future_impl<future_result_type>);
00117 future <future_result_type> res(impl);
00118
00119
00120 pool.schedule(detail::future_impl_task_func<detail::future_impl, Function>(task, impl));
00121
00122
00123 return res;
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 }
00138
00139
00140
00141 } }
00142
00143 #endif // THREADPOOL_FUTURE_HPP_INCLUDED
00144