summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/include/std/thread
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2009-01-29 23:24:05 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2009-01-29 23:24:05 +0000
commit6db3e8352fefa7e59317de8a9078f0c001289e3f (patch)
tree7d1482ccf71102b2e07f20bbe2ac2e2aa38e6c60 /libstdc++-v3/include/std/thread
parentac50b6ef556f85dd1a8e2d9f529ce5a3ef085675 (diff)
downloadppe42-gcc-6db3e8352fefa7e59317de8a9078f0c001289e3f.tar.gz
ppe42-gcc-6db3e8352fefa7e59317de8a9078f0c001289e3f.zip
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@143772 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/thread')
-rw-r--r--libstdc++-v3/include/std/thread39
1 files changed, 13 insertions, 26 deletions
diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index e6ce0f71876..79bf29013a4 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -41,12 +41,10 @@
#else
#include <chrono>
-#include <exception>
#include <functional>
#include <memory>
#include <mutex>
#include <condition_variable>
-#include <type_traits>
#include <cstddef>
#include <bits/functexcept.h>
#include <bits/gthr.h>
@@ -59,7 +57,7 @@ namespace std
typedef shared_ptr<__thread_data_base> __thread_data_ptr;
- class __thread_data_base : public enable_shared_from_this<__thread_data_base>
+ class __thread_data_base
{
public:
__thread_data_base() = default;
@@ -69,7 +67,6 @@ namespace std
__gthread_t _M_thread_handle;
__thread_data_ptr _M_this_ptr;
- mutex _M_data_mutex;
};
template<typename _Callable>
@@ -109,7 +106,10 @@ namespace std
{ _M_start_thread(); }
~thread()
- { detach(); }
+ {
+ if (joinable())
+ detach();
+ }
thread(const thread&) = delete;
thread(thread&& __t)
@@ -130,7 +130,8 @@ namespace std
{ std::swap(_M_thread_data, __t._M_thread_data); }
bool
- joinable() const;
+ joinable() const
+ { return _M_thread_data; }
void
join();
@@ -141,6 +142,8 @@ namespace std
thread::id
get_id() const;
+ /** @pre thread is joinable
+ */
native_handle_type
native_handle()
{ return _M_thread_data->_M_thread_handle; }
@@ -148,30 +151,18 @@ namespace std
// static members
static unsigned hardware_concurrency();
- __thread_data_ptr
- _M_get_thread_data() const
- {
- lock_guard<mutex> __l(_M_thread_data_mutex);
- return _M_thread_data;
- }
-
private:
template<typename _Callable>
__thread_data_ptr
_M_make_thread_data(_Callable&& __f)
{
- return __thread_data_ptr(
- new __thread_data<_Callable>(std::forward<_Callable>(__f)));
+ return make_shared<__thread_data<_Callable>>(
+ std::forward<_Callable>(__f));
}
- __thread_data_ptr
- _M_make_thread_data(void(*__f)())
- { return __thread_data_ptr(new __thread_data<void(*)()>(__f)); }
-
void _M_start_thread();
__thread_data_ptr _M_thread_data;
- mutable mutex _M_thread_data_mutex;
};
inline void
@@ -237,8 +228,7 @@ namespace std
friend bool
operator==(thread::id __x, thread::id __y)
- { return static_cast<bool>(__gthread_equal(__x._M_thread_id,
- __y._M_thread_id)); }
+ { return __gthread_equal(__x._M_thread_id, __y._M_thread_id); }
friend bool
operator<(thread::id __x, thread::id __y)
@@ -248,6 +238,7 @@ namespace std
friend basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>&& __out, thread::id __id);
+ explicit
id(__gthread_t __id)
: _M_thread_id(__id)
{ }
@@ -281,10 +272,6 @@ namespace std
return __out << __id._M_thread_id;
}
- inline bool
- thread::joinable() const
- { return get_id() != thread::id(); }
-
inline thread::id
thread::get_id() const
{
OpenPOWER on IntegriCloud