diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2011-03-29 09:02:20 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2011-03-31 14:32:46 (GMT) |
commit | b63e0f7c612f7e63831dbee3565292ddca7dba59 (patch) | |
tree | 54a26ffe1dd6d0ceb26487863c588bdcab47db34 /src/corelib/thread/qmutexpool.cpp | |
parent | 6fcd431d04cf7416179d5ab30f656a6ce3926070 (diff) | |
download | Qt-b63e0f7c612f7e63831dbee3565292ddca7dba59.zip Qt-b63e0f7c612f7e63831dbee3565292ddca7dba59.tar.gz Qt-b63e0f7c612f7e63831dbee3565292ddca7dba59.tar.bz2 |
Optimize QMutexPool
Make the get() function inline
and simplify the hash computation
Reviewed-by: brad
Diffstat (limited to 'src/corelib/thread/qmutexpool.cpp')
-rw-r--r-- | src/corelib/thread/qmutexpool.cpp | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp index 13e29c3..144fa35 100644 --- a/src/corelib/thread/qmutexpool.cpp +++ b/src/corelib/thread/qmutexpool.cpp @@ -123,22 +123,20 @@ QMutexPool *QMutexPool::instance() return globalMutexPool(); } -/*! +/*! \fn QMutexPool::get(void *address) Returns a QMutex from the pool. QMutexPool uses the value \a address to determine which mutex is returned from the pool. */ -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)) % mutexes.count()); - - if (!mutexes[index]) { - // mutex not created, create one - QMutex *newMutex = new QMutex(recursionMode); - if (!mutexes[index].testAndSetOrdered(0, newMutex)) - delete newMutex; - } +/*! \internal + create the mutex for the given index + */ +QMutex *QMutexPool::createMutex(int index) +{ + // mutex not created, create one + QMutex *newMutex = new QMutex(recursionMode); + if (!mutexes[index].testAndSetOrdered(0, newMutex)) + delete newMutex; return mutexes[index]; } |