From 3eb16ce106114bbc4c2ae30cae7224a13f93c6de Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 5 Feb 2010 17:19:10 +0000 Subject: [PATCH] 2010-02-05 Paolo Carlini * include/std/future (swap(packaged_task<>&, packaged_task<>&), swap(promise<>&, promise<>&)): Add; minor formatting fixes. * testsuite/30_threads/packaged_task/cons/assign_neg.cc: Adjust dg-error line number. * testsuite/30_threads/packaged_task/cons/copy_neg.cc: Likewise. * testsuite/30_threads/promise/cons/assign_neg.cc: Likewise. * testsuite/30_threads/promise/cons/copy_neg.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156522 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 10 +++ libstdc++-v3/include/std/future | 80 ++++++++++++++-------- .../30_threads/packaged_task/cons/assign_neg.cc | 4 +- .../30_threads/packaged_task/cons/copy_neg.cc | 4 +- .../30_threads/promise/cons/assign_neg.cc | 4 +- .../testsuite/30_threads/promise/cons/copy_neg.cc | 4 +- 6 files changed, 69 insertions(+), 37 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4b418ed9c7a..5468a0eb456 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,15 @@ 2010-02-05 Paolo Carlini + * include/std/future (swap(packaged_task<>&, packaged_task<>&), + swap(promise<>&, promise<>&)): Add; minor formatting fixes. + * testsuite/30_threads/packaged_task/cons/assign_neg.cc: Adjust + dg-error line number. + * testsuite/30_threads/packaged_task/cons/copy_neg.cc: Likewise. + * testsuite/30_threads/promise/cons/assign_neg.cc: Likewise. + * testsuite/30_threads/promise/cons/copy_neg.cc: Likewise. + +2010-02-05 Paolo Carlini + * include/bits/stl_algobase.h (struct __iter_base): Rename to _Iter_base; add iterator_type typedef. (struct __miter_base): Rename to _Miter_base. diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index 629d61aec22..b7b244988ac 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -1,6 +1,6 @@ // -*- C++ -*- -// Copyright (C) 2009 Free Software Foundation, Inc. +// Copyright (C) 2009, 2010 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -799,17 +799,20 @@ namespace std // Now we can define the protected __basic_future constructors. template - __basic_future<_Res>::__basic_future(const shared_future<_Res>& __sf) + inline __basic_future<_Res>:: + __basic_future(const shared_future<_Res>& __sf) : _M_state(__sf._M_state) { } template - __basic_future<_Res>::__basic_future(shared_future<_Res>&& __sf) + inline __basic_future<_Res>:: + __basic_future(shared_future<_Res>&& __sf) : _M_state(std::move(__sf._M_state)) { } template - __basic_future<_Res>::__basic_future(future<_Res>&& __uf) + inline __basic_future<_Res>:: + __basic_future(future<_Res>&& __uf) : _M_state(std::move(__uf._M_state)) { } @@ -828,12 +831,13 @@ namespace std public: promise() - : _M_future(std::make_shared<_State>()), _M_storage(new _Res_type()) + : _M_future(std::make_shared<_State>()), + _M_storage(new _Res_type()) { } promise(promise&& __rhs) : _M_future(std::move(__rhs._M_future)), - _M_storage(std::move(__rhs._M_storage)) + _M_storage(std::move(__rhs._M_storage)) { } // TODO: needs allocator_arg_t @@ -898,6 +902,11 @@ namespace std } }; + template + inline void + swap(promise<_Res>& __x, promise<_Res>& __y) + { __x.swap(__y); } + /// Partial specialization for promise template class promise<_Res&> @@ -912,7 +921,8 @@ namespace std public: promise() - : _M_future(std::make_shared<_State>()), _M_storage(new _Res_type()) + : _M_future(std::make_shared<_State>()), + _M_storage(new _Res_type()) { } promise(promise&& __rhs) @@ -995,7 +1005,7 @@ namespace std promise(promise&& __rhs) : _M_future(std::move(__rhs._M_future)), - _M_storage(std::move(__rhs._M_storage)) + _M_storage(std::move(__rhs._M_storage)) { } @@ -1087,11 +1097,14 @@ namespace std { typename _StateT::_Ptr_type operator()() { - __try { - _M_state->_M_result->_M_set(_M_fn()); - } __catch(...) { - _M_state->_M_result->_M_error = current_exception(); - } + __try + { + _M_state->_M_result->_M_set(_M_fn()); + } + __catch(...) + { + _M_state->_M_result->_M_error = current_exception(); + } return std::move(_M_state->_M_result); } _StateT* _M_state; @@ -1103,12 +1116,15 @@ namespace std { typename _StateT::_Ptr_type operator()() { - __try { - _M_fn(); - } __catch(...) { - _M_state->_M_result->_M_error = current_exception(); - } - return std::move(_M_state->_M_result); + __try + { + _M_fn(); + } + __catch(...) + { + _M_state->_M_result->_M_error = current_exception(); + } + return std::move(_M_state->_M_result); } _StateT* _M_state; std::function _M_fn; @@ -1245,6 +1261,12 @@ namespace std } }; + template + void inline + swap(packaged_task<_Res(_ArgTypes...)>& __x, + packaged_task<_Res(_ArgTypes...)>& __y) + { __x.swap(__y); } + template class __future_base::_Deferred_state : public __future_base::_State { @@ -1280,7 +1302,7 @@ namespace std explicit _Async_state(std::function<_Res()>&& __fn) : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn)), - _M_thread(mem_fn(&_Async_state::_M_do_run), this) + _M_thread(mem_fn(&_Async_state::_M_do_run), this) { } ~_Async_state() { _M_thread.join(); } @@ -1306,17 +1328,17 @@ namespace std typedef typename _Fn::result_type result_type; std::shared_ptr<__future_base::_State> __state; if (__policy == launch::async) - { - typedef typename __future_base::_Async_state _State; - __state = std::make_shared<_State>(std::bind( + { + typedef typename __future_base::_Async_state _State; + __state = std::make_shared<_State>(std::bind( std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)); - } + } else - { - typedef typename __future_base::_Deferred_state _State; - __state = std::make_shared<_State>(std::bind( + { + typedef typename __future_base::_Deferred_state _State; + __state = std::make_shared<_State>(std::bind( std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)); - } + } return future(__state); } @@ -1325,7 +1347,7 @@ namespace std async(_Fn&& __fn, _Args&&... __args) { return async(launch::any, std::forward<_Fn>(__fn), - std::forward<_Args>(__args)...); + std::forward<_Args>(__args)...); } #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc index 8b724d502da..69cfdd32aae 100644 --- a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/assign_neg.cc @@ -4,7 +4,7 @@ // { dg-require-gthreads "" } // { dg-require-atomic-builtins "" } -// Copyright (C) 2009 Free Software Foundation, Inc. +// Copyright (C) 2009, 2010 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -33,4 +33,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 32 } -// { dg-error "deleted function" "" { target *-*-* } 1209 } +// { dg-error "deleted function" "" { target *-*-* } 1225 } diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc index 82a330fef2e..b3fbdbcff3b 100644 --- a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/copy_neg.cc @@ -4,7 +4,7 @@ // { dg-require-gthreads "" } // { dg-require-atomic-builtins "" } -// Copyright (C) 2009 Free Software Foundation, Inc. +// Copyright (C) 2009, 2010 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -32,4 +32,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 31 } -// { dg-error "deleted function" "" { target *-*-* } 1208 } +// { dg-error "deleted function" "" { target *-*-* } 1224 } diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc index 229ee3ff4bb..a52ceae7019 100644 --- a/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/promise/cons/assign_neg.cc @@ -4,7 +4,7 @@ // { dg-require-gthreads "" } // { dg-require-atomic-builtins "" } -// Copyright (C) 2009 Free Software Foundation, Inc. +// Copyright (C) 2009, 2010 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -33,4 +33,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 32 } -// { dg-error "deleted function" "" { target *-*-* } 864 } +// { dg-error "deleted function" "" { target *-*-* } 868 } diff --git a/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc index a40ab79b5b6..22d44cef341 100644 --- a/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc +++ b/libstdc++-v3/testsuite/30_threads/promise/cons/copy_neg.cc @@ -4,7 +4,7 @@ // { dg-require-gthreads "" } // { dg-require-atomic-builtins "" } -// Copyright (C) 2009 Free Software Foundation, Inc. +// Copyright (C) 2009, 2010 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -32,4 +32,4 @@ void test01() } // { dg-error "used here" "" { target *-*-* } 31 } -// { dg-error "deleted function" "" { target *-*-* } 848 } +// { dg-error "deleted function" "" { target *-*-* } 852 } -- 2.11.0