1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 06:07:37 +02:00

Add a Cache mutex to protect shared data

This commit is contained in:
Casey Link
2012-04-12 17:02:11 -05:00
parent 67d943bce3
commit c6beda5a7b
2 changed files with 7 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
#include <QDateTime> #include <QDateTime>
#include <QSettings> #include <QSettings>
#include <QMutexLocker>
using namespace TomahawkUtils; using namespace TomahawkUtils;
@@ -53,6 +54,8 @@ Cache::~Cache()
void Cache::pruneTimerFired() void Cache::pruneTimerFired()
{ {
QMutexLocker mutex_locker( &m_mutex );
qDebug() << Q_FUNC_INFO << "Pruning tomahawkcache"; qDebug() << Q_FUNC_INFO << "Pruning tomahawkcache";
qlonglong currentMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch(); qlonglong currentMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
@@ -79,6 +82,8 @@ void Cache::pruneTimerFired()
QVariant Cache::getData ( const QString& identifier, const QString& key ) QVariant Cache::getData ( const QString& identifier, const QString& key )
{ {
QMutexLocker mutex_locker( &m_mutex );
const QString cacheDir = m_cacheBaseDir + identifier; const QString cacheDir = m_cacheBaseDir + identifier;
QSettings cached_settings ( cacheDir, QSettings::IniFormat ); QSettings cached_settings ( cacheDir, QSettings::IniFormat );

View File

@@ -22,6 +22,7 @@
#include "dllmacro.h" #include "dllmacro.h"
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include <QMutex>
#include <QSettings> #include <QSettings>
#include <QObject> #include <QObject>
#include <QTimer> #include <QTimer>
@@ -63,6 +64,7 @@ private:
QString m_cacheBaseDir; QString m_cacheBaseDir;
QSettings m_cacheManifest; QSettings m_cacheManifest;
QTimer m_pruneTimer; QTimer m_pruneTimer;
QMutex m_mutex;
}; };
} }