|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53389 - in trunk: boost/thread/pthread libs/thread/src/pthread
From: anthony_at_[hidden]
Date: 2009-05-29 07:34:26
Author: anthonyw
Date: 2009-05-29 07:34:25 EDT (Fri, 29 May 2009)
New Revision: 53389
URL: http://svn.boost.org/trac/boost/changeset/53389
Log:
Changed thread_specific_ptr to use a map for faster lookup, and erase empty nodes
Text files modified:
trunk/boost/thread/pthread/thread_data.hpp | 17 +++++++-
trunk/libs/thread/src/pthread/thread.cpp | 74 ++++++++++++++++++++++-----------------
2 files changed, 55 insertions(+), 36 deletions(-)
Modified: trunk/boost/thread/pthread/thread_data.hpp
==============================================================================
--- trunk/boost/thread/pthread/thread_data.hpp (original)
+++ trunk/boost/thread/pthread/thread_data.hpp 2009-05-29 07:34:25 EDT (Fri, 29 May 2009)
@@ -13,6 +13,7 @@
#include <boost/optional.hpp>
#include <pthread.h>
#include "condition_variable_fwd.hpp"
+#include <map>
#include <boost/config/abi_prefix.hpp>
@@ -22,8 +23,18 @@
namespace detail
{
+ struct tss_cleanup_function;
struct thread_exit_callback_node;
- struct tss_data_node;
+ struct tss_data_node
+ {
+ boost::shared_ptr<boost::detail::tss_cleanup_function> func;
+ void* value;
+
+ tss_data_node(boost::shared_ptr<boost::detail::tss_cleanup_function> func_,
+ void* value_):
+ func(func_),value(value_)
+ {}
+ };
struct thread_data_base;
typedef boost::shared_ptr<thread_data_base> thread_data_ptr;
@@ -41,14 +52,14 @@
bool join_started;
bool joined;
boost::detail::thread_exit_callback_node* thread_exit_callbacks;
- boost::detail::tss_data_node* tss_data;
+ std::map<void const*,boost::detail::tss_data_node> tss_data;
bool interrupt_enabled;
bool interrupt_requested;
pthread_cond_t* current_cond;
thread_data_base():
done(false),join_started(false),joined(false),
- thread_exit_callbacks(0),tss_data(0),
+ thread_exit_callbacks(0),
interrupt_enabled(true),
interrupt_requested(false),
current_cond(0)
Modified: trunk/libs/thread/src/pthread/thread.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/thread.cpp (original)
+++ trunk/libs/thread/src/pthread/thread.cpp 2009-05-29 07:34:25 EDT (Fri, 29 May 2009)
@@ -42,19 +42,6 @@
{}
};
- struct tss_data_node
- {
- void const* key;
- boost::shared_ptr<boost::detail::tss_cleanup_function> func;
- void* value;
- tss_data_node* next;
-
- tss_data_node(void const* key_,boost::shared_ptr<boost::detail::tss_cleanup_function> func_,void* value_,
- tss_data_node* next_):
- key(key_),func(func_),value(value_),next(next_)
- {}
- };
-
namespace
{
boost::once_flag current_thread_tls_init_flag=BOOST_ONCE_INIT;
@@ -67,7 +54,7 @@
boost::detail::thread_data_base* thread_info=static_cast<boost::detail::thread_data_base*>(data);
if(thread_info)
{
- while(thread_info->tss_data || thread_info->thread_exit_callbacks)
+ while(!thread_info->tss_data.empty() || thread_info->thread_exit_callbacks)
{
while(thread_info->thread_exit_callbacks)
{
@@ -80,15 +67,18 @@
}
delete current_node;
}
- while(thread_info->tss_data)
+ for(std::map<void const*,tss_data_node>::iterator next=thread_info->tss_data.begin(),
+ current,
+ end=thread_info->tss_data.end();
+ next!=end;)
{
- detail::tss_data_node* const current_node=thread_info->tss_data;
- thread_info->tss_data=current_node->next;
- if(current_node->func)
+ current=next;
+ ++next;
+ if(current->second.func && current->second.value)
{
- (*current_node->func)(current_node->value);
+ (*current->second.func)(current->second.value);
}
- delete current_node;
+ thread_info->tss_data.erase(current);
}
}
thread_info->self.reset();
@@ -552,14 +542,11 @@
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)
+ std::map<void const*,tss_data_node>::iterator current_node=
+ current_thread_data->tss_data.find(key);
+ if(current_node!=current_thread_data->tss_data.end())
{
- if(current_node->key==key)
- {
- return current_node;
- }
- current_node=current_node->next;
+ return ¤t_node->second;
}
}
return NULL;
@@ -573,8 +560,24 @@
}
return NULL;
}
+
+ void add_new_tss_node(void const* key,
+ boost::shared_ptr<tss_cleanup_function> func,
+ void* tss_data)
+ {
+ detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
+ current_thread_data->tss_data.insert(std::make_pair(key,tss_data_node(func,tss_data)));
+ }
+
+ void erase_tss_node(void const* key)
+ {
+ detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
+ current_thread_data->tss_data.erase(key);
+ }
- void set_tss_data(void const* key,boost::shared_ptr<tss_cleanup_function> func,void* tss_data,bool cleanup_existing)
+ void set_tss_data(void const* key,
+ boost::shared_ptr<tss_cleanup_function> func,
+ void* tss_data,bool cleanup_existing)
{
if(tss_data_node* const current_node=find_tss_data(key))
{
@@ -582,14 +585,19 @@
{
(*current_node->func)(current_node->value);
}
- current_node->func=func;
- current_node->value=tss_data;
+ if(func || tss_data)
+ {
+ current_node->func=func;
+ current_node->value=tss_data;
+ }
+ else
+ {
+ erase_tss_node(key);
+ }
}
else
{
- detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
- tss_data_node* const new_node=new tss_data_node(key,func,tss_data,current_thread_data->tss_data);
- current_thread_data->tss_data=new_node;
+ add_new_tss_node(key,func,tss_data);
}
}
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk