|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75788 - trunk/boost/thread
From: vicente.botet_at_[hidden]
Date: 2011-12-03 09:06:33
Author: viboes
Date: 2011-12-03 09:06:32 EST (Sat, 03 Dec 2011)
New Revision: 75788
URL: http://svn.boost.org/trac/boost/changeset/75788
Log:
Thread: 4480 (move part) + 6175 Compile error with SunStudio
Text files modified:
trunk/boost/thread/future.hpp | 151 ++++++++++++++++++++-------------------
1 files changed, 79 insertions(+), 72 deletions(-)
Modified: trunk/boost/thread/future.hpp
==============================================================================
--- trunk/boost/thread/future.hpp (original)
+++ trunk/boost/thread/future.hpp 2011-12-03 09:06:32 EST (Sat, 03 Dec 2011)
@@ -1,4 +1,4 @@
-// (C) Copyright 2008-10 Anthony Williams
+// (C) Copyright 2008-10 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -111,7 +111,7 @@
do_callback(lock);
return external_waiters.insert(external_waiters.end(),&cv);
}
-
+
void remove_external_waiter(waiter_list::iterator it)
{
boost::lock_guard<boost::mutex> lock(mutex);
@@ -132,7 +132,7 @@
struct relocker
{
boost::unique_lock<boost::mutex>& lock;
-
+
relocker(boost::unique_lock<boost::mutex>& lock_):
lock(lock_)
{
@@ -155,7 +155,7 @@
local_callback();
}
}
-
+
void wait(bool rethrow=true)
{
@@ -185,7 +185,7 @@
}
return true;
}
-
+
void mark_exceptional_finish_internal(boost::exception_ptr const& e)
{
exception=e;
@@ -213,7 +213,7 @@
{
callback=boost::bind(f,boost::ref(*u));
}
-
+
private:
future_object_base(future_object_base const&);
future_object_base& operator=(future_object_base const&);
@@ -238,7 +238,7 @@
{
storage.reset(new T(t));
}
-
+
static void init(storage_type& storage,rvalue_source_type t)
{
storage.reset(new T(static_cast<rvalue_source_type>(t)));
@@ -249,7 +249,7 @@
storage.reset();
}
};
-
+
template<typename T>
struct future_traits<T&>
{
@@ -296,7 +296,7 @@
typedef typename future_traits<T>::source_reference_type source_reference_type;
typedef typename future_traits<T>::rvalue_source_type rvalue_source_type;
typedef typename future_traits<T>::move_dest_type move_dest_type;
-
+
storage_type result;
future_object():
@@ -353,6 +353,8 @@
struct future_object<void>:
detail::future_object_base
{
+ typedef void move_dest_type;
+
future_object()
{}
@@ -371,7 +373,7 @@
{
wait();
}
-
+
future_state::state get_state()
{
boost::lock_guard<boost::mutex> guard(mutex);
@@ -394,7 +396,7 @@
{
struct registered_waiter;
typedef std::vector<registered_waiter>::size_type count_type;
-
+
struct registered_waiter
{
boost::shared_ptr<detail::future_object_base> future;
@@ -408,26 +410,30 @@
{}
};
-
+
struct all_futures_lock
{
count_type count;
boost::scoped_array<boost::unique_lock<boost::mutex> > locks;
-
+
all_futures_lock(std::vector<registered_waiter>& futures):
count(futures.size()),locks(new boost::unique_lock<boost::mutex>[count])
{
for(count_type i=0;i<count;++i)
{
+#if defined __DECCXX || defined __SUNPRO_CC
+ locks[i]=boost::unique_lock<boost::mutex>(futures[i].future->mutex).move();
+#else
locks[i]=boost::unique_lock<boost::mutex>(futures[i].future->mutex);
+#endif
}
}
-
+
void lock()
{
boost::lock(locks.get(),locks.get()+count);
}
-
+
void unlock()
{
for(count_type i=0;i<count;++i)
@@ -436,16 +442,16 @@
}
}
};
-
+
boost::condition_variable_any cv;
std::vector<registered_waiter> futures;
count_type future_count;
-
+
public:
future_waiter():
future_count(0)
{}
-
+
template<typename F>
void add(F& f)
{
@@ -471,7 +477,7 @@
cv.wait(lk);
}
}
-
+
~future_waiter()
{
for(count_type i=0;i<futures.size();++i)
@@ -479,9 +485,9 @@
futures[i].future->remove_external_waiter(futures[i].wait_iterator);
}
}
-
+
};
-
+
}
template <typename R>
@@ -495,13 +501,13 @@
{
BOOST_STATIC_CONSTANT(bool, value=false);
};
-
+
template<typename T>
struct is_future_type<unique_future<T> >
{
BOOST_STATIC_CONSTANT(bool, value=true);
};
-
+
template<typename T>
struct is_future_type<shared_future<T> >
{
@@ -531,7 +537,7 @@
f2.wait();
f3.wait();
}
-
+
template<typename F1,typename F2,typename F3,typename F4>
void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4)
{
@@ -556,7 +562,7 @@
{
if(begin==end)
return end;
-
+
detail::future_waiter waiter;
for(Iterator current=begin;current!=end;++current)
{
@@ -583,7 +589,7 @@
waiter.add(f3);
return waiter.wait();
}
-
+
template<typename F1,typename F2,typename F3,typename F4>
unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4)
{
@@ -606,7 +612,7 @@
waiter.add(f5);
return waiter.wait();
}
-
+
template <typename R>
class promise;
@@ -620,7 +626,7 @@
unique_future& operator=(unique_future& rhs);// = delete;
typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
-
+
future_ptr future;
friend class shared_future<R>;
@@ -639,7 +645,7 @@
unique_future()
{}
-
+
~unique_future()
{}
@@ -689,7 +695,7 @@
return future->get();
}
-
+
// functions to check state, and wait for ready
state get_state() const
{
@@ -699,23 +705,23 @@
}
return future->get_state();
}
-
+
bool is_ready() const
{
return get_state()==future_state::ready;
}
-
+
bool has_exception() const
{
return future && future->has_exception();
}
-
+
bool has_value() const
{
return future && future->has_value();
}
-
+
void wait() const
{
if(!future)
@@ -724,13 +730,13 @@
}
future->wait(false);
}
-
+
template<typename Duration>
bool timed_wait(Duration const& rel_time) const
{
return timed_wait_until(boost::get_system_time()+rel_time);
}
-
+
bool timed_wait_until(boost::system_time const& abs_time) const
{
if(!future)
@@ -739,14 +745,14 @@
}
return future->timed_wait_until(abs_time);
}
-
+
};
template <typename R>
class shared_future
{
typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
-
+
future_ptr future;
// shared_future(const unique_future<R>& other);
@@ -755,7 +761,7 @@
friend class detail::future_waiter;
friend class promise<R>;
friend class packaged_task<R>;
-
+
shared_future(future_ptr future_):
future(future_)
{}
@@ -799,7 +805,7 @@
other.future.reset();
return *this;
}
-#else
+#else
shared_future(boost::detail::thread_move_t<shared_future> other):
future(other->future)
{
@@ -837,6 +843,7 @@
}
// retrieving the value
+ //typename detail::future_object<R>::move_dest_type get()
R get()
{
if(!future)
@@ -846,7 +853,7 @@
return future->get();
}
-
+
// functions to check state, and wait for ready
state get_state() const
{
@@ -856,18 +863,18 @@
}
return future->get_state();
}
-
+
bool is_ready() const
{
return get_state()==future_state::ready;
}
-
+
bool has_exception() const
{
return future && future->has_exception();
}
-
+
bool has_value() const
{
return future && future->has_value();
@@ -881,13 +888,13 @@
}
future->wait(false);
}
-
+
template<typename Duration>
bool timed_wait(Duration const& rel_time) const
{
return timed_wait_until(boost::get_system_time()+rel_time);
}
-
+
bool timed_wait_until(boost::system_time const& abs_time) const
{
if(!future)
@@ -896,17 +903,17 @@
}
return future->timed_wait_until(abs_time);
}
-
+
};
template <typename R>
class promise
{
typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
-
+
future_ptr future;
bool future_obtained;
-
+
promise(promise & rhs);// = delete;
promise & operator=(promise & rhs);// = delete;
@@ -918,14 +925,14 @@
atomic_compare_exchange(&future,&blank,future_ptr(new detail::future_object<R>));
}
}
-
+
public:
// template <class Allocator> explicit promise(Allocator a);
promise():
future(),future_obtained(false)
{}
-
+
~promise()
{
if(future)
@@ -975,8 +982,8 @@
{
return boost::detail::thread_move_t<promise>(*this);
}
-#endif
-
+#endif
+
void swap(promise& other)
{
future.swap(other.future);
@@ -1035,17 +1042,17 @@
lazy_init();
future->set_wait_callback(f,this);
}
-
+
};
template <>
class promise<void>
{
typedef boost::shared_ptr<detail::future_object<void> > future_ptr;
-
+
future_ptr future;
bool future_obtained;
-
+
promise(promise & rhs);// = delete;
promise & operator=(promise & rhs);// = delete;
@@ -1063,7 +1070,7 @@
promise():
future(),future_obtained(false)
{}
-
+
~promise()
{
if(future)
@@ -1114,7 +1121,7 @@
return boost::detail::thread_move_t<promise>(*this);
}
#endif
-
+
void swap(promise& other)
{
future.swap(other.future);
@@ -1125,7 +1132,7 @@
unique_future<void> get_future()
{
lazy_init();
-
+
if(future_obtained)
{
boost::throw_exception(future_already_retrieved());
@@ -1162,7 +1169,7 @@
lazy_init();
future->set_wait_callback(f,this);
}
-
+
};
namespace detail
@@ -1199,12 +1206,12 @@
this->mark_exceptional_finish_internal(boost::copy_exception(boost::broken_promise()));
}
}
-
-
+
+
virtual void do_run()=0;
};
-
-
+
+
template<typename R,typename F>
struct task_object:
task_base<R>
@@ -1216,7 +1223,7 @@
task_object(boost::detail::thread_move_t<F> f_):
f(f_)
{}
-
+
void do_run()
{
try
@@ -1241,7 +1248,7 @@
task_object(boost::detail::thread_move_t<F> f_):
f(f_)
{}
-
+
void do_run()
{
try
@@ -1257,7 +1264,7 @@
};
}
-
+
template<typename R>
class packaged_task
@@ -1267,12 +1274,12 @@
packaged_task(packaged_task&);// = delete;
packaged_task& operator=(packaged_task&);// = delete;
-
+
public:
packaged_task():
future_obtained(false)
{}
-
+
// construction and destruction
template <class F>
explicit packaged_task(F const& f):
@@ -1281,7 +1288,7 @@
explicit packaged_task(R(*f)()):
task(new detail::task_object<R,R(*)()>(f)),future_obtained(false)
{}
-
+
template <class F>
explicit packaged_task(boost::detail::thread_move_t<F> f):
task(new detail::task_object<R,F>(f)),future_obtained(false)
@@ -1357,7 +1364,7 @@
boost::throw_exception(future_already_retrieved());
}
}
-
+
// execution
void operator()()
@@ -1374,7 +1381,7 @@
{
task->set_wait_callback(f,this);
}
-
+
};
}
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