diff options
author | theraven <theraven@FreeBSD.org> | 2012-03-13 14:09:15 +0000 |
---|---|---|
committer | theraven <theraven@FreeBSD.org> | 2012-03-13 14:09:15 +0000 |
commit | baa75b9984d33ea49ffb76a73507b64d879166cc (patch) | |
tree | 491848d33dbdf1751fd52f321d3fbf70a8e616f2 /include/thread | |
parent | d8f28ec8a2faabad3aabb9f7a26755971424ef05 (diff) | |
download | FreeBSD-src-baa75b9984d33ea49ffb76a73507b64d879166cc.zip FreeBSD-src-baa75b9984d33ea49ffb76a73507b64d879166cc.tar.gz |
Import new version of libc++ into vendor branch.
Approved by: dim (mentor)
Diffstat (limited to 'include/thread')
-rw-r--r-- | include/thread | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/include/thread b/include/thread index 4db4f61..23b1915 100644 --- a/include/thread +++ b/include/thread @@ -183,6 +183,9 @@ __thread_id get_id(); } // this_thread +class _LIBCPP_VISIBLE __thread_id; +template<> struct _LIBCPP_VISIBLE hash<__thread_id>; + class _LIBCPP_VISIBLE __thread_id { // FIXME: pthread_t is a pointer on Darwin but a long on Linux. @@ -226,10 +229,9 @@ private: friend __thread_id this_thread::get_id(); friend class _LIBCPP_VISIBLE thread; + friend struct _LIBCPP_VISIBLE hash<__thread_id>; }; -template<class _Tp> struct hash; - template<> struct _LIBCPP_VISIBLE hash<__thread_id> : public unary_function<__thread_id, size_t> @@ -237,8 +239,7 @@ struct _LIBCPP_VISIBLE hash<__thread_id> _LIBCPP_INLINE_VISIBILITY size_t operator()(__thread_id __v) const { - const size_t* const __p = reinterpret_cast<const size_t*>(&__v); - return *__p; + return hash<pthread_t>()(__v.__id_); } }; @@ -267,15 +268,15 @@ public: _LIBCPP_INLINE_VISIBILITY thread() : __t_(0) {} #ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _F, class ..._Args, + template <class _Fp, class ..._Args, class = typename enable_if < - !is_same<typename decay<_F>::type, thread>::value + !is_same<typename decay<_Fp>::type, thread>::value >::type > - explicit thread(_F&& __f, _Args&&... __args); + explicit thread(_Fp&& __f, _Args&&... __args); #else // _LIBCPP_HAS_NO_VARIADICS - template <class _F> explicit thread(_F __f); + template <class _Fp> explicit thread(_Fp __f); #endif ~thread(); @@ -322,34 +323,34 @@ __thread_specific_ptr<__thread_struct>& __thread_local_data(); #ifndef _LIBCPP_HAS_NO_VARIADICS -template <class _F, class ..._Args, size_t ..._Indices> +template <class _Fp, class ..._Args, size_t ..._Indices> inline _LIBCPP_INLINE_VISIBILITY void -__threaad_execute(tuple<_F, _Args...>& __t, __tuple_indices<_Indices...>) +__threaad_execute(tuple<_Fp, _Args...>& __t, __tuple_indices<_Indices...>) { __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...); } -template <class _F> +template <class _Fp> void* __thread_proxy(void* __vp) { __thread_local_data().reset(new __thread_struct); - std::unique_ptr<_F> __p(static_cast<_F*>(__vp)); - typedef typename __make_tuple_indices<tuple_size<_F>::value, 1>::type _Index; + std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp)); + typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 1>::type _Index; __threaad_execute(*__p, _Index()); return nullptr; } -template <class _F, class ..._Args, +template <class _Fp, class ..._Args, class > -thread::thread(_F&& __f, _Args&&... __args) +thread::thread(_Fp&& __f, _Args&&... __args) { - typedef tuple<typename decay<_F>::type, typename decay<_Args>::type...> _G; - _VSTD::unique_ptr<_G> __p(new _G(__decay_copy(_VSTD::forward<_F>(__f)), + typedef tuple<typename decay<_Fp>::type, typename decay<_Args>::type...> _Gp; + _VSTD::unique_ptr<_Gp> __p(new _Gp(__decay_copy(_VSTD::forward<_Fp>(__f)), __decay_copy(_VSTD::forward<_Args>(__args))...)); - int __ec = pthread_create(&__t_, 0, &__thread_proxy<_G>, __p.get()); + int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Gp>, __p.get()); if (__ec == 0) __p.release(); else @@ -358,21 +359,21 @@ thread::thread(_F&& __f, _Args&&... __args) #else // _LIBCPP_HAS_NO_VARIADICS -template <class _F> +template <class _Fp> void* __thread_proxy(void* __vp) { __thread_local_data().reset(new __thread_struct); - std::unique_ptr<_F> __p(static_cast<_F*>(__vp)); + std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp)); (*__p)(); return nullptr; } -template <class _F> -thread::thread(_F __f) +template <class _Fp> +thread::thread(_Fp __f) { - std::unique_ptr<_F> __p(new _F(__f)); - int __ec = pthread_create(&__t_, 0, &__thread_proxy<_F>, __p.get()); + std::unique_ptr<_Fp> __p(new _Fp(__f)); + int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Fp>, __p.get()); if (__ec == 0) __p.release(); else |