2
0
mirror of https://github.com/boostorg/thread.git synced 2026-01-29 20:12:10 +00:00

Add automatic tss cleanup to statically linked Win32 Boost.Threads library (currently works only for VC++ 7.1).

[SVN r24235]
This commit is contained in:
Michael Glassford
2004-08-01 17:26:45 +00:00
parent cebaf27ee8
commit 8fc3d1f718
2 changed files with 52 additions and 0 deletions

45
src/pe_tls.ipp Normal file
View File

@@ -0,0 +1,45 @@
// (C) Copyright Aaron W. LaFramboise 2004.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
extern "C" void tss_cleanup_implemented(void)
{
//Don't need to do anything; this function's
//sole purpose is to cause a link error in cases
//where tss cleanup is not implemented by Boost.Threads
//as a reminder that user code is responsible for calling
//on_process_enter(), on_thread_exit(), and
//on_process_exit() at the appropriate times
//and implementing an empty tss_cleanup_implemented()
//function to eliminate the link error.
}
//Force a TLS directory to be generated even when static TLS is not used.
extern "C" int _tls_used;
int dummy()
{
return _tls_used;
}
//Report thread and process detach events.
void NTAPI tls_callback (PVOID, DWORD Reason, PVOID)
{
if(Reason == DLL_THREAD_DETACH)
on_thread_exit();
else if(Reason == DLL_PROCESS_DETACH)
{
on_thread_exit();
on_process_exit();
}
}
// Add callback to the TLS callback list in TLS directory.
#pragma data_seg(push, old_seg)
#pragma data_seg(".CRT$XLB")
DWORD tls_callback_ptr = (DWORD)tls_callback;
#pragma data_seg(pop, old_seg)

View File

@@ -176,6 +176,13 @@
}
return TRUE;
}
#elif defined(BOOST_THREAD_BUILD_LIB)
#if defined(BOOST_MSVC) && (BOOST_MSVC >= 1310) //1310 == VC++ 7.1
//As currently defined, the following is known
//to work only for VC++ 7.1.
//It is known not to work with VC 6.
#include <libs/thread/src/pe_tls.ipp>
#endif
#endif // BOOST_THREAD_BUILD_DLL
#endif // BOOST_HAS_WINTHREADS