Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/corelib/concurrent/qtconcurrentthreadengine.h

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the QtCore module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5252#include <QtCore/qtconcurrentexception.h>
    5353#include <QtCore/qwaitcondition.h>
     54
     55
    5456
    5557QT_BEGIN_HEADER
     
    6264namespace QtConcurrent {
    6365
    64 // A Semaphore that can wait until all resources are returned.
    65 class ThreadEngineSemaphore
    66 {
    67 public:
    68     ThreadEngineSemaphore()
    69     :count(0) { }
    70 
    71     void acquire()
    72     {
    73         QMutexLocker lock(&mutex);
    74         ++count;
    75     }
    76 
    77     int release()
    78     {
    79         QMutexLocker lock(&mutex);
    80         if (--count == 0)
    81             waitCondition.wakeAll();
    82         return count;
    83     }
    84 
    85     // Wait until all resources are released.
    86     void wait()
    87     {
    88         QMutexLocker lock(&mutex);
    89         if (count != 0)
    90             waitCondition.wait(&mutex);
    91     }
    92 
    93     int currentCount()
    94     {
    95         return count;
    96     }
    97 
    98     // releases a resource, unless this is the last resource.
    99     // returns true if a resource was released.
    100     bool releaseUnlessLast()
    101     {
    102         QMutexLocker lock(&mutex);
    103         if (count == 1)
    104             return false;
    105         --count;
    106         return true;
    107     }
    108 
     66// The ThreadEngineBarrier counts worker threads, and allows one
     67// thread to wait for all others to finish. Tested for its use in
     68// QtConcurrent, requires more testing for use as a general class.
     69class ThreadEngineBarrier
     70{
    10971private:
     72
     73
     74
     75
     76
     77
    11078    QMutex mutex;
    111     int count;
    112     QWaitCondition waitCondition;
     79    QAtomicInt count;
     80
     81    QSemaphore semaphore;
     82public:
     83    ThreadEngineBarrier();
     84    void acquire();
     85    int release();
     86    void wait();
     87    int currentCount();
     88    bool releaseUnlessLast();
    11389};
    11490
     
    133109    void setProgressValue(int progress);
    134110    void setProgressRange(int minimum, int maximum);
     111
    135112
    136113protected: // The user overrides these:
     
    153130    QFutureInterfaceBase *futureInterface;
    154131    QThreadPool *threadPool;
    155     ThreadEngineSemaphore semaphore;
     132    ThreadEngine;
    156133    QtConcurrent::internal::ExceptionStore exceptionStore;
    157134};
     
    200177        start();
    201178
    202         semaphore.acquire();
     179        re();
    203180        threadPool->start(this);
    204181        return future;
     
    262239class ThreadEngineStarter : public ThreadEngineStarterBase<T>
    263240{
    264 public:
    265     ThreadEngineStarter(ThreadEngine<T> *threadEngine)
    266     :ThreadEngineStarterBase<T>(threadEngine) {}
     241    typedef ThreadEngineStarterBase<T> Base;
     242    typedef ThreadEngine<T> TypedThreadEngine;
     243public:
     244    ThreadEngineStarter(TypedThreadEngine *eng)
     245        : Base(eng) { }
    267246
    268247    T startBlocking()
Note: See TracChangeset for help on using the changeset viewer.