Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77838 - in trunk: boost/thread/detail libs/thread/src/pthread libs/thread/src/win32
From: vicente.botet_at_[hidden]
Date: 2012-04-08 15:22:39


Author: viboes
Date: 2012-04-08 15:22:38 EDT (Sun, 08 Apr 2012)
New Revision: 77838
URL: http://svn.boost.org/trac/boost/changeset/77838

Log:
Thread: Provided an alternative implementation for thread::id using pthread_t and Windows Thread Id
Text files modified:
   trunk/boost/thread/detail/thread.hpp | 31 +++++++++++++++++++++++++++----
   trunk/libs/thread/src/pthread/thread.cpp | 11 ++++++++++-
   trunk/libs/thread/src/win32/thread.cpp | 11 +++++++++++
   3 files changed, 48 insertions(+), 5 deletions(-)

Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp (original)
+++ trunk/boost/thread/detail/thread.hpp 2012-04-08 15:22:38 EDT (Sun, 08 Apr 2012)
@@ -649,19 +649,41 @@
         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 @@
         {
             if(thread_data)
             {
- return os<<thread_data;
+ io::ios_flags_saver ifs( os );
+ return os<< std::hex << thread_data;
             }
             else
             {

Modified: trunk/libs/thread/src/pthread/thread.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/thread.cpp (original)
+++ trunk/libs/thread/src/pthread/thread.cpp 2012-04-08 15:22:38 EDT (Sun, 08 Apr 2012)
@@ -483,6 +483,10 @@
 
     thread::id thread::get_id() const BOOST_NOEXCEPT
     {
+ #if defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID
+ //return local_thread_info->thread_handle;
+ return const_cast<thread*>(this)->native_handle();
+ #else
         detail::thread_data_ptr const local_thread_info=(get_thread_info)();
         if(local_thread_info)
         {
@@ -490,8 +494,9 @@
         }
         else
         {
- return id();
+ return id();
         }
+ #endif
     }
 
     void thread::interrupt()
@@ -543,8 +548,12 @@
     {
         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()

Modified: trunk/libs/thread/src/win32/thread.cpp
==============================================================================
--- trunk/libs/thread/src/win32/thread.cpp (original)
+++ trunk/libs/thread/src/win32/thread.cpp 2012-04-08 15:22:38 EDT (Sun, 08 Apr 2012)
@@ -277,7 +277,13 @@
 
     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<thread*>(this)->native_handle();
+ #else
         return thread::id((get_thread_info)());
+ #endif
     }
 
     bool thread::joinable() const BOOST_NOEXCEPT
@@ -537,7 +543,12 @@
 
         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()


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk