Commit 2913770f by Stefan Olsson Committed by Benjamin Kosnik

mt_allocator.h: Reuse thread id's as soon as possible by changing the behaviour of...


2004-01-15  Stefan Olsson  <stefan@snon.net>

	* include/ext/mt_allocator.h: Reuse thread id's as soon as
	possible by changing the behaviour of thread_freelist to do
	push_front when threads die instead of push_back.

From-SVN: r75939
parent ecc74832
2004-01-15 Stefan Olsson <stefan@snon.net>
* include/ext/mt_allocator.h: Reuse thread id's as soon as
possible by changing the behaviour of thread_freelist to do
push_front when threads die instead of push_back.
2004-01-14 Paolo Carlini <pcarlini@suse.de> 2004-01-14 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.h (struct __numpunct_cache): * include/bits/locale_facets.h (struct __numpunct_cache):
......
...@@ -122,7 +122,7 @@ namespace __gnu_cxx ...@@ -122,7 +122,7 @@ namespace __gnu_cxx
#ifdef __GTHREADS #ifdef __GTHREADS
static __gthread_once_t _S_once_mt; static __gthread_once_t _S_once_mt;
#endif #endif
static bool _S_initialized; static bool volatile _S_initialized;
/* /*
* Using short int as type for the binmap implies we are never caching * Using short int as type for the binmap implies we are never caching
...@@ -151,7 +151,7 @@ namespace __gnu_cxx ...@@ -151,7 +151,7 @@ namespace __gnu_cxx
* memory we remove the first record in this list and stores the address * memory we remove the first record in this list and stores the address
* in a __gthread_key. When initializing the __gthread_key * in a __gthread_key. When initializing the __gthread_key
* we specify a destructor. When this destructor (i.e. the thread dies) * we specify a destructor. When this destructor (i.e. the thread dies)
* is called, we return the thread id to the back of this list. * is called, we return the thread id to the front of this list.
*/ */
#ifdef __GTHREADS #ifdef __GTHREADS
struct thread_record struct thread_record
...@@ -159,7 +159,7 @@ namespace __gnu_cxx ...@@ -159,7 +159,7 @@ namespace __gnu_cxx
/* /*
* Points to next free thread id record. NULL if last record in list. * Points to next free thread id record. NULL if last record in list.
*/ */
thread_record* next; thread_record* volatile next;
/* /*
* Thread id ranging from 1 to _S_max_threads. * Thread id ranging from 1 to _S_max_threads.
...@@ -167,8 +167,7 @@ namespace __gnu_cxx ...@@ -167,8 +167,7 @@ namespace __gnu_cxx
size_t id; size_t id;
}; };
static thread_record* _S_thread_freelist_first; static thread_record* volatile _S_thread_freelist_first;
static thread_record* _S_thread_freelist_last;
static __gthread_mutex_t _S_thread_freelist_mutex; static __gthread_mutex_t _S_thread_freelist_mutex;
static void _S_thread_key_destr(void* freelist_pos); static void _S_thread_key_destr(void* freelist_pos);
static __gthread_key_t _S_thread_key; static __gthread_key_t _S_thread_key;
...@@ -412,7 +411,7 @@ namespace __gnu_cxx ...@@ -412,7 +411,7 @@ namespace __gnu_cxx
{ {
free(__p); free(__p);
return; return;
} }
/* /*
* Round up to power of 2 and figure out which bin to use * Round up to power of 2 and figure out which bin to use
...@@ -599,11 +598,10 @@ namespace __gnu_cxx ...@@ -599,11 +598,10 @@ namespace __gnu_cxx
} }
/* /*
* Set last record and pointer to this * Set last record
*/ */
_S_thread_freelist_first[i - 1].next = NULL; _S_thread_freelist_first[i - 1].next = NULL;
_S_thread_freelist_first[i - 1].id = i; _S_thread_freelist_first[i - 1].id = i;
_S_thread_freelist_last = &_S_thread_freelist_first[i - 1];
/* /*
* Initialize per thread key to hold pointer to * Initialize per thread key to hold pointer to
...@@ -708,12 +706,11 @@ namespace __gnu_cxx ...@@ -708,12 +706,11 @@ namespace __gnu_cxx
} }
/* /*
* Return this thread id record to thread_freelist * Return this thread id record to front of thread_freelist
*/ */
__gthread_mutex_lock(&_S_thread_freelist_mutex); __gthread_mutex_lock(&_S_thread_freelist_mutex);
_S_thread_freelist_last->next = (thread_record*)freelist_pos; ((thread_record*)freelist_pos)->next = _S_thread_freelist_first;
_S_thread_freelist_last = (thread_record*)freelist_pos; _S_thread_freelist_first = (thread_record*)freelist_pos;
_S_thread_freelist_last->next = NULL;
__gthread_mutex_unlock(&_S_thread_freelist_mutex); __gthread_mutex_unlock(&_S_thread_freelist_mutex);
} }
...@@ -730,7 +727,7 @@ namespace __gnu_cxx ...@@ -730,7 +727,7 @@ namespace __gnu_cxx
*/ */
if (__gthread_active_p()) if (__gthread_active_p())
{ {
thread_record* freelist_pos; thread_record* volatile freelist_pos;
if ((freelist_pos = if ((freelist_pos =
(thread_record*)__gthread_getspecific(_S_thread_key)) == NULL) (thread_record*)__gthread_getspecific(_S_thread_key)) == NULL)
...@@ -778,7 +775,7 @@ namespace __gnu_cxx ...@@ -778,7 +775,7 @@ namespace __gnu_cxx
#endif #endif
template<typename _Tp> bool template<typename _Tp> bool
__mt_alloc<_Tp>::_S_initialized = false; volatile __mt_alloc<_Tp>::_S_initialized = false;
template<typename _Tp> typename __mt_alloc<_Tp>::binmap_type* template<typename _Tp> typename __mt_alloc<_Tp>::binmap_type*
__mt_alloc<_Tp>::_S_binmap = NULL; __mt_alloc<_Tp>::_S_binmap = NULL;
...@@ -829,10 +826,7 @@ namespace __gnu_cxx ...@@ -829,10 +826,7 @@ namespace __gnu_cxx
*/ */
#ifdef __GTHREADS #ifdef __GTHREADS
template<typename _Tp> typename __mt_alloc<_Tp>::thread_record* template<typename _Tp> typename __mt_alloc<_Tp>::thread_record*
__mt_alloc<_Tp>::_S_thread_freelist_first = NULL; volatile __mt_alloc<_Tp>::_S_thread_freelist_first = NULL;
template<typename _Tp> typename __mt_alloc<_Tp>::thread_record*
__mt_alloc<_Tp>::_S_thread_freelist_last = NULL;
template<typename _Tp> __gthread_mutex_t template<typename _Tp> __gthread_mutex_t
__mt_alloc<_Tp>::_S_thread_freelist_mutex = __GTHREAD_MUTEX_INIT; __mt_alloc<_Tp>::_S_thread_freelist_mutex = __GTHREAD_MUTEX_INIT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment