diff options
author | Paolo Carlini <pcarlini@suse.de> | 2004-04-02 19:51:21 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2004-04-02 19:51:21 +0000 |
commit | ab40b100d3e1676c60d3ccd0765a45736471beaf (patch) | |
tree | 046ad4d64956ce9f400bdfb9a9c27ae074b1c26b | |
parent | 89c43c0a0bdf4db3e857fc60aecba58793e41107 (diff) | |
download | gcc-ab40b100d3e1676c60d3ccd0765a45736471beaf.zip gcc-ab40b100d3e1676c60d3ccd0765a45736471beaf.tar.gz gcc-ab40b100d3e1676c60d3ccd0765a45736471beaf.tar.bz2 |
mt_allocator.h (__mt_alloc<>::deallocate): Rearrange arithmetic to avoid computing two divisions at each deallocation.
2004-04-02 Paolo Carlini <pcarlini@suse.de>
* include/ext/mt_allocator.h (__mt_alloc<>::deallocate):
Rearrange arithmetic to avoid computing two divisions at
each deallocation.
From-SVN: r80356
-rw-r--r-- | libstdc++-v3/ChangeLog | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/mt_allocator.h | 26 |
2 files changed, 18 insertions, 14 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b47d26e..3248c32 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2004-04-02 Paolo Carlini <pcarlini@suse.de> + + * include/ext/mt_allocator.h (__mt_alloc<>::deallocate): + Rearrange arithmetic to avoid computing two divisions at + each deallocation. + 2004-04-01 Paolo Carlini <pcarlini@suse.de> * include/ext/mt_allocator.h (__mt_alloc<>::_S_initialize): diff --git a/libstdc++-v3/include/ext/mt_allocator.h b/libstdc++-v3/include/ext/mt_allocator.h index 8edbaaa..d69b0e1 100644 --- a/libstdc++-v3/include/ext/mt_allocator.h +++ b/libstdc++-v3/include/ext/mt_allocator.h @@ -434,25 +434,23 @@ namespace __gnu_cxx #ifdef __GTHREADS if (__gthread_active_p()) { - // Calculate the number of records to remove from our freelist. + // Calculate the number of records to remove from our freelist: + // in order to avoid too much contention we wait until the + // number of records is "high enough". const size_t __thread_id = _S_get_thread_id(); - int __remove = (__bin._M_free[__thread_id] - - (__bin._M_used[__thread_id] - / _S_options._M_freelist_headroom)); - - // The calculation above will almost always tell us to - // remove one or two records at a time, but this creates too - // much contention when locking and therefore we wait until - // the number of records is "high enough". - int __cond1 = static_cast<int>(100 * (_S_bin_size - __which)); - int __cond2 = static_cast<int>(__bin._M_free[__thread_id] - / _S_options._M_freelist_headroom); - if (__remove > __cond1 && __remove > __cond2) + + long __remove = ((__bin._M_free[__thread_id] + * _S_options._M_freelist_headroom) + - __bin._M_used[__thread_id]); + if (__remove > static_cast<long>(100 * (_S_bin_size - __which) + * _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; - const int __removed = __remove; + __remove /= _S_options._M_freelist_headroom; + const long __removed = __remove; while (__remove > 1) { __tmp = __tmp->_M_next; |