/*! \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 //#include "pool.hpp" //#include //#include namespace boost { namespace threadpool { /*! \brief Experimental. Do not use in production code. TODO. * * TODO Future * * \see TODO * */ template class future { private: shared_ptr > 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()) // TODO remove this { } // only for internal usage future(shared_ptr > 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 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 > impl(new detail::future_impl); future res(impl); // schedule future impl pool.schedule(detail::future_impl_task_func(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