summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-05-22 12:30:27 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-05-22 12:35:45 (GMT)
commit3ebbecd49d9e3cd8818634d5da5c7b1850190d54 (patch)
tree51abbce383aa517c03ff85c3def557a380c01fc4 /src/corelib/thread
parentd001cef792b2f41615cb1f7657bed3d7525ffb0e (diff)
downloadQt-3ebbecd49d9e3cd8818634d5da5c7b1850190d54.zip
Qt-3ebbecd49d9e3cd8818634d5da5c7b1850190d54.tar.gz
Qt-3ebbecd49d9e3cd8818634d5da5c7b1850190d54.tar.bz2
Make the default size of QMutexPool a prime number
As pointed out by Olivier, this should allow for better distribution in the array. I also removed the unnecessary count member, since we can use QVarLengthArray.count() instead.
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qmutexpool.cpp8
-rw-r--r--src/corelib/thread/qmutexpool_p.h5
2 files changed, 6 insertions, 7 deletions
diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp
index 77a3cca..0d7c890 100644
--- a/src/corelib/thread/qmutexpool.cpp
+++ b/src/corelib/thread/qmutexpool.cpp
@@ -96,9 +96,9 @@ Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive))
QMutexPool is destructed.
*/
QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size)
- : mutexes(size), count(size), recursionMode(recursionMode)
+ : mutexes(size), recursionMode(recursionMode)
{
- for (int index = 0; index < count; ++index) {
+ for (int index = 0; index < mutexes.count(); ++index) {
mutexes[index] = 0;
}
}
@@ -109,7 +109,7 @@ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size)
*/
QMutexPool::~QMutexPool()
{
- for (int index = 0; index < count; ++index) {
+ for (int index = 0; index < mutexes.count(); ++index) {
delete mutexes[index];
mutexes[index] = 0;
}
@@ -130,7 +130,7 @@ QMutexPool *QMutexPool::instance()
QMutex *QMutexPool::get(const void *address)
{
Q_ASSERT_X(address != 0, "QMutexPool::get()", "'address' argument cannot be zero");
- int index = int((quintptr(address) >> (sizeof(address) >> 1)) % count);
+ int index = int((quintptr(address) >> (sizeof(address) >> 1)) % mutexes.count());
if (!mutexes[index]) {
// mutex not created, create one
diff --git a/src/corelib/thread/qmutexpool_p.h b/src/corelib/thread/qmutexpool_p.h
index 4c1e32c..30a16d4 100644
--- a/src/corelib/thread/qmutexpool_p.h
+++ b/src/corelib/thread/qmutexpool_p.h
@@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QMutexPool
{
public:
- explicit QMutexPool(QMutex::RecursionMode recursionMode = QMutex::NonRecursive, int size = 128);
+ explicit QMutexPool(QMutex::RecursionMode recursionMode = QMutex::NonRecursive, int size = 131);
~QMutexPool();
QMutex *get(const void *address);
@@ -72,8 +72,7 @@ public:
static QMutex *globalInstanceGet(const void *address);
private:
- QVarLengthArray<QAtomicPointer<QMutex>, 128> mutexes;
- int count;
+ QVarLengthArray<QAtomicPointer<QMutex>, 131> mutexes;
QMutex::RecursionMode recursionMode;
};