diff options
author | João Abecasis <joao@abecasis.name> | 2009-07-22 18:06:37 (GMT) |
---|---|---|
committer | João Abecasis <joao@abecasis.name> | 2009-07-22 18:25:52 (GMT) |
commit | fa854a8ed0eaefa3a65c6b3b66e98ba5bdc6d6c2 (patch) | |
tree | 8a4301370a57283203d8e4a10805ebf25e859f3a /src/corelib | |
parent | 5796404298446038878da065c32429a0e31e9506 (diff) | |
download | Qt-fa854a8ed0eaefa3a65c6b3b66e98ba5bdc6d6c2.zip Qt-fa854a8ed0eaefa3a65c6b3b66e98ba5bdc6d6c2.tar.gz Qt-fa854a8ed0eaefa3a65c6b3b66e98ba5bdc6d6c2.tar.bz2 |
Fix potential deadlock in QAbstractFileEngine
There's a possibility for deadlocking with user code in
QAbstractFileEngine. Changing the QMutex there to a QReadWriteLock
should reduce the possibilities for this happening.
Also reduced the scope of the lock in QAbstractFileEngine.
Reviewed-by: Thiago Macieira
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qabstractfileengine.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/corelib/io/qabstractfileengine.cpp b/src/corelib/io/qabstractfileengine.cpp index 93097bc..9eb3305 100644 --- a/src/corelib/io/qabstractfileengine.cpp +++ b/src/corelib/io/qabstractfileengine.cpp @@ -42,7 +42,7 @@ #include "qabstractfileengine.h" #include "private/qabstractfileengine_p.h" #include "qdatetime.h" -#include "qmutex.h" +#include "qreadwritelock.h" #include "qvariant.h" // built-in handlers #include "qfsfileengine.h" @@ -98,14 +98,14 @@ QT_BEGIN_NAMESPACE All application-wide handlers are stored in this list. The mutex must be acquired to ensure thread safety. */ -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, fileEngineHandlerMutex, (QMutex::Recursive)) +Q_GLOBAL_STATIC_WITH_ARGS(QReadWriteLock, fileEngineHandlerMutex, (QReadWriteLock::Recursive)) static bool qt_abstractfileenginehandlerlist_shutDown = false; class QAbstractFileEngineHandlerList : public QList<QAbstractFileEngineHandler *> { public: ~QAbstractFileEngineHandlerList() { - QMutexLocker locker(fileEngineHandlerMutex()); + QWriteLocker locker(fileEngineHandlerMutex()); qt_abstractfileenginehandlerlist_shutDown = true; } }; @@ -122,7 +122,7 @@ Q_GLOBAL_STATIC(QAbstractFileEngineHandlerList, fileEngineHandlers) */ QAbstractFileEngineHandler::QAbstractFileEngineHandler() { - QMutexLocker locker(fileEngineHandlerMutex()); + QWriteLocker locker(fileEngineHandlerMutex()); fileEngineHandlers()->prepend(this); } @@ -132,7 +132,7 @@ QAbstractFileEngineHandler::QAbstractFileEngineHandler() */ QAbstractFileEngineHandler::~QAbstractFileEngineHandler() { - QMutexLocker locker(fileEngineHandlerMutex()); + QWriteLocker locker(fileEngineHandlerMutex()); // Remove this handler from the handler list only if the list is valid. if (!qt_abstractfileenginehandlerlist_shutDown) fileEngineHandlers()->removeAll(this); @@ -166,12 +166,14 @@ QAbstractFileEngineHandler::~QAbstractFileEngineHandler() */ QAbstractFileEngine *QAbstractFileEngine::create(const QString &fileName) { - QMutexLocker locker(fileEngineHandlerMutex()); + { + QReadLocker locker(fileEngineHandlerMutex()); - // check for registered handlers that can load the file - for (int i = 0; i < fileEngineHandlers()->size(); i++) { - if (QAbstractFileEngine *ret = fileEngineHandlers()->at(i)->create(fileName)) - return ret; + // check for registered handlers that can load the file + for (int i = 0; i < fileEngineHandlers()->size(); i++) { + if (QAbstractFileEngine *ret = fileEngineHandlers()->at(i)->create(fileName)) + return ret; + } } #ifdef QT_BUILD_CORE_LIB |