QReadWriteLock replaced with QMutex.

This commit is contained in:
Martin Rotter 2014-02-02 09:21:26 +01:00
parent f1229f9003
commit 1672198bee
5 changed files with 11 additions and 15 deletions

View File

@ -11,13 +11,12 @@
#include <QString> #include <QString>
#include <QFile> #include <QFile>
#include <QApplication> #include <QApplication>
#include <QReadWriteLock>
QPointer<SystemFactory> SystemFactory::s_instance; QPointer<SystemFactory> SystemFactory::s_instance;
SystemFactory::SystemFactory(QObject *parent) : QObject(parent) { SystemFactory::SystemFactory(QObject *parent) : QObject(parent) {
m_applicationCloseLock = new QReadWriteLock(QReadWriteLock::NonRecursive); m_applicationCloseLock = new QMutex();
} }
SystemFactory::~SystemFactory() { SystemFactory::~SystemFactory() {

View File

@ -3,11 +3,9 @@
#include <QObject> #include <QObject>
#include <QPointer> #include <QPointer>
#include <QMutex>
class QReadWriteLock;
class QMutex;
class SystemFactory : public QObject { class SystemFactory : public QObject {
Q_OBJECT Q_OBJECT
@ -42,7 +40,7 @@ class SystemFactory : public QObject {
// Access to application-wide close lock. // Access to application-wide close lock.
inline QReadWriteLock *applicationCloseLock() const { inline QMutex *applicationCloseLock() const {
return m_applicationCloseLock; return m_applicationCloseLock;
} }
@ -62,7 +60,7 @@ class SystemFactory : public QObject {
// But of user decides to close the application (in other words, // But of user decides to close the application (in other words,
// tries to lock the lock for writing), then no other // tries to lock the lock for writing), then no other
// action will be allowed to lock for reading. // action will be allowed to lock for reading.
QReadWriteLock *m_applicationCloseLock; QMutex *m_applicationCloseLock;
static QPointer<SystemFactory> s_instance; static QPointer<SystemFactory> s_instance;
}; };

View File

@ -25,7 +25,6 @@
#include <QMenu> #include <QMenu>
#include <QWidgetAction> #include <QWidgetAction>
#include <QThread> #include <QThread>
#include <QReadWriteLock>
#include <QProgressBar> #include <QProgressBar>
#include <QStatusBar> #include <QStatusBar>
@ -99,7 +98,7 @@ void FeedMessageViewer::quitDownloader() {
} }
void FeedMessageViewer::updateSelectedFeeds() { void FeedMessageViewer::updateSelectedFeeds() {
if (SystemFactory::instance()->applicationCloseLock()->tryLockForWrite()) { if (SystemFactory::instance()->applicationCloseLock()->tryLock()) {
emit feedsUpdateRequested(m_feedsView->selectedFeeds()); emit feedsUpdateRequested(m_feedsView->selectedFeeds());
} }
else { else {
@ -118,7 +117,7 @@ void FeedMessageViewer::updateSelectedFeeds() {
} }
void FeedMessageViewer::updateAllFeeds() { void FeedMessageViewer::updateAllFeeds() {
if (SystemFactory::instance()->applicationCloseLock()->tryLockForWrite()) { if (SystemFactory::instance()->applicationCloseLock()->tryLock()) {
emit feedsUpdateRequested(m_feedsView->allFeeds()); emit feedsUpdateRequested(m_feedsView->allFeeds());
} }
else { else {

View File

@ -76,7 +76,7 @@ void FeedsView::clearSelectedFeeds() {
} }
void FeedsView::addNewStandardCategory() { void FeedsView::addNewStandardCategory() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLockForWrite()) { if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
// Lock was not obtained because // Lock was not obtained because
// it is used probably by feed updater or application // it is used probably by feed updater or application
// is quitting. // is quitting.
@ -115,7 +115,7 @@ void FeedsView::editStandardCategory(FeedsModelStandardCategory *category) {
} }
void FeedsView::addNewStandardFeed() { void FeedsView::addNewStandardFeed() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLockForWrite()) { if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
// Lock was not obtained because // Lock was not obtained because
// it is used probably by feed updater or application // it is used probably by feed updater or application
// is quitting. // is quitting.
@ -154,7 +154,7 @@ void FeedsView::editStandardFeed(FeedsModelStandardFeed *feed) {
} }
void FeedsView::editSelectedItem() { void FeedsView::editSelectedItem() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLockForWrite()) { if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
// Lock was not obtained because // Lock was not obtained because
// it is used probably by feed updater or application // it is used probably by feed updater or application
// is quitting. // is quitting.
@ -212,7 +212,7 @@ void FeedsView::editSelectedItem() {
} }
void FeedsView::deleteSelectedItem() { void FeedsView::deleteSelectedItem() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLockForWrite()) { if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
// Lock was not obtained because // Lock was not obtained because
// it is used probably by feed updater or application // it is used probably by feed updater or application
// is quitting. // is quitting.

View File

@ -175,7 +175,7 @@ void FormMain::onSaveState(QSessionManager &manager) {
void FormMain::onAboutToQuit() { void FormMain::onAboutToQuit() {
// Make sure that we obtain close lock // Make sure that we obtain close lock
// BEFORE even trying to quit the application. // BEFORE even trying to quit the application.
if (SystemFactory::instance()->applicationCloseLock()->tryLockForWrite(CLOSE_LOCK_TIMEOUT)) { if (SystemFactory::instance()->applicationCloseLock()->tryLock(CLOSE_LOCK_TIMEOUT)) {
// Application obtained permission to close // Application obtained permission to close
// in a safety way. // in a safety way.
qDebug("Close lock obtained safely."); qDebug("Close lock obtained safely.");