mirror of
https://github.com/boostorg/thread.git
synced 2026-02-09 11:32:12 +00:00
Thread: Try to fix 4885 - Access violation in set_tss_data at process exit due to invalid assumption about TlsAlloc
[SVN r76752]
This commit is contained in:
@@ -27,32 +27,33 @@ namespace boost
|
||||
namespace
|
||||
{
|
||||
boost::once_flag current_thread_tls_init_flag=BOOST_ONCE_INIT;
|
||||
DWORD current_thread_tls_key=0;
|
||||
#if defined(UNDER_CE)
|
||||
// Windows CE does not define the TLS_OUT_OF_INDEXES constant.
|
||||
DWORD tls_out_of_index=0xFFFFFFFF;
|
||||
#else
|
||||
DWORD tls_out_of_index=TLS_OUT_OF_INDEXES;
|
||||
#endif
|
||||
DWORD current_thread_tls_key=tls_out_of_index;
|
||||
|
||||
void create_current_thread_tls_key()
|
||||
{
|
||||
tss_cleanup_implemented(); // if anyone uses TSS, we need the cleanup linked in
|
||||
current_thread_tls_key=TlsAlloc();
|
||||
#if defined(UNDER_CE)
|
||||
// Windows CE does not define the TLS_OUT_OF_INDEXES constant.
|
||||
BOOST_ASSERT(current_thread_tls_key!=0xFFFFFFFF);
|
||||
#else
|
||||
BOOST_ASSERT(current_thread_tls_key!=TLS_OUT_OF_INDEXES);
|
||||
#endif
|
||||
BOOST_ASSERT(current_thread_tls_key!=tls_out_of_index);
|
||||
}
|
||||
|
||||
void cleanup_tls_key()
|
||||
{
|
||||
if(current_thread_tls_key)
|
||||
if(current_thread_tls_key!=tls_out_of_index)
|
||||
{
|
||||
TlsFree(current_thread_tls_key);
|
||||
current_thread_tls_key=0;
|
||||
current_thread_tls_key=tls_out_of_index;
|
||||
}
|
||||
}
|
||||
|
||||
detail::thread_data_base* get_current_thread_data()
|
||||
{
|
||||
if(!current_thread_tls_key)
|
||||
if(current_thread_tls_key==tls_out_of_index)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -62,7 +63,7 @@ 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);
|
||||
if(current_thread_tls_key)
|
||||
if(current_thread_tls_key!=tls_out_of_index)
|
||||
BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data));
|
||||
else
|
||||
boost::throw_exception(thread_resource_error());
|
||||
|
||||
Reference in New Issue
Block a user