7 #ifndef _QI_STRAND_HPP_
8 #define _QI_STRAND_HPP_
11 #include <boost/shared_ptr.hpp>
12 #include <boost/function.hpp>
13 #include <boost/noncopyable.hpp>
14 #include <boost/type_traits/function_traits.hpp>
44 void post(
const boost::function<
void()>& callback);
51 bool isInThisContext();
53 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
54 template <typename T, typename F, typename ARG0 comma ATYPEDECL> \
55 boost::function<T> schedulerFor( \
56 const F& func, const ARG0& arg0 comma ADECL, \
57 const boost::function<void()>& fallbackCb = boost::function<void()>()) \
59 boost::function<T> funcbind = qi::bind<T>(func, arg0 comma AUSE); \
60 return qi::trackWithFallback( \
62 SchedulerHelper<boost::function_traits<T>::arity, T>::_scheduler( \
70 boost::shared_ptr<StrandPrivate> _p;
72 template <
int N,
typename T>
73 struct SchedulerHelper;
74 #define typedefi(z, n, _) \
75 typedef typename boost::function_traits<T>::BOOST_PP_CAT( \
76 BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type) BOOST_PP_CAT(P, n);
77 #define placeholders(z, n, __) , BOOST_PP_CAT(_, BOOST_PP_INC(n))
78 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
79 template <typename T> \
80 struct SchedulerHelper<n, T> \
82 BOOST_PP_REPEAT(n, typedefi, _); \
83 typedef typename boost::function_traits<T>::result_type R; \
84 static boost::function<T> _scheduler(const boost::function<T>& f, \
87 return qi::bind<T>(&_asyncCall, strand, \
88 f BOOST_PP_REPEAT(n, placeholders, _)); \
90 static qi::Future<R> _asyncCall(Strand* strand, \
91 const boost::function<T>& func comma \
95 return ((qi::ExecutionContext*)strand) \
96 ->async(qi::bind<R()>(func comma AUSE)); \
107 #endif // _QI_STRAND_HPP_
boost::chrono::duration< int64_t, boost::nano > Duration
Convenience typedefs.
#define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)
Future< R > async(boost::function< R()> callback, uint64_t usDelay=0)
SteadyClock::time_point SteadyClockTimePoint
Steady clock time point.