From d75cda0cc32ea0d7b934dba50f8c64a1935628c6 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Sun, 8 Apr 2012 19:22:38 +0000 Subject: [PATCH] Thread: Provided an alternative implementation for thread::id using pthread_t and Windows Thread Id [SVN r77838] --- include/boost/thread/detail/thread.hpp | 31 ++++++++++++++++++++++---- src/pthread/thread.cpp | 11 ++++++++- src/win32/thread.cpp | 11 +++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/include/boost/thread/detail/thread.hpp b/include/boost/thread/detail/thread.hpp index 17c04e45..4a79bc96 100644 --- a/include/boost/thread/detail/thread.hpp +++ b/include/boost/thread/detail/thread.hpp @@ -649,19 +649,41 @@ namespace boost std::size_t hash_value(const thread::id &v) { +#if defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID + return hash_value(v.thread_data); +#else return hash_value(v.thread_data.get()); +#endif } - detail::thread_data_ptr thread_data; +#if defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID +#if defined(BOOST_THREAD_PLATFORM_WIN32) + typedef unsigned int data; +#else + typedef thread::native_handle_type data; +#endif +#else + typedef detail::thread_data_ptr data; +#endif + data thread_data; - id(detail::thread_data_ptr thread_data_): + id(data thread_data_): thread_data(thread_data_) {} friend class thread; friend id BOOST_THREAD_DECL this_thread::get_id() BOOST_NOEXCEPT; public: id() BOOST_NOEXCEPT: - thread_data() +#if defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID +#if defined(BOOST_THREAD_PLATFORM_WIN32) + //thread_data(detail::win32::invalid_handle_value) + thread_data(0) +#else + thread_data(0) +#endif +#else + thread_data() +#endif {} id(const id& other) BOOST_NOEXCEPT : @@ -723,7 +745,8 @@ namespace boost { if(thread_data) { - return os<thread_handle; + return const_cast(this)->native_handle(); + #else detail::thread_data_ptr const local_thread_info=(get_thread_info)(); if(local_thread_info) { @@ -490,8 +494,9 @@ namespace boost } else { - return id(); + return id(); } + #endif } void thread::interrupt() @@ -543,8 +548,12 @@ namespace boost { thread::id get_id() BOOST_NOEXCEPT { + #if defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID + return pthread_self(); + #else boost::detail::thread_data_base* const thread_info=get_or_make_current_thread_data(); return thread::id(thread_info?thread_info->shared_from_this():detail::thread_data_ptr()); + #endif } void interruption_point() diff --git a/src/win32/thread.cpp b/src/win32/thread.cpp index 38979d45..95f876e9 100644 --- a/src/win32/thread.cpp +++ b/src/win32/thread.cpp @@ -277,7 +277,13 @@ namespace boost thread::id thread::get_id() const BOOST_NOEXCEPT { + #if defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID + detail::thread_data_ptr local_thread_info=(get_thread_info)(); + return local_thread_info?local_thread_info->id:0; + //return const_cast(this)->native_handle(); + #else return thread::id((get_thread_info)()); + #endif } bool thread::joinable() const BOOST_NOEXCEPT @@ -537,7 +543,12 @@ namespace boost thread::id get_id() BOOST_NOEXCEPT { + #if defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID + //return detail::win32::GetCurrentThread(); + return detail::win32::GetCurrentThreadId(); + #else return thread::id(get_or_make_current_thread_data()); + #endif } void interruption_point()