| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- /*! \file
- * \brief TODO.
- *
- * TODO.
- *
- * Copyright (c) 2005-2007 Philipp Henkel
- *
- * Use, modification, and distribution are subject to the
- * Boost Software License, Version 1.0. (See accompanying file
- * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- *
- * http://threadpool.sourceforge.net
- *
- */
- #ifndef THREADPOOL_FUTURE_HPP_INCLUDED
- #define THREADPOOL_FUTURE_HPP_INCLUDED
-
- #include "./detail/future.hpp"
- #include <boost/utility/enable_if.hpp>
- //#include "pool.hpp"
- //#include <boost/utility.hpp>
- //#include <boost/thread/mutex.hpp>
- namespace boost { namespace threadpool
- {
- /*! \brief Experimental. Do not use in production code. TODO.
- *
- * TODO Future
- *
- * \see TODO
- *
- */
- template<class Result>
- class future
- {
- private:
- shared_ptr<detail::future_impl<Result> > m_impl;
- public:
- typedef Result const & result_type; //!< Indicates the functor's result type.
- typedef Result future_result_type; //!< Indicates the future's result type.
- public:
- future()
- : m_impl(new detail::future_impl<future_result_type>()) // TODO remove this
- {
- }
- // only for internal usage
- future(shared_ptr<detail::future_impl<Result> > const & impl)
- : m_impl(impl)
- {
- }
- bool ready() const
- {
- return m_impl->ready();
- }
- void wait() const
- {
- m_impl->wait();
- }
- bool timed_wait(boost::xtime const & timestamp) const
- {
- return m_impl->timed_wait(timestamp);
- }
- result_type operator()() // throw( thread::cancelation_exception, ... )
- {
- return (*m_impl)();
- }
- result_type get() // throw( thread::cancelation_exception, ... )
- {
- return (*m_impl)();
- }
- bool cancel()
- {
- return m_impl->cancel();
- }
- bool is_cancelled() const
- {
- return m_impl->is_cancelled();
- }
- };
- template<class Pool, class Function>
- typename disable_if <
- is_void< typename result_of< Function() >::type >,
- future< typename result_of< Function() >::type >
- >::type
- schedule(Pool& pool, const Function& task)
- {
- typedef typename result_of< Function() >::type future_result_type;
- // create future impl and future
- shared_ptr<detail::future_impl<future_result_type> > impl(new detail::future_impl<future_result_type>);
- future <future_result_type> res(impl);
- // schedule future impl
- pool.schedule(detail::future_impl_task_func<detail::future_impl, Function>(task, impl));
- // return future
- return res;
- /*
- TODO
- if(pool->schedule(bind(&Future::run, future)))
- {
- return future;
- }
- else
- {
- // construct empty future
- return error_future;
- }
- */
- }
- } } // namespace boost::threadpool
- #endif // THREADPOOL_FUTURE_HPP_INCLUDED
|