summaryrefslogtreecommitdiff
path: root/boost/thread
diff options
context:
space:
mode:
Diffstat (limited to 'boost/thread')
-rw-r--r--boost/thread/future.hpp147
-rw-r--r--boost/thread/futures/launch.hpp1
-rw-r--r--boost/thread/pthread/condition_variable.hpp7
-rw-r--r--boost/thread/scoped_thread.hpp3
-rw-r--r--boost/thread/win32/thread_primitives.hpp6
5 files changed, 136 insertions, 28 deletions
diff --git a/boost/thread/future.hpp b/boost/thread/future.hpp
index 0ec484c2bf..6100c1606b 100644
--- a/boost/thread/future.hpp
+++ b/boost/thread/future.hpp
@@ -1434,6 +1434,10 @@ namespace boost
template <class F, class Rp, class Fp>
BOOST_THREAD_FUTURE<Rp>
+ make_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c);
+
+ template <class F, class Rp, class Fp>
+ BOOST_THREAD_FUTURE<Rp>
make_future_deferred_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c);
template<typename F, typename Rp, typename Fp>
@@ -1444,6 +1448,11 @@ namespace boost
BOOST_THREAD_FUTURE<Rp>
make_shared_future_async_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c);
+ template<typename F, typename Rp, typename Fp>
+ BOOST_THREAD_FUTURE<Rp>
+ make_shared_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c);
+
+
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
template<typename Ex, typename F, typename Rp, typename Fp>
BOOST_THREAD_FUTURE<Rp>
@@ -1518,6 +1527,10 @@ namespace boost
template <class F, class Rp, class Fp>
friend BOOST_THREAD_FUTURE<Rp>
+ detail::make_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c);
+
+ template <class F, class Rp, class Fp>
+ friend BOOST_THREAD_FUTURE<Rp>
detail::make_future_deferred_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c);
template<typename F, typename Rp, typename Fp>
@@ -1528,6 +1541,10 @@ namespace boost
friend BOOST_THREAD_FUTURE<Rp>
detail::make_shared_future_async_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c);
+ template<typename F, typename Rp, typename Fp>
+ friend BOOST_THREAD_FUTURE<Rp>
+ detail::make_shared_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c);
+
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
template<typename Ex, typename F, typename Rp, typename Fp>
friend BOOST_THREAD_FUTURE<Rp>
@@ -1774,6 +1791,10 @@ namespace boost
template <class F, class Rp, class Fp>
friend BOOST_THREAD_FUTURE<Rp>
+ detail::make_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c);
+
+ template <class F, class Rp, class Fp>
+ friend BOOST_THREAD_FUTURE<Rp>
detail::make_future_deferred_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c);
template<typename F, typename Rp, typename Fp>
@@ -1784,6 +1805,10 @@ namespace boost
friend BOOST_THREAD_FUTURE<Rp>
detail::make_shared_future_async_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c);
+ template<typename F, typename Rp, typename Fp>
+ friend BOOST_THREAD_FUTURE<Rp>
+ detail::make_shared_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, F f, BOOST_THREAD_FWD_REF(Fp) c);
+
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
template<typename Ex, typename F, typename Rp, typename Fp>
friend BOOST_THREAD_FUTURE<Rp>
@@ -2007,6 +2032,10 @@ namespace boost
template <class F, class Rp, class Fp>
friend BOOST_THREAD_FUTURE<Rp>
+ detail::make_future_sync_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c);
+
+ template <class F, class Rp, class Fp>
+ friend BOOST_THREAD_FUTURE<Rp>
detail::make_future_deferred_continuation_shared_state(boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c);
#endif
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
@@ -4210,12 +4239,6 @@ namespace detail {
////////////////////////////////
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
-#if defined BOOST_THREAD_CONTINUATION_SYNC
-#define continuation_shared_state_base shared_state
-#else
-#define continuation_shared_state_base future_async_shared_state_base
-#endif
-
namespace detail
{
//////////////////////
@@ -4345,27 +4368,44 @@ namespace detail
/////////////////////////
template<typename F, typename Rp, typename Fp>
- struct future_async_continuation_shared_state: continuation_shared_state<F,Rp,Fp,continuation_shared_state_base<Rp> >
+ struct future_async_continuation_shared_state: continuation_shared_state<F,Rp,Fp,future_async_shared_state_base<Rp> >
{
- typedef continuation_shared_state<F,Rp,Fp,continuation_shared_state_base<Rp> > base_type;
+ typedef continuation_shared_state<F,Rp,Fp,future_async_shared_state_base<Rp> > base_type;
public:
future_async_continuation_shared_state(BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c)
: base_type(boost::move(f), boost::forward<Fp>(c))
{ }
void launch_continuation() {
-#if defined BOOST_THREAD_CONTINUATION_SYNC
- this->call();
-#elif defined BOOST_THREAD_FUTURE_BLOCKING
+#if defined BOOST_THREAD_FUTURE_BLOCKING
boost::lock_guard<boost::mutex> lk(this->mutex);
this->thr_ = thread(&future_async_continuation_shared_state::run, static_shared_from_this(this));
#else
- thread(&future_async_continuation_shared_state::run, static_shared_from_this(this)).detach();
+ thread(&base_type::run, static_shared_from_this(this)).detach();
#endif
}
};
/////////////////////////
+ /// future_sync_continuation_shared_state
+ /////////////////////////
+
+ template<typename F, typename Rp, typename Fp>
+ struct future_sync_continuation_shared_state: continuation_shared_state<F,Rp,Fp,shared_state<Rp> >
+ {
+ typedef continuation_shared_state<F,Rp,Fp,shared_state<Rp> > base_type;
+ public:
+ future_sync_continuation_shared_state(BOOST_THREAD_RV_REF(F) f, BOOST_THREAD_FWD_REF(Fp) c)
+ : base_type(boost::move(f), boost::forward<Fp>(c))
+ { }
+
+ void launch_continuation() {
+ this->call();
+ }
+ };
+
+
+ /////////////////////////
/// future_executor_continuation_shared_state
/////////////////////////
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
@@ -4445,9 +4485,9 @@ namespace detail {
/////////////////////////
template<typename F, typename Rp, typename Fp>
- struct shared_future_async_continuation_shared_state: continuation_shared_state<F,Rp,Fp,continuation_shared_state_base<Rp> >
+ struct shared_future_async_continuation_shared_state: continuation_shared_state<F,Rp,Fp,future_async_shared_state_base<Rp> >
{
- typedef continuation_shared_state<F,Rp,Fp,continuation_shared_state_base<Rp> > base_type;
+ typedef continuation_shared_state<F,Rp,Fp,future_async_shared_state_base<Rp> > base_type;
public:
shared_future_async_continuation_shared_state(F f, BOOST_THREAD_FWD_REF(Fp) c)
@@ -4456,19 +4496,36 @@ namespace detail {
}
void launch_continuation() {
-#if defined BOOST_THREAD_CONTINUATION_SYNC
- this->call();
-#elif defined BOOST_THREAD_FUTURE_BLOCKING
+#if defined BOOST_THREAD_FUTURE_BLOCKING
boost::lock_guard<boost::mutex> lk(this->mutex);
- this->thr_ = thread(&shared_future_async_continuation_shared_state::run, static_shared_from_this(this));
+ this->thr_ = thread(&base_type::run, static_shared_from_this(this));
#else
- thread(&shared_future_async_continuation_shared_state::run, static_shared_from_this(this)).detach();
+ thread(&base_type::run, static_shared_from_this(this)).detach();
#endif
}
+ };
- ~shared_future_async_continuation_shared_state() {}
+ /////////////////////////
+ /// shared_future_async_continuation_shared_state
+ /////////////////////////
+
+ template<typename F, typename Rp, typename Fp>
+ struct shared_future_sync_continuation_shared_state: continuation_shared_state<F,Rp,Fp,shared_state<Rp> >
+ {
+ typedef continuation_shared_state<F,Rp,Fp,shared_state<Rp> > base_type;
+
+ public:
+ shared_future_sync_continuation_shared_state(F f, BOOST_THREAD_FWD_REF(Fp) c)
+ : base_type(boost::move(f), boost::forward<Fp>(c))
+ {
+ }
+
+ void launch_continuation() {
+ this->call();
+ }
};
+
/////////////////////////
/// shared_future_executor_continuation_shared_state
/////////////////////////
@@ -4577,6 +4634,21 @@ namespace detail {
return BOOST_THREAD_FUTURE<Rp>(h);
}
+ ////////////////////////////////
+ // make_future_sync_continuation_shared_state
+ ////////////////////////////////
+ template<typename F, typename Rp, typename Fp>
+ BOOST_THREAD_FUTURE<Rp>
+ make_future_sync_continuation_shared_state(
+ boost::unique_lock<boost::mutex> &lock, BOOST_THREAD_RV_REF(F) f,
+ BOOST_THREAD_FWD_REF(Fp) c) {
+ typedef typename decay<Fp>::type Cont;
+ shared_ptr<future_sync_continuation_shared_state<F,Rp, Cont> >
+ h(new future_sync_continuation_shared_state<F,Rp, Cont>(boost::move(f), boost::forward<Fp>(c)));
+ h->init(lock);
+
+ return BOOST_THREAD_FUTURE<Rp>(h);
+ }
////////////////////////////////
// make_future_executor_continuation_shared_state
@@ -4628,6 +4700,21 @@ namespace detail {
return BOOST_THREAD_FUTURE<Rp>(h);
}
////////////////////////////////
+ // make_shared_future_sync_continuation_shared_state
+ ////////////////////////////////
+ template<typename F, typename Rp, typename Fp>
+ BOOST_THREAD_FUTURE<Rp>
+ make_shared_future_sync_continuation_shared_state(
+ boost::unique_lock<boost::mutex> &lock, F f,
+ BOOST_THREAD_FWD_REF(Fp) c) {
+ typedef typename decay<Fp>::type Cont;
+ shared_ptr<shared_future_sync_continuation_shared_state<F,Rp, Cont> >
+ h(new shared_future_sync_continuation_shared_state<F,Rp, Cont>(f, boost::forward<Fp>(c)));
+ h->init(lock);
+
+ return BOOST_THREAD_FUTURE<Rp>(h);
+ }
+ ////////////////////////////////
// make_shared_future_executor_continuation_shared_state
////////////////////////////////
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
@@ -4787,6 +4874,10 @@ namespace detail {
return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_deferred_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
lock, boost::move(*this), boost::forward<F>(func)
)));
+ } else if (underlying_cast<int>(policy) & int(launch::sync)) {
+ return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_sync_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
+ lock, boost::move(*this), boost::forward<F>(func)
+ )));
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
} else if (underlying_cast<int>(policy) & int(launch::executor)) {
assert(this->future_->get_executor());
@@ -4807,6 +4898,10 @@ namespace detail {
return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_deferred_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
lock, boost::move(*this), boost::forward<F>(func)
)));
+ } else if (underlying_cast<int>(policy) & int(launch::sync)) {
+ return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_sync_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
+ lock, boost::move(*this), boost::forward<F>(func)
+ )));
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
} else if (underlying_cast<int>(policy) & int(launch::executor)) {
assert(this->future_->get_executor());
@@ -4878,7 +4973,7 @@ namespace detail {
lock, boost::move(*this), boost::forward<F>(func)
)));
} else {
- return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_async_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
+ return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_future_sync_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type>(
lock, boost::move(*this), boost::forward<F>(func)
)));
}
@@ -4906,6 +5001,10 @@ namespace detail {
return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_deferred_continuation_shared_state<shared_future<R>, future_type>(
lock, *this, boost::forward<F>(func)
)));
+ } else if (underlying_cast<int>(policy) & int(launch::sync)) {
+ return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_sync_continuation_shared_state<shared_future<R>, future_type>(
+ lock, *this, boost::forward<F>(func)
+ )));
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
} else if (underlying_cast<int>(policy) & int(launch::executor)) {
typedef executor Ex;
@@ -4925,6 +5024,10 @@ namespace detail {
return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_deferred_continuation_shared_state<shared_future<R>, future_type>(
lock, *this, boost::forward<F>(func)
)));
+ } else if (underlying_cast<int>(policy) & int(launch::sync)) {
+ return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_sync_continuation_shared_state<shared_future<R>, future_type>(
+ lock, *this, boost::forward<F>(func)
+ )));
#ifdef BOOST_THREAD_PROVIDES_EXECUTORS
} else if (underlying_cast<int>(policy) & int(launch::executor)) {
typedef executor Ex;
@@ -4986,7 +5089,7 @@ namespace detail {
lock, *this, boost::forward<F>(func)
)));
} else {
- return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_async_continuation_shared_state<shared_future<R>, future_type>(
+ return BOOST_THREAD_MAKE_RV_REF((boost::detail::make_shared_future_sync_continuation_shared_state<shared_future<R>, future_type>(
lock, *this, boost::forward<F>(func)
)));
}
diff --git a/boost/thread/futures/launch.hpp b/boost/thread/futures/launch.hpp
index 8eed42cf4d..329f40d8f3 100644
--- a/boost/thread/futures/launch.hpp
+++ b/boost/thread/futures/launch.hpp
@@ -23,6 +23,7 @@ namespace boost
executor = 4,
#endif
inherit = 8,
+ sync = 16,
any = async | deferred
}
BOOST_SCOPED_ENUM_DECLARE_END(launch)
diff --git a/boost/thread/pthread/condition_variable.hpp b/boost/thread/pthread/condition_variable.hpp
index a603351591..e8378c7d3e 100644
--- a/boost/thread/pthread/condition_variable.hpp
+++ b/boost/thread/pthread/condition_variable.hpp
@@ -336,14 +336,15 @@ namespace boost
cv_status::timeout;
}
+ template <class lock_type>
inline cv_status wait_until(
- unique_lock<mutex>& lk,
+ lock_type& lock,
chrono::time_point<chrono::steady_clock, chrono::nanoseconds> tp)
{
using namespace chrono;
nanoseconds d = tp.time_since_epoch();
timespec ts = boost::detail::to_timespec(d);
- if (do_wait_until(lk, ts)) return cv_status::no_timeout;
+ if (do_wait_until(lock, ts)) return cv_status::no_timeout;
else return cv_status::timeout;
}
@@ -391,7 +392,7 @@ namespace boost
private: // used by boost::thread::try_join_until
template <class lock_type>
- inline bool do_wait_until(
+ bool do_wait_until(
lock_type& m,
struct timespec const &timeout)
{
diff --git a/boost/thread/scoped_thread.hpp b/boost/thread/scoped_thread.hpp
index ae0d1efc53..c2da919728 100644
--- a/boost/thread/scoped_thread.hpp
+++ b/boost/thread/scoped_thread.hpp
@@ -197,6 +197,9 @@ namespace boost
*/
scoped_thread& operator=(BOOST_RV_REF(scoped_thread) x)
{
+ CallableThread on_destructor;
+
+ on_destructor(t_);
t_ = boost::move(BOOST_THREAD_RV(x).t_);
return *this;
}
diff --git a/boost/thread/win32/thread_primitives.hpp b/boost/thread/win32/thread_primitives.hpp
index b63503ad52..6d2ca7c2cf 100644
--- a/boost/thread/win32/thread_primitives.hpp
+++ b/boost/thread/win32/thread_primitives.hpp
@@ -156,7 +156,7 @@ namespace boost
{
struct _SECURITY_ATTRIBUTES;
# ifdef BOOST_NO_ANSI_APIS
-# if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA
+# if defined(BOOST_USE_WINAPI_VERSION) && ( BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA )
__declspec(dllimport) void* __stdcall CreateMutexW(_SECURITY_ATTRIBUTES*,int,wchar_t const*);
__declspec(dllimport) void* __stdcall CreateSemaphoreW(_SECURITY_ATTRIBUTES*,long,long,wchar_t const*);
__declspec(dllimport) void* __stdcall CreateEventW(_SECURITY_ATTRIBUTES*,int,int,wchar_t const*);
@@ -339,7 +339,7 @@ namespace boost
{
#if !defined(BOOST_NO_ANSI_APIS)
handle const res = win32::CreateEventA(0, type, state, mutex_name);
-#elif BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA
+#elif defined(BOOST_USE_WINAPI_VERSION) && ( BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA )
handle const res = win32::CreateEventW(0, type, state, mutex_name);
#else
handle const res = win32::CreateEventExW(
@@ -366,7 +366,7 @@ namespace boost
#if !defined(BOOST_NO_ANSI_APIS)
handle const res=win32::CreateSemaphoreA(0,initial_count,max_count,0);
#else
-#if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA
+#if defined(BOOST_USE_WINAPI_VERSION) && ( BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_VISTA )
handle const res=win32::CreateSemaphoreEx(0,initial_count,max_count,0,0);
#else
handle const res=win32::CreateSemaphoreExW(0,initial_count,max_count,0,0,semaphore_all_access);