Skip to content

Commit

Permalink
Use QRecursiveMutex
Browse files Browse the repository at this point in the history
Instead of deprecated constructor QMutex(QMutex::RecursionMode), use
recommended replacement class QRecursiveMutex.

This deprecation was done only in the KDE branch of Qt, specifically in
https://invent.kde.org/qt/qt/qtbase/-/commit/6d5988831862f081404270bd7fa2f25bc836fdc9.
Since that commit is included in the Qt packaged for some Linux
distributions (e.g. Arch Linux:
https://archlinux.org/packages/extra/x86_64/qt5-base/), it seems worth
respecting this deprecation.

Since QRecursiveMutex was only introduced in Qt 5.14, whereas we need to
support Qt 5.9.5 or better, this involves some #ifdef magic.
  • Loading branch information
c4rlo committed Apr 18, 2022
1 parent 8512ce4 commit f7b22f2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/keys/drivers/YubiKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <QtConcurrent>

YubiKey::YubiKey()
: m_interfaces_detect_mutex(QMutex::Recursive)
{
int num_interfaces = 0;

Expand Down
15 changes: 13 additions & 2 deletions src/keys/drivers/YubiKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
#define KEEPASSX_YUBIKEY_H

#include <QHash>
#include <QMutex>
#include <QObject>
#include <QTimer>

#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#include <QRecursiveMutex>
#else
#include <QMutex>
#endif

#include <botan/secmem.h>

typedef QPair<unsigned int, int> YubiKeySlot;
Expand Down Expand Up @@ -85,7 +91,12 @@ class YubiKey : public QObject
QTimer m_interactionTimer;
bool m_initialized = false;
QString m_error;
QMutex m_interfaces_detect_mutex;

#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex m_interfaces_detect_mutex;
#else
QMutex m_interfaces_detect_mutex{QMutex::Recursive};
#endif

Q_DISABLE_COPY(YubiKey)
};
Expand Down
1 change: 0 additions & 1 deletion src/keys/drivers/YubiKeyInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "YubiKeyInterface.h"

YubiKeyInterface::YubiKeyInterface()
: m_mutex(QMutex::Recursive)
{
m_interactionTimer.setSingleShot(true);
m_interactionTimer.setInterval(300);
Expand Down
13 changes: 12 additions & 1 deletion src/keys/drivers/YubiKeyInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

#include <QMultiMap>

#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#include <QRecursiveMutex>
#else
#include <QMutex>
#endif

/**
* Abstract base class to manage the interfaces to hardware key(s)
*/
Expand Down Expand Up @@ -70,7 +76,12 @@ class YubiKeyInterface : public QObject

QMultiMap<unsigned int, QPair<int, QString>> m_foundKeys;

QMutex m_mutex;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex m_mutex;
#else
QMutex m_mutex{QMutex::Recursive};
#endif

QTimer m_interactionTimer;
bool m_initialized = false;
QString m_error;
Expand Down

0 comments on commit f7b22f2

Please sign in to comment.