Ticket #5173: thread_ext.patch
File thread_ext.patch, 6.6 KB (added by , 12 years ago) |
---|
-
boost/thread/detail/thread.hpp
27 27 28 28 #include <boost/config/abi_prefix.hpp> 29 29 30 /** Enabling the boost thread extension, will enable a cached version of 31 * boost::this_thread::get_id() and the retrieval of the main thread::id 32 * via boost::main_thread::get_id(), both base on thread_ext.hpp. 33 */ 34 #define BOOST_THREAD_EXT 35 30 36 #ifdef BOOST_MSVC 31 37 #pragma warning(push) 32 38 #pragma warning(disable:4251) … … 374 380 375 381 namespace this_thread 376 382 { 383 #ifndef BOOST_THREAD_EXT 377 384 thread::id BOOST_THREAD_DECL get_id(); 385 #else 386 struct handler; 387 #endif 378 388 379 389 void BOOST_THREAD_DECL interruption_point(); 380 390 bool BOOST_THREAD_DECL interruption_enabled(); … … 395 405 thread_data(thread_data_) 396 406 {} 397 407 friend class thread; 408 409 #ifndef BOOST_THREAD_EXT 398 410 friend id BOOST_THREAD_DECL this_thread::get_id(); 411 #else 412 friend struct this_thread::handler; 413 #endif 399 414 public: 400 415 id(): 401 416 thread_data() … … 523 538 } 524 539 } 525 540 541 #ifdef BOOST_THREAD_EXT 542 #include <boost/thread/detail/thread_ext.hpp> 543 #endif 544 526 545 #ifdef BOOST_MSVC 527 546 #pragma warning(pop) 528 547 #endif -
boost/thread/detail/thread_ext.hpp
1 /** 2 * @note Copyright\n 3 * ADOxx for Windows and Linux\n 4 * (C) COPYRIGHT BOC - Business Objectives Consulting 1996-2011\n 5 * All Rights Reserved\n 6 * Use, duplication or disclosure restricted by BOC Information Systems\n 7 * Vienna, 2011 8 * @brief 9 * @author iloehken, 2011 10 * 11 */ 12 13 #ifdef _MSC_VER 14 #pragma once 15 #endif 16 17 #ifndef THREAD_THREAD_EXT_HPP_ 18 #define THREAD_THREAD_EXT_HPP_ 19 20 namespace boost { namespace this_thread 21 { 22 //-------------------------------------------------------------------- 23 struct BOOST_THREAD_DECL handler 24 //-------------------------------------------------------------------- 25 { 26 private: 27 static thread::id const make_id(); // called once by get_id to initialize caching and abstract from platform 28 29 public: 30 static thread::id const& get_id(); 31 static thread::id const& get_main_id(); 32 }; 33 34 //-------------------------------------------------------------------- 35 inline thread::id const& 36 get_id() 37 //-------------------------------------------------------------------- 38 { 39 return handler::get_id(); 40 } 41 } // namespace this_thread 42 43 namespace main_thread 44 { 45 //-------------------------------------------------------------------- 46 inline thread::id const& 47 get_id() 48 //-------------------------------------------------------------------- 49 { 50 return this_thread::handler::get_main_id(); 51 } 52 }} // namespace boost::main_thread 53 54 #endif -
libs/thread/src/pthread/thread.cpp
449 449 450 450 namespace this_thread 451 451 { 452 #ifndef BOOST_THREAD_EXT 452 453 thread::id get_id() 454 #else 455 boost::thread::id const handler::make_id() 456 #endif 453 457 { 454 458 boost::detail::thread_data_base* const thread_info=get_or_make_current_thread_data(); 455 459 return thread::id(thread_info?thread_info->shared_from_this():detail::thread_data_ptr()); … … 600 604 601 605 602 606 } 607 608 #ifdef BOOST_THREAD_EXT 609 #include "../thread_ext.inl" 610 #endif -
libs/thread/src/thread_ext.inl
1 /** 2 * @note Copyright\n 3 * ADOxx for Windows and Linux\n 4 * (C) COPYRIGHT BOC - Business Objectives Consulting 1996-2011\n 5 * All Rights Reserved\n 6 * Use, duplication or disclosure restricted by BOC Information Systems\n 7 * Vienna, 2011 8 * @brief 9 * @author iloehken, 2011 10 * 11 */ 12 13 #include <boost/pool/detail/singleton.hpp> 14 15 namespace boost { namespace this_thread { 16 17 //-------------------------------------------------------------------- 18 boost::thread::id const& 19 handler::get_id() 20 //-------------------------------------------------------------------- 21 { 22 /** ILO : 24/02/2011 23 * Injected code, that stores the thread id in thread specific_ptr 24 * to speed up access, because without caching the retrieval of the 25 * current thread id is really slow (60 times faster with caching) 26 */ 27 static boost::thread_specific_ptr<thread::id> aCachedID; 28 29 if(boost::thread::id* pThreadID = aCachedID.get()) 30 { 31 return *pThreadID; 32 } 33 34 aCachedID.reset(new thread::id(handler::make_id())); 35 return *aCachedID.get(); 36 } 37 38 namespace { 39 40 /** ILO : 24/02/2011 41 * 42 * Simple Holder for MainThreadID used with recurring static 43 * initialization scheme to determine the main thread in a safe way. 44 */ 45 //-------------------------------------------------------------------- 46 struct main_id 47 //-------------------------------------------------------------------- 48 { 49 boost::thread::id const m_id;; 50 51 //-------------------------------------------------------------------- 52 explicit main_id() 53 : m_id(boost::this_thread::get_id()) 54 //-------------------------------------------------------------------- 55 {} 56 }; 57 58 } // namespace anonymous 59 60 //-------------------------------------------------------------------- 61 boost::thread::id const& 62 handler::get_main_id() 63 //-------------------------------------------------------------------- 64 { 65 return boost::details::pool::singleton_default<main_id>::instance().m_id; 66 } 67 68 }} 69 -
libs/thread/src/win32/thread.cpp
482 482 return false; 483 483 } 484 484 485 #ifndef BOOST_THREAD_EXT 485 486 thread::id get_id() 487 #else 488 boost::thread::id const handler::make_id() 489 #endif 486 490 { 487 491 return thread::id(get_or_make_current_thread_data()); 488 492 } … … 621 625 622 626 } 623 627 624 628 #ifdef BOOST_THREAD_EXT 629 #include "../thread_ext.inl" 630 #endif