diff options
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); + } } } |