[futures.atomic_future] and notify_all_at_thread_exit.  This completes the header <future> and all of Chapter 30 (for C++0x enabled compilers).

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@113017 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/condition_variable b/include/condition_variable
index 3e766b6..aacae0a 100644
--- a/include/condition_variable
+++ b/include/condition_variable
@@ -246,6 +246,8 @@
                       _STD::move(__pred));
 }
 
+void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_CONDITION_VARIABLE
diff --git a/include/future b/include/future
index 4189d88..a1f976f 100644
--- a/include/future
+++ b/include/future
@@ -439,7 +439,7 @@
 #include <memory>
 #include <chrono>
 #include <exception>
-#include <__mutex_base>
+#include <mutex>
 #include <thread>
 
 #pragma GCC system_header
@@ -2066,6 +2066,8 @@
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
+// shared_future
+
 template <class _R>
 class shared_future
 {
@@ -2244,6 +2246,200 @@
     __x.swap(__y);
 }
 
+// atomic_future
+
+template <class _R>
+class atomic_future
+{
+    __assoc_state<_R>* __state_;
+    mutable mutex __mut_;
+
+public:
+    atomic_future() : __state_(nullptr) {}
+    atomic_future(const atomic_future& __rhs) : __state_(__rhs.__state_)
+        {if (__state_) __state_->__add_shared();}
+#ifdef _LIBCPP_MOVE
+    atomic_future(future<_R>&& __f) : __state_(__f.__state_)
+        {__f.__state_ = nullptr;}
+#endif  // _LIBCPP_MOVE
+    ~atomic_future();
+    atomic_future& operator=(const atomic_future& __rhs);
+
+    // retrieving the value
+    const _R& get() const {return __state_->copy();}
+
+    void swap(atomic_future& __rhs);
+
+    // functions to check state
+    bool valid() const {return __state_ != nullptr;}
+
+    void wait() const {__state_->wait();}
+    template <class _Rep, class _Period>
+        future_status
+        wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
+            {return __state_->wait_for(__rel_time);}
+    template <class _Clock, class _Duration>
+        future_status
+        wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
+            {return __state_->wait_until(__abs_time);}
+};
+
+template <class _R>
+atomic_future<_R>::~atomic_future()
+{
+    if (__state_)
+        __state_->__release_shared();
+}
+
+template <class _R>
+atomic_future<_R>&
+atomic_future<_R>::operator=(const atomic_future& __rhs)
+{
+    if (this != &__rhs)
+    {
+        unique_lock<mutex> __this(__mut_, defer_lock);
+        unique_lock<mutex> __that(__rhs.__mut_, defer_lock);
+        _STD::lock(__this, __that);
+        if (__rhs.__state_)
+            __rhs.__state_->__add_shared();
+        if (__state_)
+            __state_->__release_shared();
+        __state_ = __rhs.__state_;
+    }
+    return *this;
+}
+
+template <class _R>
+void
+atomic_future<_R>::swap(atomic_future& __rhs)
+{
+    if (this != &__rhs)
+    {
+        unique_lock<mutex> __this(__mut_, defer_lock);
+        unique_lock<mutex> __that(__rhs.__mut_, defer_lock);
+        _STD::lock(__this, __that);
+        _STD::swap(__state_, __rhs.__state_);
+    }
+}
+
+template <class _R>
+class atomic_future<_R&>
+{
+    __assoc_state<_R&>* __state_;
+    mutable mutex __mut_;
+
+public:
+    atomic_future() : __state_(nullptr) {}
+    atomic_future(const atomic_future& __rhs) : __state_(__rhs.__state_)
+        {if (__state_) __state_->__add_shared();}
+#ifdef _LIBCPP_MOVE
+    atomic_future(future<_R&>&& __f) : __state_(__f.__state_)
+        {__f.__state_ = nullptr;}
+#endif  // _LIBCPP_MOVE
+    ~atomic_future();
+    atomic_future& operator=(const atomic_future& __rhs);
+
+    // retrieving the value
+    _R& get() const {return __state_->copy();}
+
+    void swap(atomic_future& __rhs);
+
+    // functions to check state
+    bool valid() const {return __state_ != nullptr;}
+
+    void wait() const {__state_->wait();}
+    template <class _Rep, class _Period>
+        future_status
+        wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
+            {return __state_->wait_for(__rel_time);}
+    template <class _Clock, class _Duration>
+        future_status
+        wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
+            {return __state_->wait_until(__abs_time);}
+};
+
+template <class _R>
+atomic_future<_R&>::~atomic_future()
+{
+    if (__state_)
+        __state_->__release_shared();
+}
+
+template <class _R>
+atomic_future<_R&>&
+atomic_future<_R&>::operator=(const atomic_future& __rhs)
+{
+    if (this != &__rhs)
+    {
+        unique_lock<mutex> __this(__mut_, defer_lock);
+        unique_lock<mutex> __that(__rhs.__mut_, defer_lock);
+        _STD::lock(__this, __that);
+        if (__rhs.__state_)
+            __rhs.__state_->__add_shared();
+        if (__state_)
+            __state_->__release_shared();
+        __state_ = __rhs.__state_;
+    }
+    return *this;
+}
+
+template <class _R>
+void
+atomic_future<_R&>::swap(atomic_future& __rhs)
+{
+    if (this != &__rhs)
+    {
+        unique_lock<mutex> __this(__mut_, defer_lock);
+        unique_lock<mutex> __that(__rhs.__mut_, defer_lock);
+        _STD::lock(__this, __that);
+        _STD::swap(__state_, __rhs.__state_);
+    }
+}
+
+template <>
+class atomic_future<void>
+{
+    __assoc_sub_state* __state_;
+    mutable mutex __mut_;
+
+public:
+    atomic_future() : __state_(nullptr) {}
+    atomic_future(const atomic_future& __rhs) : __state_(__rhs.__state_)
+        {if (__state_) __state_->__add_shared();}
+#ifdef _LIBCPP_MOVE
+    atomic_future(future<void>&& __f) : __state_(__f.__state_)
+        {__f.__state_ = nullptr;}
+#endif  // _LIBCPP_MOVE
+    ~atomic_future();
+    atomic_future& operator=(const atomic_future& __rhs);
+
+    // retrieving the value
+    void get() const {__state_->copy();}
+
+    void swap(atomic_future& __rhs);
+
+    // functions to check state
+    bool valid() const {return __state_ != nullptr;}
+
+    void wait() const {__state_->wait();}
+    template <class _Rep, class _Period>
+        future_status
+        wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
+            {return __state_->wait_for(__rel_time);}
+    template <class _Clock, class _Duration>
+        future_status
+        wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
+            {return __state_->wait_until(__abs_time);}
+};
+
+template <class _R>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+swap(atomic_future<_R>& __x, atomic_future<_R>& __y)
+{
+    __x.swap(__y);
+}
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_FUTURE
diff --git a/include/thread b/include/thread
index 123c472..c380fe6 100644
--- a/include/thread
+++ b/include/thread
@@ -295,6 +295,7 @@
     __thread_struct();
     ~__thread_struct();
 
+    void notify_all_at_thread_exit(condition_variable*, mutex*);
     void __make_ready_at_thread_exit(__assoc_sub_state*);
 };