Changeset 561 for trunk/src/corelib/concurrent/qtconcurrentthreadengine.h
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/corelib/concurrent/qtconcurrentthreadengine.h
r2 r561 2 2 ** 3 3 ** 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]) 5 6 ** 6 7 ** This file is part of the QtCore module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 52 52 #include <QtCore/qtconcurrentexception.h> 53 53 #include <QtCore/qwaitcondition.h> 54 55 54 56 55 57 QT_BEGIN_HEADER … … 62 64 namespace QtConcurrent { 63 65 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. 69 class ThreadEngineBarrier 70 { 109 71 private: 72 73 74 75 76 77 110 78 QMutex mutex; 111 int count; 112 QWaitCondition waitCondition; 79 QAtomicInt count; 80 81 QSemaphore semaphore; 82 public: 83 ThreadEngineBarrier(); 84 void acquire(); 85 int release(); 86 void wait(); 87 int currentCount(); 88 bool releaseUnlessLast(); 113 89 }; 114 90 … … 133 109 void setProgressValue(int progress); 134 110 void setProgressRange(int minimum, int maximum); 111 135 112 136 113 protected: // The user overrides these: … … 153 130 QFutureInterfaceBase *futureInterface; 154 131 QThreadPool *threadPool; 155 ThreadEngine Semaphore semaphore;132 ThreadEngine; 156 133 QtConcurrent::internal::ExceptionStore exceptionStore; 157 134 }; … … 200 177 start(); 201 178 202 semaphore.acquire();179 re(); 203 180 threadPool->start(this); 204 181 return future; … … 262 239 class ThreadEngineStarter : public ThreadEngineStarterBase<T> 263 240 { 264 public: 265 ThreadEngineStarter(ThreadEngine<T> *threadEngine) 266 :ThreadEngineStarterBase<T>(threadEngine) {} 241 typedef ThreadEngineStarterBase<T> Base; 242 typedef ThreadEngine<T> TypedThreadEngine; 243 public: 244 ThreadEngineStarter(TypedThreadEngine *eng) 245 : Base(eng) { } 267 246 268 247 T startBlocking()
Note:
See TracChangeset
for help on using the changeset viewer.