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_p.h | |
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_p.h')
-rw-r--r-- | src/corelib/thread/qmutexpool_p.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/corelib/thread/qmutexpool_p.h b/src/corelib/thread/qmutexpool_p.h index 1a45ba9..b2cd210 100644 --- a/src/corelib/thread/qmutexpool_p.h +++ b/src/corelib/thread/qmutexpool_p.h @@ -67,11 +67,19 @@ public: explicit QMutexPool(QMutex::RecursionMode recursionMode = QMutex::NonRecursive, int size = 131); ~QMutexPool(); - QMutex *get(const void *address); + inline QMutex *get(const void *address) { + int index = uint(quintptr(address)) % mutexes.count(); + QMutex *m = mutexes[index]; + if (m) + return m; + else + return createMutex(index); + } static QMutexPool *instance(); static QMutex *globalInstanceGet(const void *address); private: + QMutex *createMutex(int index); QVarLengthArray<QAtomicPointer<QMutex>, 131> mutexes; QMutex::RecursionMode recursionMode; }; |