summaryrefslogtreecommitdiffstats
path: root/libcxx/include/future
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2010-09-03 21:46:37 +0000
committerHoward Hinnant <hhinnant@apple.com>2010-09-03 21:46:37 +0000
commitb77c0c03bb5f48c7ff98aa0d8dd5c648e8a1a651 (patch)
tree51b1ae1903851f02fc0104ff07339673c7e83f73 /libcxx/include/future
parent005155e236afd14f9cc1342a213f050287e9bb26 (diff)
downloadbcm5719-llvm-b77c0c03bb5f48c7ff98aa0d8dd5c648e8a1a651.tar.gz
bcm5719-llvm-b77c0c03bb5f48c7ff98aa0d8dd5c648e8a1a651.zip
[futures.atomic_future] and notify_all_at_thread_exit. This completes the header <future> and all of Chapter 30 (for C++0x enabled compilers).
llvm-svn: 113017
Diffstat (limited to 'libcxx/include/future')
-rw-r--r--libcxx/include/future198
1 files changed, 197 insertions, 1 deletions
diff --git a/libcxx/include/future b/libcxx/include/future
index 4189d88165e..a1f976f2925 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -439,7 +439,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
#include <memory>
#include <chrono>
#include <exception>
-#include <__mutex_base>
+#include <mutex>
#include <thread>
#pragma GCC system_header
@@ -2066,6 +2066,8 @@ async(_F&& __f, _Args&&... __args)
#endif // _LIBCPP_HAS_NO_VARIADICS
+// shared_future
+
template <class _R>
class shared_future
{
@@ -2244,6 +2246,200 @@ swap(shared_future<_R>& __x, shared_future<_R>& __y)
__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
OpenPOWER on IntegriCloud