This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Reduce contention in __mt_alloc::deallocate
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Mon, 05 Apr 2004 10:50:11 +0200
- Subject: [Patch] Reduce contention in __mt_alloc::deallocate
Hi,
this small patch just notices that the critical section is
actually much smaller.
Tested x86/x86_64/ia64-linux, will apply later today.
Paolo.
//////////////
2004-04-05 Paolo Carlini <pcarlini@suse.de>
* include/ext/mt_allocator.h (__mt_alloc<>::deallocate):
The critical section is actually very small, only two assignments.
diff -prN libstdc++-v3-orig/include/ext/mt_allocator.h libstdc++-v3/include/ext/mt_allocator.h
*** libstdc++-v3-orig/include/ext/mt_allocator.h Sat Apr 3 14:17:59 2004
--- libstdc++-v3/include/ext/mt_allocator.h Mon Apr 5 10:01:54 2004
*************** namespace __gnu_cxx
*** 430,449 ****
* _S_options._M_freelist_headroom)
&& __remove > static_cast<long>(__bin._M_free[__thread_id]))
{
- __gthread_mutex_lock(__bin._M_mutex);
_Block_record* __tmp = __bin._M_first[__thread_id];
_Block_record* __first = __tmp;
__remove /= _S_options._M_freelist_headroom;
const long __removed = __remove;
! while (__remove > 1)
! {
! __tmp = __tmp->_M_next;
! --__remove;
! }
__bin._M_first[__thread_id] = __tmp->_M_next;
__tmp->_M_next = __bin._M_first[0];
__bin._M_first[0] = __first;
- __bin._M_free[__thread_id] -= __removed;
__gthread_mutex_unlock(__bin._M_mutex);
}
--- 430,447 ----
* _S_options._M_freelist_headroom)
&& __remove > static_cast<long>(__bin._M_free[__thread_id]))
{
_Block_record* __tmp = __bin._M_first[__thread_id];
_Block_record* __first = __tmp;
__remove /= _S_options._M_freelist_headroom;
const long __removed = __remove;
! while (__remove-- > 1)
! __tmp = __tmp->_M_next;
__bin._M_first[__thread_id] = __tmp->_M_next;
+ __bin._M_free[__thread_id] -= __removed;
+
+ __gthread_mutex_lock(__bin._M_mutex);
__tmp->_M_next = __bin._M_first[0];
__bin._M_first[0] = __first;
__gthread_mutex_unlock(__bin._M_mutex);
}