This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [c++0x] std::thread fixes
2009/1/22 Benjamin Kosnik:
>
> Can we break this patch down into a couple patches, and move a bit more
> incrementally?
Sure, this just adds the move ops and renames the member functions, it
doesn't change the type names __thread_data_base, __thread_data or
__thread_data_ptr.
I've remembered the diff for the ABI exports this time too.
* include/std/thread (__thread_data_base, thread): Rename member
functions to match coding style.
(thread::thread,thread::operator=): Define move operations.
* src/thread.cc (__thread_data_base, thread): Rename member functions.
* config/abi/pre/gnu.ver: Adjust.
tested x86_64 linux
Index: include/std/thread
===================================================================
--- include/std/thread (revision 143555)
+++ include/std/thread (working copy)
@@ -65,7 +65,7 @@ namespace std
__thread_data_base() = default;
virtual ~__thread_data_base() = default;
- virtual void __run() = 0;
+ virtual void _M_run() = 0;
__gthread_t _M_thread_handle;
__thread_data_ptr _M_this_ptr;
@@ -80,7 +80,7 @@ namespace std
: _M_func(std::forward<_Callable>(__f))
{ }
- void __run()
+ void _M_run()
{ _M_func(); }
private:
@@ -100,21 +100,29 @@ namespace std
template<typename _Callable>
explicit thread(_Callable __f)
- : _M_thread_data(__make_thread_data(__f))
- { __start_thread(); }
+ : _M_thread_data(_M_make_thread_data(__f))
+ { _M_start_thread(); }
template<typename _Callable, typename... _Args>
thread(_Callable&& __f, _Args&&... __args)
- : _M_thread_data(__make_thread_data(std::bind(__f, __args...)))
- { __start_thread(); }
+ : _M_thread_data(_M_make_thread_data(std::bind(__f, __args...)))
+ { _M_start_thread(); }
~thread()
{ detach(); }
thread(const thread&) = delete;
- thread(thread&&);
+ thread(thread&& __t)
+ { swap(__t); }
+
thread& operator=(const thread&) = delete;
- thread& operator=(thread&&);
+ thread& operator=(thread&& __t)
+ {
+ if (joinable())
+ detach();
+ swap(__t);
+ return *this;
+ }
// members
void
@@ -150,17 +158,17 @@ namespace std
private:
template<typename _Callable>
__thread_data_ptr
- __make_thread_data(_Callable&& __f)
+ _M_make_thread_data(_Callable&& __f)
{
return __thread_data_ptr(
new __thread_data<_Callable>(std::forward<_Callable>(__f)));
}
__thread_data_ptr
- __make_thread_data(void(*__f)())
+ _M_make_thread_data(void(*__f)())
{ return __thread_data_ptr(new __thread_data<void(*)()>(__f)); }
- void __start_thread();
+ void _M_start_thread();
__thread_data_ptr _M_thread_data;
mutable mutex _M_thread_data_mutex;
Index: src/thread.cc
===================================================================
--- src/thread.cc (revision 143555)
+++ src/thread.cc (working copy)
@@ -46,7 +46,7 @@ namespace std
try
{
- __local_thread_data->__run();
+ __local_thread_data->_M_run();
}
catch(...)
{
@@ -88,7 +88,7 @@ namespace std
}
void
- thread::__start_thread()
+ thread::_M_start_thread()
{
_M_thread_data->_M_this_ptr = _M_thread_data;
int __e = __gthread_create(&_M_thread_data->_M_thread_handle,
Index: config/abi/pre/gnu.ver
===================================================================
--- config/abi/pre/gnu.ver (revision 143486)
+++ config/abi/pre/gnu.ver (working copy)
@@ -901,7 +901,7 @@ GLIBCXX_3.4.11 {
_ZNSt10shared_ptrISt18__thread_data_baseED1Ev;
_ZNSt12bad_weak_ptrD0Ev;
_ZNSt12bad_weak_ptrD1Ev;
- _ZNSt6thread14__start_threadEv;
+ _ZNSt6thread15_M_start_threadEv;
_ZNSt6thread4joinEv;
_ZNSt6thread6detachEv;