diff options
author | Jonathan Wakely <jwakely.gcc@gmail.com> | 2009-01-29 23:24:05 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2009-01-29 23:24:05 +0000 |
commit | cbdab9c897d52b8311979a1e31e41d248671a4cb (patch) | |
tree | 7d1482ccf71102b2e07f20bbe2ac2e2aa38e6c60 /libstdc++-v3/src | |
parent | 3631be4865f1942115b43d7f30a232a6cfb9c4b8 (diff) | |
download | gcc-cbdab9c897d52b8311979a1e31e41d248671a4cb.zip gcc-cbdab9c897d52b8311979a1e31e41d248671a4cb.tar.gz gcc-cbdab9c897d52b8311979a1e31e41d248671a4cb.tar.bz2 |
thread: Remove unused headers.
2009-01-29 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/std/thread: Remove unused headers.
(__thread_data_base): Remove unused mutex and base.
(thread::~thread): Only detach if joinable.
(thread::joinable): Test if thread data ptr is empty.
(thread::_M_thread_data_mutex): Remove.
(thread::_M_get_thread_data): Remove.
(thread::_M_make_thread_data): Remove overload, use make_shared.
(thread::id::id): Make constructor explicit.
* src/thread.cc (thread::join,thread::detach): Throw if not joinable.
(thread::_M_start_thread): Break shared_ptr cycle on error.
(__thread_proxy): Use shared_ptr swap instead of copy and reset.
* testsuite/30_threads/thread/member/4.cc: New.
* testsuite/30_threads/thread/member/5.cc: New.
From-SVN: r143772
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r-- | libstdc++-v3/src/thread.cc | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/libstdc++-v3/src/thread.cc b/libstdc++-v3/src/thread.cc index ca934dd..357034f 100644 --- a/libstdc++-v3/src/thread.cc +++ b/libstdc++-v3/src/thread.cc @@ -28,7 +28,7 @@ // the GNU General Public License. #include <thread> -#include <bits/move.h> // std::move +#include <cerrno> #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) @@ -41,8 +41,8 @@ namespace std void* __thread_proxy(void* __p) { __thread_data_base* __t = static_cast<__thread_data_base*>(__p); - __thread_data_ptr __local_thread_data = __t->_M_this_ptr; - __t->_M_this_ptr.reset(); + __thread_data_ptr __local_thread_data; + __local_thread_data.swap(__t->_M_this_ptr); try { @@ -61,30 +61,32 @@ namespace std void thread::join() { - if(joinable()) - { - void* __r = 0; - int __e = __gthread_join(_M_thread_data->_M_thread_handle, &__r); - if(__e) - __throw_system_error(__e); + int __e = EINVAL; - lock_guard<mutex> __lock(_M_thread_data_mutex); - _M_thread_data.reset(); - } + if (_M_thread_data) + { + void* __r = 0; + __e = __gthread_join(_M_thread_data->_M_thread_handle, &__r); + } + + if (__e) + __throw_system_error(__e); + + _M_thread_data.reset(); } void thread::detach() { - if(joinable()) - { - int __e = __gthread_detach(_M_thread_data->_M_thread_handle); - if(__e) - __throw_system_error(__e); + int __e = EINVAL; - lock_guard<mutex> __lock(_M_thread_data_mutex); - _M_thread_data.reset(); - } + if (_M_thread_data) + __e = __gthread_detach(_M_thread_data->_M_thread_handle); + + if (__e) + __throw_system_error(__e); + + _M_thread_data.reset(); } void @@ -93,8 +95,11 @@ namespace std _M_thread_data->_M_this_ptr = _M_thread_data; int __e = __gthread_create(&_M_thread_data->_M_thread_handle, &__thread_proxy, _M_thread_data.get()); - if(__e) + if (__e) + { + _M_thread_data->_M_this_ptr.reset(); __throw_system_error(__e); + } } } |