|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80439 - trunk/boost/thread
From: vicente.botet_at_[hidden]
Date: 2012-09-08 02:43:09
Author: viboes
Date: 2012-09-08 02:43:07 EDT (Sat, 08 Sep 2012)
New Revision: 80439
URL: http://svn.boost.org/trac/boost/changeset/80439
Log:
Thread: Try to fix move limitation on hpux: 7329
Text files modified:
trunk/boost/thread/future.hpp | 172 +++++++++++++++++++++++++++++++++++++--
1 files changed, 162 insertions(+), 10 deletions(-)
Modified: trunk/boost/thread/future.hpp
==============================================================================
--- trunk/boost/thread/future.hpp (original)
+++ trunk/boost/thread/future.hpp 2012-09-08 02:43:07 EDT (Sat, 08 Sep 2012)
@@ -598,7 +598,7 @@
{
for(count_type i=0;i<count;++i)
{
-#if defined __DECCXX || defined __SUNPRO_CC
+#if defined __DECCXX || defined __SUNPRO_CC || defined __hpux
locks[i]=boost::unique_lock<boost::mutex>(futures[i].future_->mutex).move();
#else
locks[i]=boost::unique_lock<boost::mutex>(futures[i].future_->mutex);
@@ -1412,6 +1412,8 @@
};
+
+
template<typename R,typename F>
struct task_object:
task_base<R>
@@ -1449,6 +1451,34 @@
}
};
+ template<typename R>
+ struct task_object<R,R (*)()>:
+ task_base<R>
+ {
+ private:
+ task_object(task_object&);
+ public:
+ R (*f)();
+ task_object(R (*f_)()):
+ f(f_)
+ {}
+ void do_run()
+ {
+ try
+ {
+ this->mark_finished_with_result(f());
+ }
+ catch(thread_interrupted& )
+ {
+ this->mark_interrupted_finish();
+ }
+ catch(...)
+ {
+ this->mark_exceptional_finish();
+ }
+ }
+ };
+
template<typename F>
struct task_object<void,F>:
task_base<void>
@@ -1488,6 +1518,35 @@
}
};
+ template<>
+ struct task_object<void,void (*)()>:
+ task_base<void>
+ {
+ private:
+ task_object(task_object&);
+ public:
+ void (*f)();
+ task_object(void (*f_)()):
+ f(f_)
+ {}
+ void do_run()
+ {
+ try
+ {
+ f();
+ this->mark_finished_with_result();
+ }
+ catch(thread_interrupted& )
+ {
+ this->mark_interrupted_finish();
+ }
+ catch(...)
+ {
+ this->mark_exceptional_finish();
+ }
+ }
+ };
+
}
template<typename R>
@@ -1666,15 +1725,46 @@
BOOST_THREAD_DCL_MOVABLE_BEG(T) packaged_task<T> BOOST_THREAD_DCL_MOVABLE_END
+
+ template <class R>
+ BOOST_THREAD_FUTURE<R>
+ async(launch policy, R(*f)())
+ {
+ if (int(policy) & int(launch::async))
+ {
+ packaged_task<R> pt( f );
+
+ BOOST_THREAD_FUTURE<R> ret = pt.get_future();
+ boost::thread( boost::move(pt) ).detach();
+ return ::boost::move(ret);
+ }
+ else if (int(policy) & int(launch::deferred))
+ {
+ packaged_task<R> pt( f );
+
+ BOOST_THREAD_FUTURE<R> ret = pt.get_future();
+ return ::boost::move(ret);
+ } else {
+ BOOST_THREAD_FUTURE<R> ret;
+ return ::boost::move(ret);
+ }
+ }
+
+ template <class R>
+ BOOST_THREAD_FUTURE<R>
+ async(R(*f)())
+ {
+ return async(launch::any, f);
+ }
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <class F>
- BOOST_THREAD_FUTURE<typename boost::result_of<F()>::type>
- async(launch policy, F f)
+ BOOST_THREAD_FUTURE<typename boost::result_of<typename decay<F>::type()>::type>
+ async(launch policy, BOOST_THREAD_FWD_REF(F) f)
{
- typedef typename boost::result_of<F()>::type R;
- //typedef BOOST_THREAD_FUTURE<R> future;
+ typedef typename boost::result_of<typename decay<F>::type()>::type R;
if (int(policy) & int(launch::async))
{
- packaged_task<R> pt( f );
+ packaged_task<R> pt( boost::forward<F>(f) );
BOOST_THREAD_FUTURE<R> ret = pt.get_future();
boost::thread( boost::move(pt) ).detach();
@@ -1682,7 +1772,7 @@
}
else if (int(policy) & int(launch::deferred))
{
- packaged_task<R> pt( f );
+ packaged_task<R> pt( boost::forward<F>(f) );
BOOST_THREAD_FUTURE<R> ret = pt.get_future();
return ::boost::move(ret);
@@ -1691,15 +1781,77 @@
return ::boost::move(ret);
}
}
-
template <class F>
BOOST_THREAD_FUTURE<typename boost::result_of<F()>::type>
- async(F f)
+ async(BOOST_THREAD_RV_REF(F) f)
{
- return async(launch::any, f);
+ return async(launch::any, boost::forward<F>(f));
}
+#else
+
+// template <class F>
+// BOOST_THREAD_FUTURE<typename boost::result_of<typename decay<F>::type()>::type>
+// async(launch policy, F const& f)
+// {
+// typedef typename boost::result_of<typename decay<F>::type()>::type R;
+// if (int(policy) & int(launch::async))
+// {
+// packaged_task<R> pt( f );
+//
+// BOOST_THREAD_FUTURE<R> ret = pt.get_future();
+// boost::thread( boost::move(pt) ).detach();
+// return ::boost::move(ret);
+// }
+// else if (int(policy) & int(launch::deferred))
+// {
+// packaged_task<R> pt( f );
+//
+// BOOST_THREAD_FUTURE<R> ret = pt.get_future();
+// return ::boost::move(ret);
+// } else {
+// BOOST_THREAD_FUTURE<R> ret;
+// return ::boost::move(ret);
+// }
+// }
+// template <class F>
+// BOOST_THREAD_FUTURE<typename boost::result_of<F()>::type>
+// async(F const& f)
+// {
+// return async(launch::any, f);
+// }
+
+ template <class F>
+ BOOST_THREAD_FUTURE<typename boost::result_of<typename decay<F>::type()>::type>
+ async(launch policy, BOOST_THREAD_FWD_REF(F) f)
+ {
+ typedef typename boost::result_of<typename decay<F>::type()>::type R;
+ if (int(policy) & int(launch::async))
+ {
+ packaged_task<R> pt( boost::forward<F>(f) );
+ BOOST_THREAD_FUTURE<R> ret = pt.get_future();
+ boost::thread( boost::move(pt) ).detach();
+ return ::boost::move(ret);
+ }
+ else if (int(policy) & int(launch::deferred))
+ {
+ packaged_task<R> pt( boost::forward<F>(f) );
+ BOOST_THREAD_FUTURE<R> ret = pt.get_future();
+ return ::boost::move(ret);
+ } else {
+ BOOST_THREAD_FUTURE<R> ret;
+ return ::boost::move(ret);
+ }
+ }
+ template <class F>
+ BOOST_THREAD_FUTURE<typename boost::result_of<F()>::type>
+ async(BOOST_THREAD_FWD_REF(F) f)
+ {
+ return async(launch::any, boost::forward<F>(f));
+ }
+
+#endif
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk