| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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:
46 shared_ptr<detail::future_impl<Result> > m_impl;
47
48 public:
49 typedef Result const & result_type;
50 typedef Result future_result_type;
51
52
53 public:
54
55 future()
56 : m_impl(new detail::future_impl<future_result_type>()) // TODO remove this
57 {
58 }
59
60 // only for internal usage
61 future(shared_ptr<detail::future_impl<Result> > const & impl)
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 >,
109 future< 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
116 shared_ptr<detail::future_impl<future_result_type> > impl(new detail::future_impl<future_result_type>);
117 future <future_result_type> res(impl);
118
119 // schedule future impl
120 pool.schedule(detail::future_impl_task_func<detail::future_impl, Function>(task, 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
boost::threadpool::future::ready
bool ready() const
Definition: future.hpp:66
boost::threadpool::future::future
future(shared_ptr< detail::future_impl< Result > > const &impl)
Definition: future.hpp:61
boost
The namespace threadpool contains a thread pool and related utility classes.
Definition: iter_pos.hpp:13
boost::threadpool::future::wait
void wait() const
Definition: future.hpp:71
boost::threadpool::future::future
future()
Definition: future.hpp:55
GaudiMath::Function
Genfun::AbsFunction Function
Definition: GaudiMath.h:24
boost::threadpool::future
Experimental.
Definition: future.hpp:43
boost::threadpool::future::cancel
bool cancel()
Definition: future.hpp:91
boost::threadpool::future::operator()
result_type operator()()
Definition: future.hpp:81
detail
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
pool
Definition: PoolClasses.h:11
boost::threadpool::future::m_impl
shared_ptr< detail::future_impl< Result > > m_impl
Definition: future.hpp:46
boost::threadpool::schedule
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
gaudirun.type
type
Definition: gaudirun.py:133
boost::threadpool::future::future_result_type
Result future_result_type
Indicates the future&#39;s result type.
Definition: future.hpp:50
boost::threadpool::future::timed_wait
bool timed_wait(boost::xtime const &timestamp) const
Definition: future.hpp:76
boost::threadpool::detail::future_impl
Definition: future.hpp:36
boost::threadpool::detail::future_impl_task_func
Definition: future.hpp:164
boost::threadpool::future::result_type
Result const & result_type
Indicates the functor&#39;s result type.
Definition: future.hpp:49
future.hpp
TODO.
boost::threadpool::future::is_cancelled
bool is_cancelled() const
Definition: future.hpp:96