summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2011-12-07 04:11:12 +0200
committerLaszlo Papp <ext-laszlo.papp@nokia.com>2011-12-07 04:11:12 +0200
commit8772ec52ba69b6c0816d84a550ef279a72e365c7 (patch)
tree76c6e2b75ae626ea3b603bf68bd78b9c9ffd1d36
parentb12850bf50f31e0cf0257f6ccee84ea258756ddc (diff)
Do not use QMutexLocker, just a private class member QMutex for locking
We need to construct a mutex anyway since the QMutexLocker does not have a constructor which would do that automatically for us. Also, it is better to unlock immediately after the mpg123_init call in order to lock as less code as needed. This way, the construction and deconstruction of a mutex and locker does not take effect on the private class' constructor and destructor's speed.
-rw-r--r--src/decoders/qalmpg123audiodecoder.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/decoders/qalmpg123audiodecoder.cpp b/src/decoders/qalmpg123audiodecoder.cpp
index e871e7a..21e21b2 100644
--- a/src/decoders/qalmpg123audiodecoder.cpp
+++ b/src/decoders/qalmpg123audiodecoder.cpp
@@ -23,7 +23,7 @@
#include <QtCore/QString>
#include <QtCore/QUrl>
#include <QtCore/QDebug>
-#include <QtCore/QMutexLocker>
+#include <QtCore/QMutex>
#include <mpg123.h>
@@ -33,12 +33,14 @@ class QALMpg123AudioDecoder::Private
Private()
: mpg123Handle(0)
{
- QMutexLocker mutexLocker;
+ mutex.lock();
if (++referenceCounter == 1) {
int error;
if ((error = mpg123_init()) == MPG123_OK) {
+ mutex.unlock();
isValid = true;
} else {
+ mutex.unlock();
qWarning() << Q_FUNC_INFO << "Failed to initialize the mpg123 library:" << error;
}
}
@@ -46,10 +48,11 @@ class QALMpg123AudioDecoder::Private
~Private()
{
- QMutexLocker mutexLocker;
+ mutex.lock();
if (--referenceCounter == 0) {
mpg123_exit();
}
+ mutex.unlock();
}
static sf_count_t fileLengthCallback(void *user_data);
@@ -60,6 +63,8 @@ class QALMpg123AudioDecoder::Private
static int referenceCounter;
static bool isValid;
+ QMutex mutex;
+
QFile file;
QByteArray encodedData;