diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-11-24 20:33:19 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-11-24 20:35:17 (GMT) |
commit | 332d60c56dfaa11fdd135088279d15cd5983b3d4 (patch) | |
tree | dd77717a4e1732da929d5ff8a0471fa3f005e201 /3rdParty/Boost/src/libs/thread | |
parent | 90c44a10fec26d2a0935b2d62e82b6a5be028373 (diff) | |
download | swift-332d60c56dfaa11fdd135088279d15cd5983b3d4.zip swift-332d60c56dfaa11fdd135088279d15cd5983b3d4.tar.bz2 |
Upgraded Boost to 1.45.0.
Diffstat (limited to '3rdParty/Boost/src/libs/thread')
5 files changed, 125 insertions, 100 deletions
diff --git a/3rdParty/Boost/src/libs/thread/src/pthread/thread.cpp b/3rdParty/Boost/src/libs/thread/src/pthread/thread.cpp index 1c13a9a..187c024 100644 --- a/3rdParty/Boost/src/libs/thread/src/pthread/thread.cpp +++ b/3rdParty/Boost/src/libs/thread/src/pthread/thread.cpp @@ -75,7 +75,7 @@ namespace boost { current=next; ++next; - if(current->second.func && current->second.value) + if(current->second.func && (current->second.value!=0)) { (*current->second.func)(current->second.value); } @@ -196,15 +196,14 @@ namespace boost detach(); } - detail::thread_data_ptr thread::get_thread_info() const + detail::thread_data_ptr thread::get_thread_info BOOST_PREVENT_MACRO_SUBSTITUTION () const { - lock_guard<mutex> l(thread_info_mutex); return thread_info; } void thread::join() { - detail::thread_data_ptr const local_thread_info=get_thread_info(); + detail::thread_data_ptr const local_thread_info=(get_thread_info)(); if(local_thread_info) { bool do_join=false; @@ -238,7 +237,6 @@ namespace boost local_thread_info->done_condition.notify_all(); } - lock_guard<mutex> l1(thread_info_mutex); if(thread_info==local_thread_info) { thread_info.reset(); @@ -248,7 +246,7 @@ namespace boost bool thread::timed_join(system_time const& wait_until) { - detail::thread_data_ptr const local_thread_info=get_thread_info(); + detail::thread_data_ptr const local_thread_info=(get_thread_info)(); if(local_thread_info) { bool do_join=false; @@ -285,7 +283,6 @@ namespace boost local_thread_info->done_condition.notify_all(); } - lock_guard<mutex> l1(thread_info_mutex); if(thread_info==local_thread_info) { thread_info.reset(); @@ -296,17 +293,14 @@ namespace boost bool thread::joinable() const { - return get_thread_info(); + return (get_thread_info)(); } void thread::detach() { detail::thread_data_ptr local_thread_info; - { - lock_guard<mutex> l1(thread_info_mutex); - thread_info.swap(local_thread_info); - } + thread_info.swap(local_thread_info); if(local_thread_info) { @@ -381,8 +375,6 @@ namespace boost { #if defined(PTW32_VERSION) || defined(__hpux) return pthread_num_processors_np(); -#elif defined(_GNU_SOURCE) - return get_nprocs(); #elif defined(__APPLE__) || defined(__FreeBSD__) int count; size_t size=sizeof(count); @@ -390,6 +382,8 @@ namespace boost #elif defined(BOOST_HAS_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN) int const count=sysconf(_SC_NPROCESSORS_ONLN); return (count>0)?count:0; +#elif defined(_GNU_SOURCE) + return get_nprocs(); #else return 0; #endif @@ -397,7 +391,7 @@ namespace boost thread::id thread::get_id() const { - detail::thread_data_ptr const local_thread_info=get_thread_info(); + detail::thread_data_ptr const local_thread_info=(get_thread_info)(); if(local_thread_info) { return id(local_thread_info); @@ -410,13 +404,14 @@ namespace boost void thread::interrupt() { - detail::thread_data_ptr const local_thread_info=get_thread_info(); + detail::thread_data_ptr const local_thread_info=(get_thread_info)(); if(local_thread_info) { lock_guard<mutex> lk(local_thread_info->data_mutex); local_thread_info->interrupt_requested=true; if(local_thread_info->current_cond) { + boost::pthread::pthread_mutex_scoped_lock internal_lock(local_thread_info->cond_mutex); BOOST_VERIFY(!pthread_cond_broadcast(local_thread_info->current_cond)); } } @@ -424,7 +419,7 @@ namespace boost bool thread::interruption_requested() const { - detail::thread_data_ptr const local_thread_info=get_thread_info(); + detail::thread_data_ptr const local_thread_info=(get_thread_info)(); if(local_thread_info) { lock_guard<mutex> lk(local_thread_info->data_mutex); @@ -438,7 +433,7 @@ namespace boost thread::native_handle_type thread::native_handle() { - detail::thread_data_ptr const local_thread_info=get_thread_info(); + detail::thread_data_ptr const local_thread_info=(get_thread_info)(); if(local_thread_info) { lock_guard<mutex> lk(local_thread_info->data_mutex); @@ -582,11 +577,11 @@ namespace boost { if(tss_data_node* const current_node=find_tss_data(key)) { - if(cleanup_existing && current_node->func && current_node->value) + if(cleanup_existing && current_node->func && (current_node->value!=0)) { (*current_node->func)(current_node->value); } - if(func || tss_data) + if(func || (tss_data!=0)) { current_node->func=func; current_node->value=tss_data; diff --git a/3rdParty/Boost/src/libs/thread/src/tss_null.cpp b/3rdParty/Boost/src/libs/thread/src/tss_null.cpp index ff13b30..e93ba0f 100644 --- a/3rdParty/Boost/src/libs/thread/src/tss_null.cpp +++ b/3rdParty/Boost/src/libs/thread/src/tss_null.cpp @@ -8,13 +8,15 @@ #if defined(BOOST_HAS_WINTHREADS) && (defined(BOOST_THREAD_BUILD_LIB) || defined(BOOST_THREAD_TEST) || defined(UNDER_CE)) && (!defined(_MSC_VER) || defined(UNDER_CE)) +namespace boost +{ /* This file is a "null" implementation of tss cleanup; it's purpose is to to eliminate link errors in cases where it is known that tss cleanup is not needed. */ - extern "C" void tss_cleanup_implemented(void) + void tss_cleanup_implemented(void) { /* This function's sole purpose is to cause a link error in cases where @@ -30,5 +32,7 @@ longer needed and can be removed. */ } + +} #endif //defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_LIB) && !defined(_MSC_VER) diff --git a/3rdParty/Boost/src/libs/thread/src/win32/thread.cpp b/3rdParty/Boost/src/libs/thread/src/win32/thread.cpp index b85e650..05c7a6c 100644 --- a/3rdParty/Boost/src/libs/thread/src/win32/thread.cpp +++ b/3rdParty/Boost/src/libs/thread/src/win32/thread.cpp @@ -56,7 +56,10 @@ namespace boost void set_current_thread_data(detail::thread_data_base* new_data) { boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key); - BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data)); + if(current_thread_tls_key) + BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data)); + else + boost::throw_exception(thread_resource_error()); } #ifdef BOOST_NO_THREADEX @@ -221,7 +224,15 @@ namespace boost void make_external_thread_data() { externally_launched_thread* me=detail::heap_new<externally_launched_thread>(); - set_current_thread_data(me); + try + { + set_current_thread_data(me); + } + catch(...) + { + detail::heap_delete(me); + throw; + } } detail::thread_data_base* get_or_make_current_thread_data() @@ -244,17 +255,17 @@ namespace boost thread::id thread::get_id() const { - return thread::id(get_thread_info()); + return thread::id((get_thread_info)()); } bool thread::joinable() const { - return get_thread_info(); + return (get_thread_info)(); } void thread::join() { - detail::thread_data_ptr local_thread_info=get_thread_info(); + detail::thread_data_ptr local_thread_info=(get_thread_info)(); if(local_thread_info) { this_thread::interruptible_wait(local_thread_info->thread_handle,detail::timeout::sentinel()); @@ -264,7 +275,7 @@ namespace boost bool thread::timed_join(boost::system_time const& wait_until) { - detail::thread_data_ptr local_thread_info=get_thread_info(); + detail::thread_data_ptr local_thread_info=(get_thread_info)(); if(local_thread_info) { if(!this_thread::interruptible_wait(local_thread_info->thread_handle,get_milliseconds_until(wait_until))) @@ -283,13 +294,12 @@ namespace boost void thread::release_handle() { - lock_guard<mutex> l1(thread_info_mutex); thread_info=0; } void thread::interrupt() { - detail::thread_data_ptr local_thread_info=get_thread_info(); + detail::thread_data_ptr local_thread_info=(get_thread_info)(); if(local_thread_info) { local_thread_info->interrupt(); @@ -298,26 +308,25 @@ namespace boost bool thread::interruption_requested() const { - detail::thread_data_ptr local_thread_info=get_thread_info(); + detail::thread_data_ptr local_thread_info=(get_thread_info)(); return local_thread_info.get() && (detail::win32::WaitForSingleObject(local_thread_info->interruption_handle,0)==0); } unsigned thread::hardware_concurrency() { - SYSTEM_INFO info={0}; + SYSTEM_INFO info={{0}}; GetSystemInfo(&info); return info.dwNumberOfProcessors; } thread::native_handle_type thread::native_handle() { - detail::thread_data_ptr local_thread_info=get_thread_info(); + detail::thread_data_ptr local_thread_info=(get_thread_info)(); return local_thread_info?(detail::win32::handle)local_thread_info->thread_handle:detail::win32::invalid_handle_value; } - detail::thread_data_ptr thread::get_thread_info() const + detail::thread_data_ptr thread::get_thread_info BOOST_PREVENT_MACRO_SUBSTITUTION () const { - boost::mutex::scoped_lock l(thread_info_mutex); return thread_info; } @@ -327,7 +336,7 @@ namespace boost { LARGE_INTEGER get_due_time(detail::timeout const& target_time) { - LARGE_INTEGER due_time={0}; + LARGE_INTEGER due_time={{0}}; if(target_time.relative) { unsigned long const elapsed_milliseconds=GetTickCount()-target_time.start; @@ -356,7 +365,23 @@ namespace boost else { long const hundred_nanoseconds_in_one_second=10000000; - due_time.QuadPart+=target_time.abs_time.time_of_day().fractional_seconds()*(hundred_nanoseconds_in_one_second/target_time.abs_time.time_of_day().ticks_per_second()); + posix_time::time_duration::tick_type const ticks_per_second= + target_time.abs_time.time_of_day().ticks_per_second(); + if(ticks_per_second>hundred_nanoseconds_in_one_second) + { + posix_time::time_duration::tick_type const + ticks_per_hundred_nanoseconds= + ticks_per_second/hundred_nanoseconds_in_one_second; + due_time.QuadPart+= + target_time.abs_time.time_of_day().fractional_seconds()/ + ticks_per_hundred_nanoseconds; + } + else + { + due_time.QuadPart+= + target_time.abs_time.time_of_day().fractional_seconds()* + (hundred_nanoseconds_in_one_second/ticks_per_second); + } } } return due_time; @@ -526,8 +551,8 @@ namespace boost { detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data()); thread_exit_callback_node* const new_node= - heap_new<thread_exit_callback_node>(func, - current_thread_data->thread_exit_callbacks); + heap_new<thread_exit_callback_node>( + func,current_thread_data->thread_exit_callbacks); current_thread_data->thread_exit_callbacks=new_node; } @@ -569,30 +594,31 @@ namespace boost current_node->func=func; current_node->value=tss_data; } - else + else if(func && tss_data) { detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data()); - tss_data_node* const new_node=heap_new<tss_data_node>(key,func,tss_data,current_thread_data->tss_data); + tss_data_node* const new_node= + heap_new<tss_data_node>(key,func,tss_data,current_thread_data->tss_data); current_thread_data->tss_data=new_node; } } } -} + BOOST_THREAD_DECL void __cdecl on_process_enter() + {} + BOOST_THREAD_DECL void __cdecl on_thread_enter() + {} -extern "C" BOOST_THREAD_DECL void on_process_enter() -{} + BOOST_THREAD_DECL void __cdecl on_process_exit() + { + boost::cleanup_tls_key(); + } -extern "C" BOOST_THREAD_DECL void on_thread_enter() -{} + BOOST_THREAD_DECL void __cdecl on_thread_exit() + { + boost::run_thread_exit_callbacks(); + } -extern "C" BOOST_THREAD_DECL void on_process_exit() -{ - boost::cleanup_tls_key(); } -extern "C" BOOST_THREAD_DECL void on_thread_exit() -{ - boost::run_thread_exit_callbacks(); -} diff --git a/3rdParty/Boost/src/libs/thread/src/win32/tss_dll.cpp b/3rdParty/Boost/src/libs/thread/src/win32/tss_dll.cpp index 0522a12..9699a12 100644 --- a/3rdParty/Boost/src/libs/thread/src/win32/tss_dll.cpp +++ b/3rdParty/Boost/src/libs/thread/src/win32/tss_dll.cpp @@ -24,27 +24,27 @@ { case DLL_PROCESS_ATTACH: { - on_process_enter(); - on_thread_enter(); + boost::on_process_enter(); + boost::on_thread_enter(); break; } case DLL_THREAD_ATTACH: { - on_thread_enter(); + boost::on_thread_enter(); break; } case DLL_THREAD_DETACH: { - on_thread_exit(); + boost::on_thread_exit(); break; } case DLL_PROCESS_DETACH: { - on_thread_exit(); - on_process_exit(); + boost::on_thread_exit(); + boost::on_process_exit(); break; } } @@ -52,7 +52,9 @@ return TRUE; } - extern "C" void tss_cleanup_implemented(void) +namespace boost +{ + void tss_cleanup_implemented() { /* This function's sole purpose is to cause a link error in cases where @@ -68,5 +70,7 @@ longer needed and can be removed. */ } +} + #endif //defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_DLL) diff --git a/3rdParty/Boost/src/libs/thread/src/win32/tss_pe.cpp b/3rdParty/Boost/src/libs/thread/src/win32/tss_pe.cpp index ae89bc4..8ef045b 100644 --- a/3rdParty/Boost/src/libs/thread/src/win32/tss_pe.cpp +++ b/3rdParty/Boost/src/libs/thread/src/win32/tss_pe.cpp @@ -1,4 +1,4 @@ -// $Id: tss_pe.cpp 49324 2008-10-13 20:30:13Z anthonyw $ +// $Id: tss_pe.cpp 66259 2010-10-29 23:27:00Z anthonyw $ // (C) Copyright Aaron W. LaFramboise, Roland Schwarz, Michael Glassford 2004. // (C) Copyright 2007 Roland Schwarz // (C) Copyright 2007 Anthony Williams @@ -19,7 +19,10 @@ #include <cstdlib> -extern "C" void tss_cleanup_implemented(void) {} +namespace boost +{ + void tss_cleanup_implemented() {} +} namespace { void NTAPI on_tls_callback(void* h, DWORD dwReason, PVOID pv) @@ -28,33 +31,24 @@ namespace { { case DLL_THREAD_DETACH: { - on_thread_exit(); + boost::on_thread_exit(); break; } } } - - void on_after_ctors(void) - { - on_process_enter(); - } - - void on_before_dtors(void) - { - on_thread_exit(); - } - - void on_after_dtors(void) - { - on_process_exit(); - } } +#if (__MINGW32_MAJOR_VERSION >3) || ((__MINGW32_MAJOR_VERSION==3) && (__MINGW32_MINOR_VERSION>=18)) +extern "C" +{ + PIMAGE_TLS_CALLBACK __crt_xl_tls_callback__ __attribute__ ((section(".CRT$XLB"))) = on_tls_callback; +} +#else extern "C" { - void (* after_ctors )(void) __attribute__((section(".ctors"))) = on_after_ctors; - void (* before_dtors)(void) __attribute__((section(".dtors"))) = on_before_dtors; - void (* after_dtors )(void) __attribute__((section(".dtors.zzz"))) = on_after_dtors; + void (* after_ctors )() __attribute__((section(".ctors"))) = boost::on_process_enter; + void (* before_dtors)() __attribute__((section(".dtors"))) = boost::on_thread_exit; + void (* after_dtors )() __attribute__((section(".dtors.zzz"))) = boost::on_process_exit; ULONG __tls_index__ = 0; char __tls_end__ __attribute__((section(".tls$zzz"))) = 0; @@ -62,10 +56,8 @@ extern "C" { PIMAGE_TLS_CALLBACK __crt_xl_start__ __attribute__ ((section(".CRT$XLA"))) = 0; - PIMAGE_TLS_CALLBACK __crt_xl_tls_callback__ __attribute__ ((section(".CRT$XLB"))) = on_tls_callback; PIMAGE_TLS_CALLBACK __crt_xl_end__ __attribute__ ((section(".CRT$XLZ"))) = 0; } - extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata$T"))) = { (DWORD) &__tls_start__, @@ -75,6 +67,7 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata (DWORD) 0, (DWORD) 0 }; +#endif #elif defined(_MSC_VER) && !defined(UNDER_CE) @@ -89,13 +82,13 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata //Definitions required by implementation #if (_MSC_VER < 1300) // 1300 == VC++ 7.0 - typedef void (__cdecl *_PVFV)(void); + typedef void (__cdecl *_PVFV)(); #define INIRETSUCCESS - #define PVAPI void + #define PVAPI void __cdecl #else - typedef int (__cdecl *_PVFV)(void); + typedef int (__cdecl *_PVFV)(); #define INIRETSUCCESS 0 - #define PVAPI int + #define PVAPI int __cdecl #endif typedef void (NTAPI* _TLSCB)(HINSTANCE, DWORD, PVOID); @@ -112,9 +105,9 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata { //Forward declarations - static PVAPI on_tls_prepare(void); - static PVAPI on_process_init(void); - static PVAPI on_process_term(void); + static PVAPI on_tls_prepare(); + static PVAPI on_process_init(); + static PVAPI on_process_term(); static void NTAPI on_tls_callback(HINSTANCE, DWORD, PVOID); //The .CRT$Xxx information is taken from Codeguru: @@ -169,7 +162,7 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata #pragma warning(disable:4189) #endif - PVAPI on_tls_prepare(void) + PVAPI on_tls_prepare() { //The following line has an important side effect: //if the TLS directory is not already there, it will @@ -210,7 +203,7 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata #pragma warning(pop) #endif - PVAPI on_process_init(void) + PVAPI on_process_init() { //Schedule on_thread_exit() to be called for the main //thread before destructors of global objects have been @@ -221,18 +214,18 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata //for destructors of global objects, so that //shouldn't be a problem. - atexit(on_thread_exit); + atexit(boost::on_thread_exit); //Call Boost process entry callback here - on_process_enter(); + boost::on_process_enter(); return INIRETSUCCESS; } - PVAPI on_process_term(void) + PVAPI on_process_term() { - on_process_exit(); + boost::on_process_exit(); return INIRETSUCCESS; } @@ -241,7 +234,7 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata switch (dwReason) { case DLL_THREAD_DETACH: - on_thread_exit(); + boost::on_thread_exit(); break; } } @@ -251,10 +244,10 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata switch (dwReason) { case DLL_THREAD_DETACH: - on_thread_exit(); + boost::on_thread_exit(); break; case DLL_PROCESS_DETACH: - on_process_exit(); + boost::on_process_exit(); break; } return true; @@ -265,8 +258,9 @@ extern "C" { extern BOOL (WINAPI * const _pRawDllMain)(HANDLE, DWORD, LPVOID)=&dll_callback; } - - extern "C" void tss_cleanup_implemented(void) +namespace boost +{ + void tss_cleanup_implemented() { /* This function's sole purpose is to cause a link error in cases where @@ -282,6 +276,8 @@ extern "C" longer needed and can be removed. */ } +} + #endif //defined(_MSC_VER) && !defined(UNDER_CE) #endif //defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_LIB) |