]> Some of my projects - anidbudpclient.git/commitdiff
Correctly determine if everything was read from the buffer. end() returned true in...
authorAPTX <mail@example.com>
Thu, 31 Dec 2009 19:51:58 +0000 (20:51 +0100)
committerAPTX <mail@example.com>
Thu, 31 Dec 2009 19:51:58 +0000 (20:51 +0100)
circularbuffer.h
hashconsumer.cpp

index 1be3bc006daa2bd9c8033fb5dc84dcd6dbfa80e2..4973e266f1a2c8889f899f102ab707c9dc0f13ed 100644 (file)
@@ -2,7 +2,6 @@
 #define CIRCULARBUFFER_H
 
 #include <QSemaphore>
-
 namespace AniDBUdpClient {
 namespace HashPrivate {
 
@@ -25,9 +24,10 @@ public:
                        return false;
                buffer[w] = data;
                m_end = last;
-               used.release();
-               w++;
+               ++w;
                w %= SIZE;
+               used.release();
+
                return true;
        }
 
@@ -36,15 +36,15 @@ public:
                if (!used.tryAcquire(1, timeout))
                        return false;
                *data = buffer[r];
-               free.release();
-               r++;
+               ++r;
                r %= SIZE;
+               free.release();
                return true;
        }
 
        bool end() const
        {
-               return m_end && r == w;
+               return m_end && used.available() == 0;
        }
 
        bool reset()
index 02a29bb54161d1c400934d1b1846fc0b6517b55e..9fcaaf908f13cc49e29d53fb4851faba63accc6e 100644 (file)
@@ -28,7 +28,6 @@ HashConsumer::~HashConsumer()
 void HashConsumer::hashFile(const QString &file)
 {
        QMutexLocker locker(&mutex);
-qDebug() << "hashFile()";
        fileSize = QFileInfo(file).size();
 
        if (!isRunning())
@@ -53,7 +52,6 @@ qDebug() << "Thread consumer id is: " << QThread::currentThreadId();
 
                while (!(buffer->end() || abort))
                {
-//                     qDebug() << "hash->while(" << buffer->end() << ")";
                        QByteArray data;
 
                        while (!(buffer->get(&data) || abort));
@@ -63,8 +61,7 @@ qDebug() << "Thread consumer id is: " << QThread::currentThreadId();
                        read += data.size();
                        emit progress(read, totalSize);
                }
-               bool r = buffer->reset();
-qDebug() << "buffer reset" << r;
+               buffer->reset();
 
                if (abort)
                        return;