From 8772ec52ba69b6c0816d84a550ef279a72e365c7 Mon Sep 17 00:00:00 2001 From: Laszlo Papp Date: Wed, 7 Dec 2011 04:11:12 +0200 Subject: 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. --- src/decoders/qalmpg123audiodecoder.cpp | 11 ++++++++--- 1 file 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 #include #include -#include +#include #include @@ -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; -- cgit v1.2.3