aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/src/thread.cc
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@redhat.com>2009-02-07 21:56:55 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2009-02-07 21:56:55 +0000
commitd7afcd2b9ba4534fce7ec4d6d31a508af312b928 (patch)
treeab7a64f83b4f9ff2ad08ff622a70bd0a6957bf87 /libstdc++-v3/src/thread.cc
parent5a7e237c637967eed5edff0a889c643ced174b33 (diff)
downloadgcc-d7afcd2b9ba4534fce7ec4d6d31a508af312b928.zip
gcc-d7afcd2b9ba4534fce7ec4d6d31a508af312b928.tar.gz
gcc-d7afcd2b9ba4534fce7ec4d6d31a508af312b928.tar.bz2
thread (thread::id): Move definition inside thread.
2009-02-06 Benjamin Kosnik <bkoz@redhat.com> * include/std/thread (thread::id): Move definition inside thread. Use native_handle_type. Remove this_thread::get_id friend. Change __thread_data_ptr to __shared_base_ptr. (thread::id::id(native_handle_type): Make public. Still explicit. Use native_handle_type. Change _M_thread_id to _M_thread. (thread::__thread_data_base): Rename to _Impl_base. Use id, change _M_thread_handle to _M_id. (thread::__thread_data): Rename to _Impl. Fixup for renames. (thread::_M_make_thread_data): Return derived type. (thread::hardware_concurrency): Add definition for default case. (thread::get_id): Now can define inline. (thread): Change _M_thread_data to _M_data. (this_thread::get_id): Now can define inline. * src/thread.cc (__thread_proxy): Rename to execute_native_thread_routine. Fixup for other renames. * testsuite/30_threads/thread/cons/assign_neg.cc: New. * testsuite/30_threads/thread/cons/copy_neg.cc: New. * testsuite/30_threads/thread/algorithm: Move to.. * testsuite/30_threads/thread/swap: ...this. * testsuite/30_threads/thread/member/hardware_concurrency.cc: Add. * testsuite/30_threads/thread/id/operators.cc: New. From-SVN: r144007
Diffstat (limited to 'libstdc++-v3/src/thread.cc')
-rw-r--r--libstdc++-v3/src/thread.cc62
1 files changed, 30 insertions, 32 deletions
diff --git a/libstdc++-v3/src/thread.cc b/libstdc++-v3/src/thread.cc
index e3797e6..bc30283 100644
--- a/libstdc++-v3/src/thread.cc
+++ b/libstdc++-v3/src/thread.cc
@@ -34,28 +34,25 @@
namespace std
{
- namespace
+ namespace
{
- extern "C"
+ extern "C" void*
+ execute_native_thread_routine(void* __p)
{
- void* __thread_proxy(void* __p)
- {
- thread::__thread_data_base* __t =
- static_cast<thread::__thread_data_base*>(__p);
- thread::__thread_data_ptr __local_thread_data;
- __local_thread_data.swap(__t->_M_this_ptr);
-
- __try
- {
- __local_thread_data->_M_run();
- }
- __catch(...)
- {
- std::terminate();
- }
-
- return 0;
- }
+ thread::_Impl_base* __t = static_cast<thread::_Impl_base*>(__p);
+ thread::__shared_base_type __local;
+ __local.swap(__t->_M_this_ptr);
+
+ __try
+ {
+ __local->_M_run();
+ }
+ __catch(...)
+ {
+ std::terminate();
+ }
+
+ return 0;
}
}
@@ -64,41 +61,42 @@ namespace std
{
int __e = EINVAL;
- if (_M_thread_data)
+ if (_M_data)
{
void* __r = 0;
- __e = __gthread_join(_M_thread_data->_M_thread_handle, &__r);
+ __e = __gthread_join(_M_data->_M_id._M_thread, &__r);
}
if (__e)
__throw_system_error(__e);
- _M_thread_data.reset();
+ _M_data.reset();
}
void
thread::detach()
- {
+ {
int __e = EINVAL;
- if (_M_thread_data)
- __e = __gthread_detach(_M_thread_data->_M_thread_handle);
+ if (_M_data)
+ __e = __gthread_detach(_M_data->_M_id._M_thread);
if (__e)
__throw_system_error(__e);
- _M_thread_data.reset();
+ _M_data.reset();
}
- void
+ void
thread::_M_start_thread()
{
- _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());
+ // _M_data->_M_this_ptr = _M_data;
+ _M_data->_M_this_ptr = _M_data;
+ int __e = __gthread_create(&_M_data->_M_id._M_thread,
+ &execute_native_thread_routine, _M_data.get());
if (__e)
{
- _M_thread_data->_M_this_ptr.reset();
+ _M_data->_M_this_ptr.reset();
__throw_system_error(__e);
}
}