00001
00002
00003 #ifndef _MYTH_THREAD_POOL_H_
00004 #define _MYTH_THREAD_POOL_H_
00005
00006 #include <QString>
00007
00008 #include "mythbaseexp.h"
00009
00010 class MThreadPoolPrivate;
00011 class MPoolThread;
00012 class QRunnable;
00013
00014 class MBASE_PUBLIC MThreadPool
00015 {
00016 friend class MPoolThread;
00017 public:
00018 MThreadPool(const QString &name);
00019 ~MThreadPool();
00020
00021 void Stop(void);
00022 void DeletePoolThreads(void);
00023
00024 static MThreadPool *globalInstance(void);
00025 static void StopAllPools(void);
00026 static void ShutdownAllPools(void);
00027
00028 void start(QRunnable *runnable, QString debugName, int priority = 0);
00029 bool tryStart(QRunnable *runnable, QString debugName);
00030
00031 void startReserved(QRunnable *runnable, QString debugName,
00032 int waitForAvailMS = 0);
00033
00034 int expiryTimeout(void) const;
00035 void setExpiryTimeout(int expiryTimeout);
00036
00037 int maxThreadCount(void) const;
00038 void setMaxThreadCount(int maxThreadCount);
00039
00040 int activeThreadCount(void) const;
00041
00042
00043
00044
00045 void waitForDone(void);
00046
00047 private:
00048 bool TryStartInternal(QRunnable*, QString, bool);
00049 void NotifyAvailable(MPoolThread*);
00050 void NotifyDone(MPoolThread*);
00051 void ReleaseThread(void);
00052
00053
00054 MThreadPoolPrivate *m_priv;
00055 };
00056
00057 #endif // _MYTH_THREAD_POOL_H_
00058
00059