2010-05-11 19:42:16 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===--------------------------- future -----------------------------------===//
|
|
|
|
//
|
2010-05-11 21:36:01 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
2010-11-16 22:09:02 +00:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_FUTURE
|
|
|
|
#define _LIBCPP_FUTURE
|
|
|
|
|
|
|
|
/*
|
|
|
|
future synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
enum class future_errc
|
|
|
|
{
|
|
|
|
broken_promise,
|
|
|
|
future_already_retrieved,
|
|
|
|
promise_already_satisfied,
|
|
|
|
no_state
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class launch
|
|
|
|
{
|
2010-11-23 18:33:54 +00:00
|
|
|
async = 1,
|
|
|
|
deferred = 2,
|
|
|
|
any = async | deferred
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class future_status
|
|
|
|
{
|
|
|
|
ready,
|
|
|
|
timeout,
|
|
|
|
deferred
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct is_error_code_enum<future_errc> : public true_type { };
|
2012-07-21 17:46:55 +00:00
|
|
|
error_code make_error_code(future_errc e) noexcept;
|
|
|
|
error_condition make_error_condition(future_errc e) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2012-07-21 17:46:55 +00:00
|
|
|
const error_category& future_category() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
class future_error
|
|
|
|
: public logic_error
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
future_error(error_code ec); // exposition only
|
|
|
|
|
2012-07-21 17:46:55 +00:00
|
|
|
const error_code& code() const noexcept;
|
|
|
|
const char* what() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class R>
|
|
|
|
class promise
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
promise();
|
|
|
|
template <class Allocator>
|
|
|
|
promise(allocator_arg_t, const Allocator& a);
|
2012-07-21 17:46:55 +00:00
|
|
|
promise(promise&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
promise(const promise& rhs) = delete;
|
|
|
|
~promise();
|
|
|
|
|
|
|
|
// assignment
|
2012-07-21 17:46:55 +00:00
|
|
|
promise& operator=(promise&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
promise& operator=(const promise& rhs) = delete;
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(promise& other) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// retrieving the result
|
|
|
|
future<R> get_future();
|
|
|
|
|
|
|
|
// setting the result
|
|
|
|
void set_value(const R& r);
|
|
|
|
void set_value(R&& r);
|
|
|
|
void set_exception(exception_ptr p);
|
|
|
|
|
|
|
|
// setting the result with deferred notification
|
|
|
|
void set_value_at_thread_exit(const R& r);
|
|
|
|
void set_value_at_thread_exit(R&& r);
|
|
|
|
void set_exception_at_thread_exit(exception_ptr p);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class R>
|
|
|
|
class promise<R&>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
promise();
|
|
|
|
template <class Allocator>
|
|
|
|
promise(allocator_arg_t, const Allocator& a);
|
2012-07-21 17:46:55 +00:00
|
|
|
promise(promise&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
promise(const promise& rhs) = delete;
|
|
|
|
~promise();
|
|
|
|
|
|
|
|
// assignment
|
2012-07-21 17:46:55 +00:00
|
|
|
promise& operator=(promise&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
promise& operator=(const promise& rhs) = delete;
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(promise& other) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// retrieving the result
|
2010-08-27 20:10:19 +00:00
|
|
|
future<R&> get_future();
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// setting the result
|
|
|
|
void set_value(R& r);
|
|
|
|
void set_exception(exception_ptr p);
|
|
|
|
|
|
|
|
// setting the result with deferred notification
|
|
|
|
void set_value_at_thread_exit(R&);
|
|
|
|
void set_exception_at_thread_exit(exception_ptr p);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class promise<void>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
promise();
|
|
|
|
template <class Allocator>
|
|
|
|
promise(allocator_arg_t, const Allocator& a);
|
2012-07-21 17:46:55 +00:00
|
|
|
promise(promise&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
promise(const promise& rhs) = delete;
|
|
|
|
~promise();
|
|
|
|
|
|
|
|
// assignment
|
2012-07-21 17:46:55 +00:00
|
|
|
promise& operator=(promise&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
promise& operator=(const promise& rhs) = delete;
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(promise& other) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// retrieving the result
|
2010-08-27 20:10:19 +00:00
|
|
|
future<void> get_future();
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// setting the result
|
|
|
|
void set_value();
|
|
|
|
void set_exception(exception_ptr p);
|
|
|
|
|
|
|
|
// setting the result with deferred notification
|
|
|
|
void set_value_at_thread_exit();
|
|
|
|
void set_exception_at_thread_exit(exception_ptr p);
|
|
|
|
};
|
|
|
|
|
2012-07-21 17:46:55 +00:00
|
|
|
template <class R> void swap(promise<R>& x, promise<R>& y) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class R, class Alloc>
|
|
|
|
struct uses_allocator<promise<R>, Alloc> : public true_type {};
|
|
|
|
|
|
|
|
template <class R>
|
|
|
|
class future
|
|
|
|
{
|
|
|
|
public:
|
2012-07-21 17:46:55 +00:00
|
|
|
future() noexcept;
|
|
|
|
future(future&&) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
future(const future& rhs) = delete;
|
|
|
|
~future();
|
|
|
|
future& operator=(const future& rhs) = delete;
|
2012-07-21 17:46:55 +00:00
|
|
|
future& operator=(future&&) noexcept;
|
|
|
|
shared_future<R> share();
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
|
|
|
R get();
|
|
|
|
|
|
|
|
// functions to check state
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
void wait() const;
|
|
|
|
template <class Rep, class Period>
|
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
|
|
|
|
template <class Clock, class Duration>
|
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class R>
|
|
|
|
class future<R&>
|
|
|
|
{
|
|
|
|
public:
|
2012-07-21 17:46:55 +00:00
|
|
|
future() noexcept;
|
|
|
|
future(future&&) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
future(const future& rhs) = delete;
|
|
|
|
~future();
|
|
|
|
future& operator=(const future& rhs) = delete;
|
2012-07-21 17:46:55 +00:00
|
|
|
future& operator=(future&&) noexcept;
|
|
|
|
shared_future<R&> share();
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
|
|
|
R& get();
|
|
|
|
|
|
|
|
// functions to check state
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
void wait() const;
|
|
|
|
template <class Rep, class Period>
|
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
|
|
|
|
template <class Clock, class Duration>
|
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class future<void>
|
|
|
|
{
|
|
|
|
public:
|
2012-07-21 17:46:55 +00:00
|
|
|
future() noexcept;
|
|
|
|
future(future&&) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
future(const future& rhs) = delete;
|
|
|
|
~future();
|
|
|
|
future& operator=(const future& rhs) = delete;
|
2012-07-21 17:46:55 +00:00
|
|
|
future& operator=(future&&) noexcept;
|
|
|
|
shared_future<void> share();
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
|
|
|
void get();
|
|
|
|
|
|
|
|
// functions to check state
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
void wait() const;
|
|
|
|
template <class Rep, class Period>
|
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
|
|
|
|
template <class Clock, class Duration>
|
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class R>
|
|
|
|
class shared_future
|
|
|
|
{
|
|
|
|
public:
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
shared_future(const shared_future& rhs);
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future(future<R>&&) noexcept;
|
|
|
|
shared_future(shared_future&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
~shared_future();
|
|
|
|
shared_future& operator=(const shared_future& rhs);
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future& operator=(shared_future&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
|
|
|
const R& get() const;
|
|
|
|
|
|
|
|
// functions to check state
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
void wait() const;
|
|
|
|
template <class Rep, class Period>
|
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
|
|
|
|
template <class Clock, class Duration>
|
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class R>
|
|
|
|
class shared_future<R&>
|
|
|
|
{
|
|
|
|
public:
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
shared_future(const shared_future& rhs);
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future(future<R&>&&) noexcept;
|
|
|
|
shared_future(shared_future&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
~shared_future();
|
|
|
|
shared_future& operator=(const shared_future& rhs);
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future& operator=(shared_future&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
|
|
|
R& get() const;
|
|
|
|
|
|
|
|
// functions to check state
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
void wait() const;
|
|
|
|
template <class Rep, class Period>
|
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
|
|
|
|
template <class Clock, class Duration>
|
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class shared_future<void>
|
|
|
|
{
|
|
|
|
public:
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
shared_future(const shared_future& rhs);
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future(future<void>&&) noexcept;
|
|
|
|
shared_future(shared_future&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
~shared_future();
|
|
|
|
shared_future& operator=(const shared_future& rhs);
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future& operator=(shared_future&& rhs) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
|
|
|
void get() const;
|
|
|
|
|
|
|
|
// functions to check state
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
void wait() const;
|
|
|
|
template <class Rep, class Period>
|
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
|
|
|
|
template <class Clock, class Duration>
|
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class F, class... Args>
|
|
|
|
future<typename result_of<F(Args...)>::type>
|
|
|
|
async(F&& f, Args&&... args);
|
|
|
|
|
|
|
|
template <class F, class... Args>
|
|
|
|
future<typename result_of<F(Args...)>::type>
|
|
|
|
async(launch policy, F&& f, Args&&... args);
|
|
|
|
|
2010-05-11 21:36:01 +00:00
|
|
|
template <class> class packaged_task; // undefined
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class R, class... ArgTypes>
|
|
|
|
class packaged_task<R(ArgTypes...)>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef R result_type;
|
|
|
|
|
|
|
|
// construction and destruction
|
2012-07-21 17:46:55 +00:00
|
|
|
packaged_task() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class F>
|
|
|
|
explicit packaged_task(F&& f);
|
|
|
|
template <class F, class Allocator>
|
|
|
|
explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
|
|
|
|
~packaged_task();
|
|
|
|
|
|
|
|
// no copy
|
2012-07-21 19:34:12 +00:00
|
|
|
packaged_task(const packaged_task&) = delete;
|
|
|
|
packaged_task& operator=(const packaged_task&) = delete;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// move support
|
2012-07-21 17:46:55 +00:00
|
|
|
packaged_task(packaged_task&& other) noexcept;
|
|
|
|
packaged_task& operator=(packaged_task&& other) noexcept;
|
|
|
|
void swap(packaged_task& other) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
// result retrieval
|
|
|
|
future<R> get_future();
|
|
|
|
|
|
|
|
// execution
|
|
|
|
void operator()(ArgTypes... );
|
|
|
|
void make_ready_at_thread_exit(ArgTypes...);
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class R>
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
|
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <system_error>
|
2010-08-27 20:10:19 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <chrono>
|
|
|
|
#include <exception>
|
2010-09-03 21:46:37 +00:00
|
|
|
#include <mutex>
|
2010-08-27 20:10:19 +00:00
|
|
|
#include <thread>
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-10-17 20:05:10 +00:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-05-11 19:42:16 +00:00
|
|
|
#pragma GCC system_header
|
2011-10-17 20:05:10 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
|
|
|
//enum class future_errc
|
2011-12-02 19:36:40 +00:00
|
|
|
_LIBCPP_DECLARE_STRONG_ENUM(future_errc)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
broken_promise,
|
|
|
|
future_already_retrieved,
|
|
|
|
promise_already_satisfied,
|
|
|
|
no_state
|
|
|
|
};
|
2011-12-02 19:36:40 +00:00
|
|
|
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc)
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
template <>
|
|
|
|
struct _LIBCPP_VISIBLE is_error_code_enum<future_errc> : public true_type {};
|
2010-08-25 17:32:05 +00:00
|
|
|
|
2011-12-02 19:36:40 +00:00
|
|
|
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
|
|
|
|
template <>
|
|
|
|
struct _LIBCPP_VISIBLE is_error_code_enum<future_errc::_> : public true_type { };
|
|
|
|
#endif
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
//enum class launch
|
2011-12-02 19:36:40 +00:00
|
|
|
_LIBCPP_DECLARE_STRONG_ENUM(launch)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2010-11-23 18:33:54 +00:00
|
|
|
async = 1,
|
|
|
|
deferred = 2,
|
|
|
|
any = async | deferred
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
2011-12-02 19:36:40 +00:00
|
|
|
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch)
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
//enum class future_status
|
2011-12-02 19:36:40 +00:00
|
|
|
_LIBCPP_DECLARE_STRONG_ENUM(future_status)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
ready,
|
|
|
|
timeout,
|
|
|
|
deferred
|
|
|
|
};
|
2011-12-02 19:36:40 +00:00
|
|
|
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status)
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_VISIBLE
|
2012-07-21 17:46:55 +00:00
|
|
|
const error_category& future_category() _NOEXCEPT;
|
2010-08-25 17:32:05 +00:00
|
|
|
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
error_code
|
2012-07-21 17:46:55 +00:00
|
|
|
make_error_code(future_errc __e) _NOEXCEPT
|
2010-08-25 17:32:05 +00:00
|
|
|
{
|
|
|
|
return error_code(static_cast<int>(__e), future_category());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
error_condition
|
2012-07-21 17:46:55 +00:00
|
|
|
make_error_condition(future_errc __e) _NOEXCEPT
|
2010-08-25 17:32:05 +00:00
|
|
|
{
|
|
|
|
return error_condition(static_cast<int>(__e), future_category());
|
|
|
|
}
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
class _LIBCPP_EXCEPTION_ABI future_error
|
2010-08-25 17:32:05 +00:00
|
|
|
: public logic_error
|
|
|
|
{
|
|
|
|
error_code __ec_;
|
|
|
|
public:
|
|
|
|
future_error(error_code __ec);
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
const error_code& code() const _NOEXCEPT {return __ec_;}
|
2011-07-07 21:03:52 +00:00
|
|
|
|
|
|
|
virtual ~future_error() _NOEXCEPT;
|
2010-08-25 17:32:05 +00:00
|
|
|
};
|
|
|
|
|
2010-08-27 20:10:19 +00:00
|
|
|
class __assoc_sub_state
|
|
|
|
: public __shared_count
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
exception_ptr __exception_;
|
|
|
|
mutable mutex __mut_;
|
|
|
|
mutable condition_variable __cv_;
|
|
|
|
unsigned __state_;
|
|
|
|
|
2011-05-28 14:41:13 +00:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
2010-08-30 18:46:21 +00:00
|
|
|
void __sub_wait(unique_lock<mutex>& __lk);
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
__constructed = 1,
|
|
|
|
__future_attached = 2,
|
|
|
|
ready = 4,
|
|
|
|
deferred = 8
|
|
|
|
};
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
__assoc_sub_state() : __state_(0) {}
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
bool __has_value() const
|
|
|
|
{return (__state_ & __constructed) || (__exception_ != nullptr);}
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
void __set_future_attached() {__state_ |= __future_attached;}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
bool __has_future_attached() const {return __state_ & __future_attached;}
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-30 18:46:21 +00:00
|
|
|
void __set_deferred() {__state_ |= deferred;}
|
|
|
|
|
2010-08-27 20:10:19 +00:00
|
|
|
void __make_ready();
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
bool __is_ready() const {return __state_ & ready;}
|
|
|
|
|
|
|
|
void set_value();
|
|
|
|
void set_value_at_thread_exit();
|
|
|
|
|
|
|
|
void set_exception(exception_ptr __p);
|
|
|
|
void set_exception_at_thread_exit(exception_ptr __p);
|
|
|
|
|
|
|
|
void copy();
|
|
|
|
|
2010-08-30 18:46:21 +00:00
|
|
|
void wait();
|
2010-08-27 20:10:19 +00:00
|
|
|
template <class _Rep, class _Period>
|
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const;
|
|
|
|
template <class _Clock, class _Duration>
|
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
virtual void __execute();
|
2010-08-27 20:10:19 +00:00
|
|
|
};
|
|
|
|
|
2010-08-28 21:01:06 +00:00
|
|
|
template <class _Clock, class _Duration>
|
|
|
|
future_status
|
|
|
|
__assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
|
|
|
|
{
|
|
|
|
unique_lock<mutex> __lk(__mut_);
|
2010-08-30 18:46:21 +00:00
|
|
|
if (__state_ & deferred)
|
|
|
|
return future_status::deferred;
|
|
|
|
while (!(__state_ & ready) && _Clock::now() < __abs_time)
|
2010-08-28 21:01:06 +00:00
|
|
|
__cv_.wait_until(__lk, __abs_time);
|
|
|
|
if (__state_ & ready)
|
|
|
|
return future_status::ready;
|
|
|
|
return future_status::timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Rep, class _Period>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
future_status
|
|
|
|
__assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
|
|
|
|
{
|
2010-11-20 19:16:30 +00:00
|
|
|
return wait_until(chrono::steady_clock::now() + __rel_time);
|
2010-08-28 21:01:06 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
class __assoc_state
|
|
|
|
: public __assoc_sub_state
|
|
|
|
{
|
|
|
|
typedef __assoc_sub_state base;
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef typename aligned_storage<sizeof(_Rp), alignment_of<_Rp>::value>::type _Up;
|
2010-08-27 20:10:19 +00:00
|
|
|
protected:
|
2011-11-29 18:15:50 +00:00
|
|
|
_Up __value_;
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2011-05-28 14:41:13 +00:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
template <class _Arg>
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
void set_value(_Arg&& __arg);
|
|
|
|
#else
|
|
|
|
void set_value(_Arg& __arg);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <class _Arg>
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
void set_value_at_thread_exit(_Arg&& __arg);
|
|
|
|
#else
|
|
|
|
void set_value_at_thread_exit(_Arg& __arg);
|
|
|
|
#endif
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
_Rp move();
|
|
|
|
typename add_lvalue_reference<_Rp>::type copy();
|
2010-08-27 20:10:19 +00:00
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
if (this->__state_ & base::__constructed)
|
2011-11-29 18:15:50 +00:00
|
|
|
reinterpret_cast<_Rp*>(&__value_)->~_Rp();
|
2010-08-27 20:10:19 +00:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
template <class _Arg>
|
|
|
|
void
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp>::set_value(_Arg&& __arg)
|
2010-08-27 20:10:19 +00:00
|
|
|
#else
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp>::set_value(_Arg& __arg)
|
2010-08-27 20:10:19 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
unique_lock<mutex> __lk(this->__mut_);
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (this->__has_value())
|
|
|
|
throw future_error(make_error_code(future_errc::promise_already_satisfied));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2011-11-29 18:15:50 +00:00
|
|
|
::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
|
2010-08-27 20:10:19 +00:00
|
|
|
this->__state_ |= base::__constructed | base::ready;
|
|
|
|
__lk.unlock();
|
|
|
|
__cv_.notify_all();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
template <class _Arg>
|
|
|
|
void
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg)
|
2010-08-27 20:10:19 +00:00
|
|
|
#else
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp>::set_value_at_thread_exit(_Arg& __arg)
|
2010-08-27 20:10:19 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
unique_lock<mutex> __lk(this->__mut_);
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (this->__has_value())
|
|
|
|
throw future_error(make_error_code(future_errc::promise_already_satisfied));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2011-11-29 18:15:50 +00:00
|
|
|
::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
|
2010-08-27 20:10:19 +00:00
|
|
|
this->__state_ |= base::__constructed;
|
2010-10-14 19:18:04 +00:00
|
|
|
__thread_local_data()->__make_ready_at_thread_exit(this);
|
2010-08-27 20:10:19 +00:00
|
|
|
__lk.unlock();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
_Rp
|
|
|
|
__assoc_state<_Rp>::move()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
unique_lock<mutex> __lk(this->__mut_);
|
2010-08-30 18:46:21 +00:00
|
|
|
this->__sub_wait(__lk);
|
2010-08-27 20:10:19 +00:00
|
|
|
if (this->__exception_ != nullptr)
|
|
|
|
rethrow_exception(this->__exception_);
|
2011-11-29 18:15:50 +00:00
|
|
|
return _VSTD::move(*reinterpret_cast<_Rp*>(&__value_));
|
2010-08-27 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
typename add_lvalue_reference<_Rp>::type
|
|
|
|
__assoc_state<_Rp>::copy()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
unique_lock<mutex> __lk(this->__mut_);
|
2010-08-30 18:46:21 +00:00
|
|
|
this->__sub_wait(__lk);
|
2010-08-27 20:10:19 +00:00
|
|
|
if (this->__exception_ != nullptr)
|
|
|
|
rethrow_exception(this->__exception_);
|
2011-11-29 18:15:50 +00:00
|
|
|
return *reinterpret_cast<_Rp*>(&__value_);
|
2010-08-27 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
class __assoc_state<_Rp&>
|
2010-08-28 21:01:06 +00:00
|
|
|
: public __assoc_sub_state
|
|
|
|
{
|
|
|
|
typedef __assoc_sub_state base;
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef _Rp* _Up;
|
2010-08-28 21:01:06 +00:00
|
|
|
protected:
|
2011-11-29 18:15:50 +00:00
|
|
|
_Up __value_;
|
2010-08-28 21:01:06 +00:00
|
|
|
|
2011-05-28 14:41:13 +00:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
2010-08-28 21:01:06 +00:00
|
|
|
public:
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
void set_value(_Rp& __arg);
|
|
|
|
void set_value_at_thread_exit(_Rp& __arg);
|
2010-08-28 21:01:06 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
_Rp& copy();
|
2010-08-28 21:01:06 +00:00
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-28 21:01:06 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp&>::__on_zero_shared() _NOEXCEPT
|
2010-08-28 21:01:06 +00:00
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-28 21:01:06 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp&>::set_value(_Rp& __arg)
|
2010-08-28 21:01:06 +00:00
|
|
|
{
|
|
|
|
unique_lock<mutex> __lk(this->__mut_);
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-28 21:01:06 +00:00
|
|
|
if (this->__has_value())
|
|
|
|
throw future_error(make_error_code(future_errc::promise_already_satisfied));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-28 21:01:06 +00:00
|
|
|
__value_ = &__arg;
|
|
|
|
this->__state_ |= base::__constructed | base::ready;
|
|
|
|
__lk.unlock();
|
|
|
|
__cv_.notify_all();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-28 21:01:06 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg)
|
2010-08-28 21:01:06 +00:00
|
|
|
{
|
|
|
|
unique_lock<mutex> __lk(this->__mut_);
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-28 21:01:06 +00:00
|
|
|
if (this->__has_value())
|
|
|
|
throw future_error(make_error_code(future_errc::promise_already_satisfied));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-28 21:01:06 +00:00
|
|
|
__value_ = &__arg;
|
|
|
|
this->__state_ |= base::__constructed;
|
2010-10-14 19:18:04 +00:00
|
|
|
__thread_local_data()->__make_ready_at_thread_exit(this);
|
2010-08-28 21:01:06 +00:00
|
|
|
__lk.unlock();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
_Rp&
|
|
|
|
__assoc_state<_Rp&>::copy()
|
2010-08-28 21:01:06 +00:00
|
|
|
{
|
|
|
|
unique_lock<mutex> __lk(this->__mut_);
|
2010-08-30 18:46:21 +00:00
|
|
|
this->__sub_wait(__lk);
|
2010-08-28 21:01:06 +00:00
|
|
|
if (this->__exception_ != nullptr)
|
|
|
|
rethrow_exception(this->__exception_);
|
|
|
|
return *__value_;
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Alloc>
|
2010-08-27 20:10:19 +00:00
|
|
|
class __assoc_state_alloc
|
2011-11-29 18:15:50 +00:00
|
|
|
: public __assoc_state<_Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef __assoc_state<_Rp> base;
|
2010-08-27 20:10:19 +00:00
|
|
|
_Alloc __alloc_;
|
|
|
|
|
2011-05-28 14:41:13 +00:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
explicit __assoc_state_alloc(const _Alloc& __a)
|
|
|
|
: __alloc_(__a) {}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Alloc>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
if (this->__state_ & base::__constructed)
|
2011-11-29 18:15:50 +00:00
|
|
|
reinterpret_cast<_Rp*>(&this->__value_)->~_Rp();
|
2010-08-27 20:10:19 +00:00
|
|
|
typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_);
|
|
|
|
this->~__assoc_state_alloc();
|
|
|
|
__a.deallocate(this, 1);
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Alloc>
|
|
|
|
class __assoc_state_alloc<_Rp&, _Alloc>
|
|
|
|
: public __assoc_state<_Rp&>
|
2010-08-28 21:01:06 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef __assoc_state<_Rp&> base;
|
2010-08-28 21:01:06 +00:00
|
|
|
_Alloc __alloc_;
|
|
|
|
|
2011-05-28 14:41:13 +00:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
2010-08-28 21:01:06 +00:00
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-28 21:01:06 +00:00
|
|
|
explicit __assoc_state_alloc(const _Alloc& __a)
|
|
|
|
: __alloc_(__a) {}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Alloc>
|
2010-08-28 21:01:06 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT
|
2010-08-28 21:01:06 +00:00
|
|
|
{
|
|
|
|
typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_);
|
|
|
|
this->~__assoc_state_alloc();
|
|
|
|
__a.deallocate(this, 1);
|
|
|
|
}
|
|
|
|
|
2010-08-27 20:10:19 +00:00
|
|
|
template <class _Alloc>
|
|
|
|
class __assoc_sub_state_alloc
|
|
|
|
: public __assoc_sub_state
|
|
|
|
{
|
|
|
|
typedef __assoc_sub_state base;
|
|
|
|
_Alloc __alloc_;
|
|
|
|
|
2011-05-28 14:41:13 +00:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
explicit __assoc_sub_state_alloc(const _Alloc& __a)
|
|
|
|
: __alloc_(__a) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
void
|
2011-05-28 14:41:13 +00:00
|
|
|
__assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2010-08-28 21:01:06 +00:00
|
|
|
typename _Alloc::template rebind<__assoc_sub_state_alloc>::other __a(__alloc_);
|
2010-08-27 20:10:19 +00:00
|
|
|
this->~__assoc_sub_state_alloc();
|
|
|
|
__a.deallocate(this, 1);
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
2010-08-30 18:46:21 +00:00
|
|
|
class __deferred_assoc_state
|
2011-11-29 18:15:50 +00:00
|
|
|
: public __assoc_state<_Rp>
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef __assoc_state<_Rp> base;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
_Fp __func_;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit __deferred_assoc_state(_Fp&& __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual void __execute();
|
|
|
|
};
|
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
2010-08-30 18:46:21 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
__deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f)
|
|
|
|
: __func_(_VSTD::forward<_Fp>(__f))
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
this->__set_deferred();
|
|
|
|
}
|
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
2010-08-30 18:46:21 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__deferred_assoc_state<_Rp, _Fp>::__execute()
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
this->set_value(__func_());
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
this->set_exception(current_exception());
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp>
|
|
|
|
class __deferred_assoc_state<void, _Fp>
|
2010-08-30 18:46:21 +00:00
|
|
|
: public __assoc_sub_state
|
|
|
|
{
|
|
|
|
typedef __assoc_sub_state base;
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
_Fp __func_;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit __deferred_assoc_state(_Fp&& __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual void __execute();
|
|
|
|
};
|
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp>
|
2010-08-30 18:46:21 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
__deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f)
|
|
|
|
: __func_(_VSTD::forward<_Fp>(__f))
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
this->__set_deferred();
|
|
|
|
}
|
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp>
|
2010-08-30 18:46:21 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__deferred_assoc_state<void, _Fp>::__execute()
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
__func_();
|
|
|
|
this->set_value();
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
this->set_exception(current_exception());
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
2011-05-19 15:05:04 +00:00
|
|
|
class __async_assoc_state
|
2011-11-29 18:15:50 +00:00
|
|
|
: public __assoc_state<_Rp>
|
2011-05-19 15:05:04 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef __assoc_state<_Rp> base;
|
2011-05-19 15:05:04 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
_Fp __func_;
|
2011-05-19 15:05:04 +00:00
|
|
|
|
2011-05-28 14:41:13 +00:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
2011-05-19 15:05:04 +00:00
|
|
|
public:
|
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit __async_assoc_state(_Fp&& __f);
|
2011-05-19 15:05:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual void __execute();
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
2011-05-19 15:05:04 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
__async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f)
|
|
|
|
: __func_(_VSTD::forward<_Fp>(__f))
|
2011-05-19 15:05:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
2011-05-19 15:05:04 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__async_assoc_state<_Rp, _Fp>::__execute()
|
2011-05-19 15:05:04 +00:00
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
this->set_value(__func_());
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
this->set_exception(current_exception());
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
2011-05-19 15:05:04 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT
|
2011-05-19 15:05:04 +00:00
|
|
|
{
|
|
|
|
this->wait();
|
|
|
|
base::__on_zero_shared();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp>
|
|
|
|
class __async_assoc_state<void, _Fp>
|
2011-05-19 15:05:04 +00:00
|
|
|
: public __assoc_sub_state
|
|
|
|
{
|
|
|
|
typedef __assoc_sub_state base;
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
_Fp __func_;
|
2011-05-19 15:05:04 +00:00
|
|
|
|
2011-05-28 14:41:13 +00:00
|
|
|
virtual void __on_zero_shared() _NOEXCEPT;
|
2011-05-19 15:05:04 +00:00
|
|
|
public:
|
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit __async_assoc_state(_Fp&& __f);
|
2011-05-19 15:05:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual void __execute();
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp>
|
2011-05-19 15:05:04 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
__async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f)
|
|
|
|
: __func_(_VSTD::forward<_Fp>(__f))
|
2011-05-19 15:05:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp>
|
2011-05-19 15:05:04 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__async_assoc_state<void, _Fp>::__execute()
|
2011-05-19 15:05:04 +00:00
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
__func_();
|
|
|
|
this->set_value();
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
this->set_exception(current_exception());
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp>
|
2011-05-19 15:05:04 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT
|
2011-05-19 15:05:04 +00:00
|
|
|
{
|
|
|
|
this->wait();
|
|
|
|
base::__on_zero_shared();
|
|
|
|
}
|
|
|
|
|
2012-09-14 00:39:16 +00:00
|
|
|
template <class _Rp> class _LIBCPP_VISIBLE promise;
|
|
|
|
template <class _Rp> class _LIBCPP_VISIBLE shared_future;
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// future
|
|
|
|
|
2012-09-14 00:39:16 +00:00
|
|
|
template <class _Rp> class _LIBCPP_VISIBLE future;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
|
|
|
future<_Rp>
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
__make_deferred_assoc_state(_Fp&& __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#else
|
2011-11-29 18:15:50 +00:00
|
|
|
__make_deferred_assoc_state(_Fp __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
|
|
|
future<_Rp>
|
2011-05-19 15:05:04 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
__make_async_assoc_state(_Fp&& __f);
|
2011-05-19 15:05:04 +00:00
|
|
|
#else
|
2011-11-29 18:15:50 +00:00
|
|
|
__make_async_assoc_state(_Fp __f);
|
2011-05-19 15:05:04 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-09-22 14:16:26 +00:00
|
|
|
class _LIBCPP_VISIBLE future
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp>* __state_;
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit future(__assoc_state<_Rp>* __state);
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
template <class> friend class promise;
|
2010-09-03 18:39:25 +00:00
|
|
|
template <class> friend class shared_future;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
|
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_async_assoc_state(_Fp&& __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#else
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_deferred_assoc_state(_Fp __f);
|
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_async_assoc_state(_Fp __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
future() _NOEXCEPT : __state_(nullptr) {}
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
future(future&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
|
|
|
|
future(const future&) = delete;
|
|
|
|
future& operator=(const future&) = delete;
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
future& operator=(future&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
future(std::move(__rhs)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2010-09-04 23:28:19 +00:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
private:
|
|
|
|
future(const future&);
|
|
|
|
future& operator=(const future&);
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
~future();
|
2011-11-29 18:15:50 +00:00
|
|
|
shared_future<_Rp> share();
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
2011-11-29 18:15:50 +00:00
|
|
|
_Rp get();
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// functions to check state
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
void wait() const {__state_->wait();}
|
|
|
|
template <class _Rep, class _Period>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
|
|
|
|
{return __state_->wait_for(__rel_time);}
|
|
|
|
template <class _Clock, class _Duration>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
|
|
|
|
{return __state_->wait_until(__abs_time);}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
future<_Rp>::future(__assoc_state<_Rp>* __state)
|
2010-08-27 20:10:19 +00:00
|
|
|
: __state_(__state)
|
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_->__has_future_attached())
|
|
|
|
throw future_error(make_error_code(future_errc::future_already_retrieved));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->__add_shared();
|
2010-08-30 18:46:21 +00:00
|
|
|
__state_->__set_future_attached();
|
2010-08-27 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-30 18:46:21 +00:00
|
|
|
struct __release_shared_count
|
|
|
|
{
|
|
|
|
void operator()(__shared_count* p) {p->__release_shared();}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
future<_Rp>::~future()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
if (__state_)
|
|
|
|
__state_->__release_shared();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
_Rp
|
|
|
|
future<_Rp>::get()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2010-08-30 18:46:21 +00:00
|
|
|
unique_ptr<__shared_count, __release_shared_count> __(__state_);
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp>* __s = __state_;
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_ = nullptr;
|
|
|
|
return __s->move();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
class _LIBCPP_VISIBLE future<_Rp&>
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp&>* __state_;
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit future(__assoc_state<_Rp&>* __state);
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
template <class> friend class promise;
|
2010-09-03 18:39:25 +00:00
|
|
|
template <class> friend class shared_future;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
|
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_async_assoc_state(_Fp&& __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#else
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_deferred_assoc_state(_Fp __f);
|
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_async_assoc_state(_Fp __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
future() _NOEXCEPT : __state_(nullptr) {}
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
future(future&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
|
|
|
|
future(const future&) = delete;
|
|
|
|
future& operator=(const future&) = delete;
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
future& operator=(future&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
future(std::move(__rhs)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2010-09-04 23:28:19 +00:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
private:
|
|
|
|
future(const future&);
|
|
|
|
future& operator=(const future&);
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
~future();
|
2011-11-29 18:15:50 +00:00
|
|
|
shared_future<_Rp&> share();
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
2011-11-29 18:15:50 +00:00
|
|
|
_Rp& get();
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// functions to check state
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
void wait() const {__state_->wait();}
|
|
|
|
template <class _Rep, class _Period>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
|
|
|
|
{return __state_->wait_for(__rel_time);}
|
|
|
|
template <class _Clock, class _Duration>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
|
|
|
|
{return __state_->wait_until(__abs_time);}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
future<_Rp&>::future(__assoc_state<_Rp&>* __state)
|
2010-08-27 20:10:19 +00:00
|
|
|
: __state_(__state)
|
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_->__has_future_attached())
|
|
|
|
throw future_error(make_error_code(future_errc::future_already_retrieved));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->__add_shared();
|
2010-08-30 18:46:21 +00:00
|
|
|
__state_->__set_future_attached();
|
2010-08-27 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
future<_Rp&>::~future()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
if (__state_)
|
|
|
|
__state_->__release_shared();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
_Rp&
|
|
|
|
future<_Rp&>::get()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2010-08-30 18:46:21 +00:00
|
|
|
unique_ptr<__shared_count, __release_shared_count> __(__state_);
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp&>* __s = __state_;
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_ = nullptr;
|
|
|
|
return __s->copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2010-09-22 14:16:26 +00:00
|
|
|
class _LIBCPP_VISIBLE future<void>
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
__assoc_sub_state* __state_;
|
|
|
|
|
|
|
|
explicit future(__assoc_sub_state* __state);
|
|
|
|
|
|
|
|
template <class> friend class promise;
|
2010-09-03 18:39:25 +00:00
|
|
|
template <class> friend class shared_future;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
|
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_async_assoc_state(_Fp&& __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#else
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_deferred_assoc_state(_Fp __f);
|
|
|
|
template <class _R1, class _Fp>
|
|
|
|
friend future<_R1> __make_async_assoc_state(_Fp __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
future() _NOEXCEPT : __state_(nullptr) {}
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
future(future&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
|
|
|
|
future(const future&) = delete;
|
|
|
|
future& operator=(const future&) = delete;
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
future& operator=(future&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
future(std::move(__rhs)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2010-09-04 23:28:19 +00:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
private:
|
|
|
|
future(const future&);
|
|
|
|
future& operator=(const future&);
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
~future();
|
2010-11-30 20:23:32 +00:00
|
|
|
shared_future<void> share();
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
|
|
|
void get();
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// functions to check state
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
void wait() const {__state_->wait();}
|
|
|
|
template <class _Rep, class _Period>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
|
|
|
|
{return __state_->wait_for(__rel_time);}
|
|
|
|
template <class _Clock, class _Duration>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-27 20:10:19 +00:00
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
|
|
|
|
{return __state_->wait_until(__abs_time);}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-09-03 18:39:25 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
2012-07-21 17:46:55 +00:00
|
|
|
swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
2010-08-27 20:10:19 +00:00
|
|
|
// promise<R>
|
|
|
|
|
2011-06-14 19:58:17 +00:00
|
|
|
template <class _Callable> class packaged_task;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-09-22 14:16:26 +00:00
|
|
|
class _LIBCPP_VISIBLE promise
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp>* __state_;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
template <class> friend class packaged_task;
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
|
|
|
promise();
|
|
|
|
template <class _Alloc>
|
|
|
|
promise(allocator_arg_t, const _Alloc& __a);
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
promise(promise&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
|
|
|
|
promise(const promise& __rhs) = delete;
|
2010-09-04 23:28:19 +00:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
private:
|
|
|
|
promise(const promise& __rhs);
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
~promise();
|
|
|
|
|
|
|
|
// assignment
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
promise& operator=(promise&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
promise(std::move(__rhs)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
promise& operator=(const promise& __rhs) = delete;
|
2010-09-04 23:28:19 +00:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
private:
|
|
|
|
promise& operator=(const promise& __rhs);
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// retrieving the result
|
2011-11-29 18:15:50 +00:00
|
|
|
future<_Rp> get_future();
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// setting the result
|
2011-11-29 18:15:50 +00:00
|
|
|
void set_value(const _Rp& __r);
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
void set_value(_Rp&& __r);
|
2010-08-27 20:10:19 +00:00
|
|
|
#endif
|
|
|
|
void set_exception(exception_ptr __p);
|
|
|
|
|
|
|
|
// setting the result with deferred notification
|
2011-11-29 18:15:50 +00:00
|
|
|
void set_value_at_thread_exit(const _Rp& __r);
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
void set_value_at_thread_exit(_Rp&& __r);
|
2010-08-27 20:10:19 +00:00
|
|
|
#endif
|
|
|
|
void set_exception_at_thread_exit(exception_ptr __p);
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
promise<_Rp>::promise()
|
|
|
|
: __state_(new __assoc_state<_Rp>)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
template <class _Alloc>
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef typename _Alloc::template rebind<__assoc_state_alloc<_Rp, _Alloc> >::other _A2;
|
2010-08-27 20:10:19 +00:00
|
|
|
typedef __allocator_destructor<_A2> _D2;
|
|
|
|
_A2 __a(__a0);
|
2011-11-29 18:15:50 +00:00
|
|
|
unique_ptr<__assoc_state_alloc<_Rp, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1));
|
|
|
|
::new(__hold.get()) __assoc_state_alloc<_Rp, _Alloc>(__a0);
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_ = __hold.release();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
promise<_Rp>::~promise()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
if (__state_)
|
|
|
|
{
|
|
|
|
if (!__state_->__has_value() && __state_->use_count() > 1)
|
|
|
|
__state_->set_exception(make_exception_ptr(
|
|
|
|
future_error(make_error_code(future_errc::broken_promise))
|
|
|
|
));
|
|
|
|
__state_->__release_shared();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
future<_Rp>
|
|
|
|
promise<_Rp>::get_future()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2011-11-29 18:15:50 +00:00
|
|
|
return future<_Rp>(__state_);
|
2010-08-27 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp>::set_value(const _Rp& __r)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->set_value(__r);
|
|
|
|
}
|
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp>::set_value(_Rp&& __r)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2011-06-30 21:18:19 +00:00
|
|
|
__state_->set_value(_VSTD::move(__r));
|
2010-08-27 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp>::set_exception(exception_ptr __p)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->set_exception(__p);
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp>::set_value_at_thread_exit(const _Rp& __r)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->set_value_at_thread_exit(__r);
|
|
|
|
}
|
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp>::set_value_at_thread_exit(_Rp&& __r)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2011-06-30 21:18:19 +00:00
|
|
|
__state_->set_value_at_thread_exit(_VSTD::move(__r));
|
2010-08-27 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->set_exception_at_thread_exit(__p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// promise<R&>
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
class _LIBCPP_VISIBLE promise<_Rp&>
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp&>* __state_;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
template <class> friend class packaged_task;
|
|
|
|
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
|
|
|
promise();
|
|
|
|
template <class _Allocator>
|
|
|
|
promise(allocator_arg_t, const _Allocator& __a);
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
promise(promise&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
|
|
|
|
promise(const promise& __rhs) = delete;
|
2010-09-04 23:28:19 +00:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
private:
|
|
|
|
promise(const promise& __rhs);
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
~promise();
|
|
|
|
|
|
|
|
// assignment
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
promise& operator=(promise&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
promise(std::move(__rhs)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
promise& operator=(const promise& __rhs) = delete;
|
2010-09-04 23:28:19 +00:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
private:
|
|
|
|
promise& operator=(const promise& __rhs);
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// retrieving the result
|
2011-11-29 18:15:50 +00:00
|
|
|
future<_Rp&> get_future();
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// setting the result
|
2011-11-29 18:15:50 +00:00
|
|
|
void set_value(_Rp& __r);
|
2010-08-27 20:10:19 +00:00
|
|
|
void set_exception(exception_ptr __p);
|
|
|
|
|
|
|
|
// setting the result with deferred notification
|
2011-11-29 18:15:50 +00:00
|
|
|
void set_value_at_thread_exit(_Rp&);
|
2010-08-27 20:10:19 +00:00
|
|
|
void set_exception_at_thread_exit(exception_ptr __p);
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
promise<_Rp&>::promise()
|
|
|
|
: __state_(new __assoc_state<_Rp&>)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
template <class _Alloc>
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef typename _Alloc::template rebind<__assoc_state_alloc<_Rp&, _Alloc> >::other _A2;
|
2010-08-27 20:10:19 +00:00
|
|
|
typedef __allocator_destructor<_A2> _D2;
|
|
|
|
_A2 __a(__a0);
|
2011-11-29 18:15:50 +00:00
|
|
|
unique_ptr<__assoc_state_alloc<_Rp&, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1));
|
|
|
|
::new(__hold.get()) __assoc_state_alloc<_Rp&, _Alloc>(__a0);
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_ = __hold.release();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
promise<_Rp&>::~promise()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
if (__state_)
|
|
|
|
{
|
|
|
|
if (!__state_->__has_value() && __state_->use_count() > 1)
|
|
|
|
__state_->set_exception(make_exception_ptr(
|
|
|
|
future_error(make_error_code(future_errc::broken_promise))
|
|
|
|
));
|
|
|
|
__state_->__release_shared();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
future<_Rp&>
|
|
|
|
promise<_Rp&>::get_future()
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2011-11-29 18:15:50 +00:00
|
|
|
return future<_Rp&>(__state_);
|
2010-08-27 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp&>::set_value(_Rp& __r)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->set_value(__r);
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp&>::set_exception(exception_ptr __p)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->set_exception(__p);
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp&>::set_value_at_thread_exit(_Rp& __r)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->set_value_at_thread_exit(__r);
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p)
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
2011-07-13 16:00:50 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-08-27 20:10:19 +00:00
|
|
|
if (__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
2011-07-13 16:00:50 +00:00
|
|
|
#endif
|
2010-08-27 20:10:19 +00:00
|
|
|
__state_->set_exception_at_thread_exit(__p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// promise<void>
|
|
|
|
|
|
|
|
template <>
|
2010-09-22 14:16:26 +00:00
|
|
|
class _LIBCPP_VISIBLE promise<void>
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
__assoc_sub_state* __state_;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
template <class> friend class packaged_task;
|
|
|
|
|
2010-08-27 20:10:19 +00:00
|
|
|
public:
|
|
|
|
promise();
|
|
|
|
template <class _Allocator>
|
|
|
|
promise(allocator_arg_t, const _Allocator& __a);
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
promise(promise&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
|
|
|
|
promise(const promise& __rhs) = delete;
|
2010-09-04 23:28:19 +00:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
private:
|
|
|
|
promise(const promise& __rhs);
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
~promise();
|
|
|
|
|
|
|
|
// assignment
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
promise& operator=(promise&& __rhs) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
promise(std::move(__rhs)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
promise& operator=(const promise& __rhs) = delete;
|
2010-09-04 23:28:19 +00:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-08-27 20:10:19 +00:00
|
|
|
private:
|
|
|
|
promise& operator=(const promise& __rhs);
|
|
|
|
public:
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
|
2010-08-27 20:10:19 +00:00
|
|
|
|
|
|
|
// retrieving the result
|
|
|
|
future<void> get_future();
|
|
|
|
|
|
|
|
// setting the result
|
|
|
|
void set_value();
|
|
|
|
void set_exception(exception_ptr __p);
|
|
|
|
|
|
|
|
// setting the result with deferred notification
|
|
|
|
void set_value_at_thread_exit();
|
|
|
|
void set_exception_at_thread_exit(exception_ptr __p);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
promise<void>::promise(allocator_arg_t, const _Alloc& __a0)
|
|
|
|
{
|
|
|
|
typedef typename _Alloc::template rebind<__assoc_sub_state_alloc<_Alloc> >::other _A2;
|
|
|
|
typedef __allocator_destructor<_A2> _D2;
|
|
|
|
_A2 __a(__a0);
|
|
|
|
unique_ptr<__assoc_sub_state_alloc<_Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1));
|
|
|
|
::new(__hold.get()) __assoc_sub_state_alloc<_Alloc>(__a0);
|
|
|
|
__state_ = __hold.release();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-08-27 20:10:19 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
2012-07-21 17:46:55 +00:00
|
|
|
swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT
|
2010-08-27 20:10:19 +00:00
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Alloc>
|
|
|
|
struct _LIBCPP_VISIBLE uses_allocator<promise<_Rp>, _Alloc>
|
2010-09-22 14:16:26 +00:00
|
|
|
: public true_type {};
|
2010-08-27 20:10:19 +00:00
|
|
|
|
2010-08-30 18:46:21 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
|
|
|
|
// packaged_task
|
|
|
|
|
|
|
|
template<class _Fp> class __packaged_task_base;
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
|
|
|
class __packaged_task_base<_Rp(_ArgTypes...)>
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
__packaged_task_base(const __packaged_task_base&);
|
|
|
|
__packaged_task_base& operator=(const __packaged_task_base&);
|
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-30 18:46:21 +00:00
|
|
|
__packaged_task_base() {}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-30 18:46:21 +00:00
|
|
|
virtual ~__packaged_task_base() {}
|
2012-07-21 17:46:55 +00:00
|
|
|
virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0;
|
2010-08-30 18:46:21 +00:00
|
|
|
virtual void destroy() = 0;
|
|
|
|
virtual void destroy_deallocate() = 0;
|
2011-11-29 18:15:50 +00:00
|
|
|
virtual _Rp operator()(_ArgTypes&& ...) = 0;
|
2010-08-30 18:46:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class _FD, class _Alloc, class _FB> class __packaged_task_func;
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
|
|
|
|
class __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>
|
|
|
|
: public __packaged_task_base<_Rp(_ArgTypes...)>
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
__compressed_pair<_Fp, _Alloc> __f_;
|
2010-08-30 18:46:21 +00:00
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit __packaged_task_func(const _Fp& __f) : __f_(__f) {}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f)) {}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
__packaged_task_func(const _Fp& __f, const _Alloc& __a)
|
2010-08-30 18:46:21 +00:00
|
|
|
: __f_(__f, __a) {}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
__packaged_task_func(_Fp&& __f, const _Alloc& __a)
|
2011-06-30 21:18:19 +00:00
|
|
|
: __f_(_VSTD::move(__f), __a) {}
|
2012-07-21 17:46:55 +00:00
|
|
|
virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT;
|
2010-08-30 18:46:21 +00:00
|
|
|
virtual void destroy();
|
|
|
|
virtual void destroy_deallocate();
|
2011-11-29 18:15:50 +00:00
|
|
|
virtual _Rp operator()(_ArgTypes&& ... __args);
|
2010-08-30 18:46:21 +00:00
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
|
2010-08-30 18:46:21 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to(
|
2012-07-21 17:46:55 +00:00
|
|
|
__packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second()));
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
|
2010-08-30 18:46:21 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy()
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
__f_.~__compressed_pair<_Fp, _Alloc>();
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
|
2010-08-30 18:46:21 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate()
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef typename _Alloc::template rebind<__packaged_task_func>::other _Ap;
|
|
|
|
_Ap __a(__f_.second());
|
|
|
|
__f_.~__compressed_pair<_Fp, _Alloc>();
|
2010-08-30 18:46:21 +00:00
|
|
|
__a.deallocate(this, 1);
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
|
|
|
|
_Rp
|
|
|
|
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-06-14 19:58:17 +00:00
|
|
|
template <class _Callable> class __packaged_task_function;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
|
|
|
class __packaged_task_function<_Rp(_ArgTypes...)>
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef __packaged_task_base<_Rp(_ArgTypes...)> __base;
|
2010-08-30 18:46:21 +00:00
|
|
|
aligned_storage<3*sizeof(void*)>::type __buf_;
|
|
|
|
__base* __f_;
|
|
|
|
|
|
|
|
public:
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef _Rp result_type;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
// construct/copy/destroy:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
__packaged_task_function() _NOEXCEPT : __f_(nullptr) {}
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Fp>
|
|
|
|
__packaged_task_function(_Fp&& __f);
|
|
|
|
template<class _Fp, class _Alloc>
|
|
|
|
__packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f);
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2012-07-21 17:46:55 +00:00
|
|
|
__packaged_task_function(__packaged_task_function&&) _NOEXCEPT;
|
|
|
|
__packaged_task_function& operator=(__packaged_task_function&&) _NOEXCEPT;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
__packaged_task_function(const __packaged_task_function&) = delete;
|
|
|
|
__packaged_task_function& operator=(const __packaged_task_function&) = delete;
|
|
|
|
|
|
|
|
~__packaged_task_function();
|
|
|
|
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(__packaged_task_function&) _NOEXCEPT;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
_Rp operator()(_ArgTypes...) const;
|
2010-08-30 18:46:21 +00:00
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
2012-07-21 17:46:55 +00:00
|
|
|
__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) _NOEXCEPT
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
if (__f.__f_ == nullptr)
|
|
|
|
__f_ = nullptr;
|
|
|
|
else if (__f.__f_ == (__base*)&__f.__buf_)
|
|
|
|
{
|
|
|
|
__f_ = (__base*)&__buf_;
|
|
|
|
__f.__f_->__move_to(__f_);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__f_ = __f.__f_;
|
|
|
|
__f.__f_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
|
|
|
template <class _Fp>
|
|
|
|
__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f)
|
2010-08-30 18:46:21 +00:00
|
|
|
: __f_(nullptr)
|
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef typename remove_reference<_Fp>::type _FR;
|
|
|
|
typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF;
|
2010-08-30 18:46:21 +00:00
|
|
|
if (sizeof(_FF) <= sizeof(__buf_))
|
|
|
|
{
|
|
|
|
__f_ = (__base*)&__buf_;
|
2011-11-29 18:15:50 +00:00
|
|
|
::new (__f_) _FF(_VSTD::forward<_Fp>(__f));
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef allocator<_FF> _Ap;
|
|
|
|
_Ap __a;
|
|
|
|
typedef __allocator_destructor<_Ap> _Dp;
|
|
|
|
unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
|
|
|
|
::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a));
|
2010-08-30 18:46:21 +00:00
|
|
|
__f_ = __hold.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
|
|
|
template <class _Fp, class _Alloc>
|
|
|
|
__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(
|
|
|
|
allocator_arg_t, const _Alloc& __a0, _Fp&& __f)
|
2010-08-30 18:46:21 +00:00
|
|
|
: __f_(nullptr)
|
|
|
|
{
|
|
|
|
typedef allocator_traits<_Alloc> __alloc_traits;
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef typename remove_reference<_Fp>::type _FR;
|
|
|
|
typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF;
|
2010-08-30 18:46:21 +00:00
|
|
|
if (sizeof(_FF) <= sizeof(__buf_))
|
|
|
|
{
|
|
|
|
__f_ = (__base*)&__buf_;
|
2011-11-29 18:15:50 +00:00
|
|
|
::new (__f_) _FF(_VSTD::forward<_Fp>(__f));
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
typedef typename __alloc_traits::template
|
|
|
|
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
|
|
|
|
rebind_alloc<_FF>
|
|
|
|
#else
|
|
|
|
rebind_alloc<_FF>::other
|
|
|
|
#endif
|
2011-11-29 18:15:50 +00:00
|
|
|
_Ap;
|
|
|
|
_Ap __a(__a0);
|
|
|
|
typedef __allocator_destructor<_Ap> _Dp;
|
|
|
|
unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
|
|
|
|
::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a));
|
2010-08-30 18:46:21 +00:00
|
|
|
__f_ = __hold.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
|
|
|
__packaged_task_function<_Rp(_ArgTypes...)>&
|
2012-07-21 17:46:55 +00:00
|
|
|
__packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f) _NOEXCEPT
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
if (__f_ == (__base*)&__buf_)
|
|
|
|
__f_->destroy();
|
|
|
|
else if (__f_)
|
|
|
|
__f_->destroy_deallocate();
|
|
|
|
__f_ = nullptr;
|
|
|
|
if (__f.__f_ == nullptr)
|
|
|
|
__f_ = nullptr;
|
|
|
|
else if (__f.__f_ == (__base*)&__f.__buf_)
|
|
|
|
{
|
|
|
|
__f_ = (__base*)&__buf_;
|
|
|
|
__f.__f_->__move_to(__f_);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__f_ = __f.__f_;
|
|
|
|
__f.__f_ = nullptr;
|
|
|
|
}
|
2012-10-13 02:03:45 +00:00
|
|
|
return *this;
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
|
|
|
__packaged_task_function<_Rp(_ArgTypes...)>::~__packaged_task_function()
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
if (__f_ == (__base*)&__buf_)
|
|
|
|
__f_->destroy();
|
|
|
|
else if (__f_)
|
|
|
|
__f_->destroy_deallocate();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
2010-08-30 18:46:21 +00:00
|
|
|
void
|
2012-07-21 17:46:55 +00:00
|
|
|
__packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f) _NOEXCEPT
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
|
|
|
|
{
|
|
|
|
typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
|
|
|
|
__base* __t = (__base*)&__tempbuf;
|
|
|
|
__f_->__move_to(__t);
|
|
|
|
__f_->destroy();
|
|
|
|
__f_ = nullptr;
|
|
|
|
__f.__f_->__move_to((__base*)&__buf_);
|
|
|
|
__f.__f_->destroy();
|
|
|
|
__f.__f_ = nullptr;
|
|
|
|
__f_ = (__base*)&__buf_;
|
|
|
|
__t->__move_to((__base*)&__f.__buf_);
|
|
|
|
__t->destroy();
|
|
|
|
__f.__f_ = (__base*)&__f.__buf_;
|
|
|
|
}
|
|
|
|
else if (__f_ == (__base*)&__buf_)
|
|
|
|
{
|
|
|
|
__f_->__move_to((__base*)&__f.__buf_);
|
|
|
|
__f_->destroy();
|
|
|
|
__f_ = __f.__f_;
|
|
|
|
__f.__f_ = (__base*)&__f.__buf_;
|
|
|
|
}
|
|
|
|
else if (__f.__f_ == (__base*)&__f.__buf_)
|
|
|
|
{
|
|
|
|
__f.__f_->__move_to((__base*)&__buf_);
|
|
|
|
__f.__f_->destroy();
|
|
|
|
__f.__f_ = __f_;
|
|
|
|
__f_ = (__base*)&__buf_;
|
|
|
|
}
|
|
|
|
else
|
2011-06-30 21:18:19 +00:00
|
|
|
_VSTD::swap(__f_, __f.__f_);
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
2010-08-30 18:46:21 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
_Rp
|
|
|
|
__packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
|
|
|
class _LIBCPP_VISIBLE packaged_task<_Rp(_ArgTypes...)>
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef _Rp result_type;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
__packaged_task_function<result_type(_ArgTypes...)> __f_;
|
|
|
|
promise<result_type> __p_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// construction and destruction
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
packaged_task() _NOEXCEPT : __p_(nullptr) {}
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
|
|
|
|
template <class _Fp, class _Allocator>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
|
|
|
|
: __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
|
2010-08-30 18:46:21 +00:00
|
|
|
__p_(allocator_arg, __a) {}
|
|
|
|
// ~packaged_task() = default;
|
|
|
|
|
|
|
|
// no copy
|
2012-07-21 19:34:12 +00:00
|
|
|
packaged_task(const packaged_task&) = delete;
|
|
|
|
packaged_task& operator=(const packaged_task&) = delete;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
// move support
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
packaged_task(packaged_task&& __other) _NOEXCEPT
|
2011-06-30 21:18:19 +00:00
|
|
|
: __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
__f_ = _VSTD::move(__other.__f_);
|
|
|
|
__p_ = _VSTD::move(__other.__p_);
|
2010-08-30 18:46:21 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(packaged_task& __other) _NOEXCEPT
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
__f_.swap(__other.__f_);
|
|
|
|
__p_.swap(__other.__p_);
|
|
|
|
}
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
// result retrieval
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-30 18:46:21 +00:00
|
|
|
future<result_type> get_future() {return __p_.get_future();}
|
|
|
|
|
|
|
|
// execution
|
|
|
|
void operator()(_ArgTypes... __args);
|
|
|
|
void make_ready_at_thread_exit(_ArgTypes... __args);
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
2010-08-30 18:46:21 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args)
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
if (__p_.__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
|
|
|
if (__p_.__state_->__has_value())
|
|
|
|
throw future_error(make_error_code(future_errc::promise_already_satisfied));
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2011-06-30 21:18:19 +00:00
|
|
|
__p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...));
|
2010-08-30 18:46:21 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
__p_.set_exception(current_exception());
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
2010-08-30 18:46:21 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
if (__p_.__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
|
|
|
if (__p_.__state_->__has_value())
|
|
|
|
throw future_error(make_error_code(future_errc::promise_already_satisfied));
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2011-06-30 21:18:19 +00:00
|
|
|
__p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...));
|
2010-08-30 18:46:21 +00:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
__p_.set_exception_at_thread_exit(current_exception());
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template<class _Rp, class ..._ArgTypes>
|
2010-08-30 18:46:21 +00:00
|
|
|
void
|
2011-11-29 18:15:50 +00:00
|
|
|
packaged_task<_Rp(_ArgTypes...)>::reset()
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-11-30 20:23:32 +00:00
|
|
|
if (!valid())
|
2010-08-30 18:46:21 +00:00
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
__p_ = promise<result_type>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class ..._ArgTypes>
|
2010-09-22 14:16:26 +00:00
|
|
|
class _LIBCPP_VISIBLE packaged_task<void(_ArgTypes...)>
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef void result_type;
|
|
|
|
|
|
|
|
private:
|
|
|
|
__packaged_task_function<result_type(_ArgTypes...)> __f_;
|
|
|
|
promise<result_type> __p_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// construction and destruction
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
packaged_task() _NOEXCEPT : __p_(nullptr) {}
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
|
|
|
|
template <class _Fp, class _Allocator>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
|
|
|
|
: __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
|
2010-08-30 18:46:21 +00:00
|
|
|
__p_(allocator_arg, __a) {}
|
|
|
|
// ~packaged_task() = default;
|
|
|
|
|
|
|
|
// no copy
|
2012-07-21 19:34:12 +00:00
|
|
|
packaged_task(const packaged_task&) = delete;
|
|
|
|
packaged_task& operator=(const packaged_task&) = delete;
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
// move support
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
packaged_task(packaged_task&& __other) _NOEXCEPT
|
2011-06-30 21:18:19 +00:00
|
|
|
: __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
__f_ = _VSTD::move(__other.__f_);
|
|
|
|
__p_ = _VSTD::move(__other.__p_);
|
2010-08-30 18:46:21 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(packaged_task& __other) _NOEXCEPT
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
__f_.swap(__other.__f_);
|
|
|
|
__p_.swap(__other.__p_);
|
|
|
|
}
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
|
2010-08-30 18:46:21 +00:00
|
|
|
|
|
|
|
// result retrieval
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-30 18:46:21 +00:00
|
|
|
future<result_type> get_future() {return __p_.get_future();}
|
|
|
|
|
|
|
|
// execution
|
|
|
|
void operator()(_ArgTypes... __args);
|
|
|
|
void make_ready_at_thread_exit(_ArgTypes... __args);
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class ..._ArgTypes>
|
|
|
|
void
|
|
|
|
packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args)
|
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
if (__p_.__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
|
|
|
if (__p_.__state_->__has_value())
|
|
|
|
throw future_error(make_error_code(future_errc::promise_already_satisfied));
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2011-06-30 21:18:19 +00:00
|
|
|
__f_(_VSTD::forward<_ArgTypes>(__args)...);
|
2010-08-30 18:46:21 +00:00
|
|
|
__p_.set_value();
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
__p_.set_exception(current_exception());
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class ..._ArgTypes>
|
|
|
|
void
|
|
|
|
packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
|
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
if (__p_.__state_ == nullptr)
|
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
|
|
|
if (__p_.__state_->__has_value())
|
|
|
|
throw future_error(make_error_code(future_errc::promise_already_satisfied));
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2011-06-30 21:18:19 +00:00
|
|
|
__f_(_VSTD::forward<_ArgTypes>(__args)...);
|
2010-08-30 18:46:21 +00:00
|
|
|
__p_.set_value_at_thread_exit();
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
__p_.set_exception_at_thread_exit(current_exception());
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class ..._ArgTypes>
|
|
|
|
void
|
|
|
|
packaged_task<void(_ArgTypes...)>::reset()
|
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-11-30 20:23:32 +00:00
|
|
|
if (!valid())
|
2010-08-30 18:46:21 +00:00
|
|
|
throw future_error(make_error_code(future_errc::no_state));
|
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
|
|
|
__p_ = promise<result_type>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Callable>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
2012-07-21 17:46:55 +00:00
|
|
|
swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Callable, class _Alloc>
|
2010-09-22 14:16:26 +00:00
|
|
|
struct _LIBCPP_VISIBLE uses_allocator<packaged_task<_Callable>, _Alloc>
|
|
|
|
: public true_type {};
|
2010-08-30 18:46:21 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
|
|
|
future<_Rp>
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
__make_deferred_assoc_state(_Fp&& __f)
|
2010-08-30 18:46:21 +00:00
|
|
|
#else
|
2011-11-29 18:15:50 +00:00
|
|
|
__make_deferred_assoc_state(_Fp __f)
|
2010-08-30 18:46:21 +00:00
|
|
|
#endif
|
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
unique_ptr<__deferred_assoc_state<_Rp, _Fp>, __release_shared_count>
|
|
|
|
__h(new __deferred_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
|
|
|
|
return future<_Rp>(__h.get());
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp, class _Fp>
|
|
|
|
future<_Rp>
|
2011-05-19 15:05:04 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-11-29 18:15:50 +00:00
|
|
|
__make_async_assoc_state(_Fp&& __f)
|
2011-05-19 15:05:04 +00:00
|
|
|
#else
|
2011-11-29 18:15:50 +00:00
|
|
|
__make_async_assoc_state(_Fp __f)
|
2011-05-19 15:05:04 +00:00
|
|
|
#endif
|
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count>
|
|
|
|
__h(new __async_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
|
|
|
|
_VSTD::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
|
|
|
|
return future<_Rp>(__h.get());
|
2011-05-19 15:05:04 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp, class... _Args>
|
2011-05-19 15:05:04 +00:00
|
|
|
class __async_func
|
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
tuple<_Fp, _Args...> __f_;
|
2011-05-19 15:05:04 +00:00
|
|
|
|
|
|
|
public:
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef typename __invoke_of<_Fp, _Args...>::type _Rp;
|
2011-05-19 15:05:04 +00:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
explicit __async_func(_Fp&& __f, _Args&&... __args)
|
2011-06-30 21:18:19 +00:00
|
|
|
: __f_(_VSTD::move(__f), _VSTD::move(__args)...) {}
|
2011-05-19 15:05:04 +00:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-30 21:18:19 +00:00
|
|
|
__async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {}
|
2011-05-19 15:05:04 +00:00
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
_Rp operator()()
|
2011-05-19 15:05:04 +00:00
|
|
|
{
|
|
|
|
typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index;
|
|
|
|
return __execute(_Index());
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
template <size_t ..._Indices>
|
2011-11-29 18:15:50 +00:00
|
|
|
_Rp
|
2011-05-19 15:05:04 +00:00
|
|
|
__execute(__tuple_indices<_Indices...>)
|
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
return __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...);
|
2011-05-19 15:05:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp, class... _Args>
|
|
|
|
future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
|
|
|
|
async(launch __policy, _Fp&& __f, _Args&&... __args)
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
typedef __async_func<typename decay<_Fp>::type, typename decay<_Args>::type...> _BF;
|
|
|
|
typedef typename _BF::_Rp _Rp;
|
|
|
|
future<_Rp> __r;
|
2011-12-02 19:36:40 +00:00
|
|
|
if (int(__policy) & int(launch::async))
|
2011-11-29 18:15:50 +00:00
|
|
|
__r = _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)),
|
2011-06-30 21:18:19 +00:00
|
|
|
__decay_copy(_VSTD::forward<_Args>(__args))...));
|
2011-12-02 19:36:40 +00:00
|
|
|
else if (int(__policy) & int(launch::deferred))
|
2011-11-29 18:15:50 +00:00
|
|
|
__r = _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)),
|
2011-06-30 21:18:19 +00:00
|
|
|
__decay_copy(_VSTD::forward<_Args>(__args))...));
|
2010-08-30 18:46:21 +00:00
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Fp, class... _Args>
|
2010-08-30 18:46:21 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
|
|
|
|
async(_Fp&& __f, _Args&&... __args)
|
2010-08-30 18:46:21 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
return _VSTD::async(launch::any, _VSTD::forward<_Fp>(__f),
|
2011-06-30 21:18:19 +00:00
|
|
|
_VSTD::forward<_Args>(__args)...);
|
2010-08-30 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
|
2010-09-03 21:46:37 +00:00
|
|
|
// shared_future
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-09-22 14:16:26 +00:00
|
|
|
class _LIBCPP_VISIBLE shared_future
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp>* __state_;
|
2010-09-03 18:39:25 +00:00
|
|
|
|
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future() _NOEXCEPT : __state_(nullptr) {}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
|
|
|
|
{if (__state_) __state_->__add_shared();}
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future(future<_Rp>&& __f) _NOEXCEPT : __state_(__f.__state_)
|
2010-09-03 18:39:25 +00:00
|
|
|
{__f.__state_ = nullptr;}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
|
2010-09-03 18:39:25 +00:00
|
|
|
{__rhs.__state_ = nullptr;}
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-03 18:39:25 +00:00
|
|
|
~shared_future();
|
|
|
|
shared_future& operator=(const shared_future& __rhs);
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
shared_future(std::move(__rhs)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-03 18:39:25 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
const _Rp& get() const {return __state_->copy();}
|
2010-09-03 18:39:25 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
|
2010-09-03 18:39:25 +00:00
|
|
|
|
|
|
|
// functions to check state
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
|
2010-09-03 18:39:25 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
void wait() const {__state_->wait();}
|
|
|
|
template <class _Rep, class _Period>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
|
|
|
|
{return __state_->wait_for(__rel_time);}
|
|
|
|
template <class _Clock, class _Duration>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
|
|
|
|
{return __state_->wait_until(__abs_time);}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
shared_future<_Rp>::~shared_future()
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
if (__state_)
|
|
|
|
__state_->__release_shared();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
shared_future<_Rp>&
|
|
|
|
shared_future<_Rp>::operator=(const shared_future& __rhs)
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
if (__rhs.__state_)
|
|
|
|
__rhs.__state_->__add_shared();
|
|
|
|
if (__state_)
|
|
|
|
__state_->__release_shared();
|
|
|
|
__state_ = __rhs.__state_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
class _LIBCPP_VISIBLE shared_future<_Rp&>
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
__assoc_state<_Rp&>* __state_;
|
2010-09-03 18:39:25 +00:00
|
|
|
|
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future() _NOEXCEPT : __state_(nullptr) {}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
|
|
|
|
{if (__state_) __state_->__add_shared();}
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future(future<_Rp&>&& __f) _NOEXCEPT : __state_(__f.__state_)
|
2010-09-03 18:39:25 +00:00
|
|
|
{__f.__state_ = nullptr;}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
|
2010-09-03 18:39:25 +00:00
|
|
|
{__rhs.__state_ = nullptr;}
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-03 18:39:25 +00:00
|
|
|
~shared_future();
|
|
|
|
shared_future& operator=(const shared_future& __rhs);
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
shared_future(std::move(__rhs)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-03 18:39:25 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
_Rp& get() const {return __state_->copy();}
|
2010-09-03 18:39:25 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
|
2010-09-03 18:39:25 +00:00
|
|
|
|
|
|
|
// functions to check state
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
|
2010-09-03 18:39:25 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
void wait() const {__state_->wait();}
|
|
|
|
template <class _Rep, class _Period>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
|
|
|
|
{return __state_->wait_for(__rel_time);}
|
|
|
|
template <class _Clock, class _Duration>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
|
|
|
|
{return __state_->wait_until(__abs_time);}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
shared_future<_Rp&>::~shared_future()
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
if (__state_)
|
|
|
|
__state_->__release_shared();
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
|
|
|
shared_future<_Rp&>&
|
|
|
|
shared_future<_Rp&>::operator=(const shared_future& __rhs)
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
if (__rhs.__state_)
|
|
|
|
__rhs.__state_->__add_shared();
|
|
|
|
if (__state_)
|
|
|
|
__state_->__release_shared();
|
|
|
|
__state_ = __rhs.__state_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2010-09-22 14:16:26 +00:00
|
|
|
class _LIBCPP_VISIBLE shared_future<void>
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
__assoc_sub_state* __state_;
|
|
|
|
|
|
|
|
public:
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future() _NOEXCEPT : __state_(nullptr) {}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
|
|
|
|
{if (__state_) __state_->__add_shared();}
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future(future<void>&& __f) _NOEXCEPT : __state_(__f.__state_)
|
2010-09-03 18:39:25 +00:00
|
|
|
{__f.__state_ = nullptr;}
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
|
2010-09-03 18:39:25 +00:00
|
|
|
{__rhs.__state_ = nullptr;}
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-03 18:39:25 +00:00
|
|
|
~shared_future();
|
|
|
|
shared_future& operator=(const shared_future& __rhs);
|
2010-09-04 23:28:19 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
shared_future(std::move(__rhs)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2010-09-04 23:28:19 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-03 18:39:25 +00:00
|
|
|
|
|
|
|
// retrieving the value
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
void get() const {__state_->copy();}
|
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
|
2010-09-03 18:39:25 +00:00
|
|
|
|
|
|
|
// functions to check state
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-21 17:46:55 +00:00
|
|
|
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
|
2010-09-03 18:39:25 +00:00
|
|
|
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
void wait() const {__state_->wait();}
|
|
|
|
template <class _Rep, class _Period>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
future_status
|
|
|
|
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
|
|
|
|
{return __state_->wait_for(__rel_time);}
|
|
|
|
template <class _Clock, class _Duration>
|
2010-09-22 14:16:26 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-09-03 18:39:25 +00:00
|
|
|
future_status
|
|
|
|
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
|
|
|
|
{return __state_->wait_until(__abs_time);}
|
|
|
|
};
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-09-03 18:39:25 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
2012-07-21 17:46:55 +00:00
|
|
|
swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT
|
2010-09-03 18:39:25 +00:00
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-11-30 20:23:32 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
shared_future<_Rp>
|
|
|
|
future<_Rp>::share()
|
2010-09-03 21:46:37 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
return shared_future<_Rp>(_VSTD::move(*this));
|
2010-09-03 21:46:37 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
template <class _Rp>
|
2010-11-30 20:23:32 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2011-11-29 18:15:50 +00:00
|
|
|
shared_future<_Rp&>
|
|
|
|
future<_Rp&>::share()
|
2010-09-03 21:46:37 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
return shared_future<_Rp&>(_VSTD::move(*this));
|
2010-09-03 21:46:37 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 16:45:21 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2010-09-03 21:46:37 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-11-30 20:23:32 +00:00
|
|
|
shared_future<void>
|
|
|
|
future<void>::share()
|
2010-09-03 21:46:37 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
return shared_future<void>(_VSTD::move(*this));
|
2010-09-03 21:46:37 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 16:45:21 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP_FUTURE
|