mirror of
https://github.com/boostorg/thread.git
synced 2026-02-09 23:42:18 +00:00
Merged revisions 41023-41071 via svnmerge from
https://svn.boost.org/svn/boost/trunk ........ r41026 | johnmaddock | 2007-11-12 02:00:46 -0800 (Mon, 12 Nov 2007) | 1 line Adjust test logic to cope with compilers that don't underflow constants to zero when they should. ........ r41027 | burbelgruff | 2007-11-12 03:10:20 -0800 (Mon, 12 Nov 2007) | 1 line #1425 Support for Visual Studio 2008 ........ r41028 | chris_kohlhoff | 2007-11-12 04:07:39 -0800 (Mon, 12 Nov 2007) | 5 lines Cannot perform concurrent operations on the /dev/poll descriptor where the sockets descriptors involved may already be being waited on. Changed the dev_poll_reactor class to keep a vector of pending event changes and interrupt the /dev/poll ioctl() wait to apply it. ........ r41029 | garcia | 2007-11-12 05:00:41 -0800 (Mon, 12 Nov 2007) | 2 lines added a reviewer for singleton. ........ r41030 | garcia | 2007-11-12 05:04:16 -0800 (Mon, 12 Nov 2007) | 2 lines Removed review dates that passed without happening. ........ r41033 | bemandawes | 2007-11-12 07:22:24 -0800 (Mon, 12 Nov 2007) | 2 lines Add separate headers for system-specific enums, thus reducing coupling. Suggested by Emil Dotchevski. ........ r41036 | bgubenko | 2007-11-12 09:03:38 -0800 (Mon, 12 Nov 2007) | 1 line add -fno-strict-aliasing to compilation with gcc ........ r41038 | johnmaddock | 2007-11-12 09:21:47 -0800 (Mon, 12 Nov 2007) | 1 line Disable long double tests if there are no long double math functions. ........ r41040 | bemandawes | 2007-11-12 09:42:42 -0800 (Mon, 12 Nov 2007) | 1 line Include system-specific headers, change namespaces accordingly. ........ r41043 | eric_niebler | 2007-11-12 13:07:54 -0800 (Mon, 12 Nov 2007) | 1 line minor clean-up ........ r41046 | bemandawes | 2007-11-12 14:29:48 -0800 (Mon, 12 Nov 2007) | 1 line Change default to --v2 ........ r41048 | noel_belcourt | 2007-11-12 14:52:12 -0800 (Mon, 12 Nov 2007) | 3 lines Get the unix timing working correctly. ........ r41050 | bgubenko | 2007-11-12 16:51:37 -0800 (Mon, 12 Nov 2007) | 1 line when setting OSPLAT, check __ia64 macro ........ r41052 | bemandawes | 2007-11-12 18:54:32 -0800 (Mon, 12 Nov 2007) | 1 line Add tests for, and fix, current_path overloading. ........ r41054 | vladimir_prus | 2007-11-12 23:54:20 -0800 (Mon, 12 Nov 2007) | 1 line Add Google Analytics tracking code ........ r41056 | anthonyw | 2007-11-13 01:27:11 -0800 (Tue, 13 Nov 2007) | 1 line Integrated TSS with storage of thread data; cleaned up the heap allocation functions to throw bad_alloc if they run out of memory ........ r41057 | danieljames | 2007-11-13 03:51:23 -0800 (Tue, 13 Nov 2007) | 1 line Don't use fpclass because it causes a warning for long doubles. I don't know if the warning is vaild here - but I don't want to disable it as it's useful for checking other function calls. ........ r41059 | chris_kohlhoff | 2007-11-13 04:50:27 -0800 (Tue, 13 Nov 2007) | 6 lines Add a workaround for MSVC secure iterator problem where allowing the destruction of an iterator to an already-destroyed string object results in a program crash. Revert previous change to destroy buffers prior to invoking the handler since it didn't fix the problem and wasn't cleaning up all copies of the buffers anyway. ........ r41060 | bemandawes | 2007-11-13 05:54:58 -0800 (Tue, 13 Nov 2007) | 1 line Correct detection of failure to run in a boost tree, and refactor code as a separate set_boost_root function. ........ r41062 | johnmaddock | 2007-11-13 08:15:27 -0800 (Tue, 13 Nov 2007) | 1 line Ooops, disable long double overloads when there is no long double support (Borland fix). ........ r41063 | eric_niebler | 2007-11-13 08:38:11 -0800 (Tue, 13 Nov 2007) | 1 line portability fix for Intel 8.1 ........ r41064 | johnmaddock | 2007-11-13 09:15:29 -0800 (Tue, 13 Nov 2007) | 1 line Updated compiler status, and regenerated docs. ........ r41069 | davedeakins | 2007-11-13 12:19:39 -0800 (Tue, 13 Nov 2007) | 1 line Have the local_time and universal_time functions use GetSystemTime and SystemTimeToFileTime on Windows CE (since GetSystemTimeAsFileTime is not present) ........ [SVN r41072]
This commit is contained in:
@@ -12,7 +12,9 @@
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <boost/thread/once.hpp>
|
||||
#include <boost/thread/tss.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/thread/detail/tss_hooks.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -130,6 +132,19 @@ namespace boost
|
||||
{}
|
||||
};
|
||||
|
||||
struct tss_data_node
|
||||
{
|
||||
void const* key;
|
||||
boost::detail::tss_cleanup_function func;
|
||||
void* value;
|
||||
tss_data_node* next;
|
||||
|
||||
tss_data_node(void const* key_,boost::detail::tss_cleanup_function func_,void* value_,
|
||||
tss_data_node* next_):
|
||||
key(key_),func(func_),value(value_),next(next_)
|
||||
{}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace
|
||||
@@ -139,17 +154,31 @@ namespace boost
|
||||
boost::intrusive_ptr<detail::thread_data_base> current_thread_data(get_current_thread_data(),false);
|
||||
if(current_thread_data)
|
||||
{
|
||||
while(current_thread_data->thread_exit_callbacks)
|
||||
while(current_thread_data->tss_data || current_thread_data->thread_exit_callbacks)
|
||||
{
|
||||
detail::thread_exit_callback_node* const current_node=current_thread_data->thread_exit_callbacks;
|
||||
current_thread_data->thread_exit_callbacks=current_node->next;
|
||||
if(current_node->func)
|
||||
while(current_thread_data->thread_exit_callbacks)
|
||||
{
|
||||
(*current_node->func)();
|
||||
boost::detail::heap_delete(current_node->func);
|
||||
detail::thread_exit_callback_node* const current_node=current_thread_data->thread_exit_callbacks;
|
||||
current_thread_data->thread_exit_callbacks=current_node->next;
|
||||
if(current_node->func)
|
||||
{
|
||||
(*current_node->func)();
|
||||
boost::detail::heap_delete(current_node->func);
|
||||
}
|
||||
boost::detail::heap_delete(current_node);
|
||||
}
|
||||
while(current_thread_data->tss_data)
|
||||
{
|
||||
detail::tss_data_node* const current_node=current_thread_data->tss_data;
|
||||
current_thread_data->tss_data=current_node->next;
|
||||
if(current_node->func)
|
||||
{
|
||||
(*current_node->func)(current_node->key,current_node->value);
|
||||
}
|
||||
boost::detail::heap_delete(current_node);
|
||||
}
|
||||
boost::detail::heap_delete(current_node);
|
||||
}
|
||||
|
||||
}
|
||||
set_current_thread_data(0);
|
||||
}
|
||||
@@ -210,14 +239,20 @@ namespace boost
|
||||
void run()
|
||||
{}
|
||||
};
|
||||
|
||||
void make_external_thread_data()
|
||||
{
|
||||
externally_launched_thread* me=detail::heap_new<externally_launched_thread>();
|
||||
set_current_thread_data(me);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
thread thread::self()
|
||||
{
|
||||
if(!get_current_thread_data())
|
||||
{
|
||||
externally_launched_thread* me=detail::heap_new<externally_launched_thread>();
|
||||
set_current_thread_data(me);
|
||||
make_external_thread_data();
|
||||
}
|
||||
return thread(boost::intrusive_ptr<detail::thread_data_base>(get_current_thread_data()));
|
||||
}
|
||||
@@ -450,49 +485,83 @@ namespace boost
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void NTAPI thread_exit_func_callback(HINSTANCE, DWORD, PVOID);
|
||||
typedef void (NTAPI* tls_callback)(HINSTANCE, DWORD, PVOID);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
extern "C"
|
||||
{
|
||||
extern DWORD _tls_used; //the tls directory (located in .rdata segment)
|
||||
extern tls_callback __xl_a[], __xl_z[]; //tls initializers */
|
||||
}
|
||||
|
||||
#if (_MSC_VER >= 1300) // 1300 == VC++ 7.0
|
||||
# pragma data_seg(push, old_seg)
|
||||
#endif
|
||||
|
||||
#pragma data_seg(".CRT$XLB")
|
||||
tls_callback p_thread_callback = thread_exit_func_callback;
|
||||
#pragma data_seg()
|
||||
|
||||
#if (_MSC_VER >= 1300) // 1300 == VC++ 7.0
|
||||
# pragma data_seg(pop, old_seg)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void NTAPI thread_exit_func_callback(HINSTANCE h, DWORD dwReason, PVOID pv)
|
||||
{
|
||||
if((dwReason==DLL_THREAD_DETACH) || (dwReason==DLL_PROCESS_DETACH))
|
||||
{
|
||||
run_thread_exit_callbacks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
void add_thread_exit_function(thread_exit_function_base* func)
|
||||
{
|
||||
detail::thread_data_base* const current_thread_data(get_current_thread_data());
|
||||
thread_exit_callback_node* const new_node=
|
||||
heap_new<thread_exit_callback_node>(func,
|
||||
get_current_thread_data()->thread_exit_callbacks);
|
||||
get_current_thread_data()->thread_exit_callbacks=new_node;
|
||||
current_thread_data->thread_exit_callbacks);
|
||||
current_thread_data->thread_exit_callbacks=new_node;
|
||||
}
|
||||
|
||||
tss_data_node* find_tss_data(void const* key)
|
||||
{
|
||||
detail::thread_data_base* const current_thread_data(get_current_thread_data());
|
||||
if(current_thread_data)
|
||||
{
|
||||
detail::tss_data_node* current_node=current_thread_data->tss_data;
|
||||
while(current_node)
|
||||
{
|
||||
if(current_node->key==key)
|
||||
{
|
||||
return current_node;
|
||||
}
|
||||
current_node=current_node->next;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* get_tss_data(void const* key)
|
||||
{
|
||||
if(tss_data_node* const current_node=find_tss_data(key))
|
||||
{
|
||||
return current_node->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void set_tss_data(void const* key,tss_cleanup_function func,void* tss_data,bool cleanup_existing)
|
||||
{
|
||||
tss_cleanup_implemented(); // if anyone uses TSS, we need the cleanup linked in
|
||||
if(tss_data_node* const current_node=find_tss_data(key))
|
||||
{
|
||||
if(cleanup_existing && current_node->func)
|
||||
{
|
||||
(current_node->func)(current_node->key,current_node->value);
|
||||
}
|
||||
current_node->func=func;
|
||||
current_node->value=tss_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
detail::thread_data_base* current_thread_data(get_current_thread_data());
|
||||
if(!current_thread_data)
|
||||
{
|
||||
make_external_thread_data();
|
||||
current_thread_data=get_current_thread_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_enter()
|
||||
{}
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_thread_enter()
|
||||
{}
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_exit()
|
||||
{}
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_thread_exit()
|
||||
{
|
||||
boost::run_thread_exit_callbacks();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user