MythTV  master
mthreadpool.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef _MYTH_THREAD_POOL_H_
4 #define _MYTH_THREAD_POOL_H_
5 
6 #include <QString>
7 
8 #include "mythbaseexp.h"
9 
10 class MThreadPoolPrivate;
11 class MPoolThread;
12 class QRunnable;
13 
18 {
19  friend class MPoolThread;
20  public:
21  explicit MThreadPool(const QString &name);
22  ~MThreadPool();
23 
24  void Stop(void);
25  void DeletePoolThreads(void);
26 
27  static MThreadPool *globalInstance(void);
28  static void StopAllPools(void);
29  static void ShutdownAllPools(void);
30 
31  void start(QRunnable *runnable, const QString& debugName, int priority = 0);
32  bool tryStart(QRunnable *runnable, const QString& debugName);
33 
34  void startReserved(QRunnable *runnable, const QString& debugName,
35  int waitForAvailMS = 0);
36 
37  int expiryTimeout(void) const;
38  void setExpiryTimeout(int expiryTimeout);
39 
40  int maxThreadCount(void) const;
41  void setMaxThreadCount(int maxThreadCount);
42 
43  int activeThreadCount(void) const;
44 
45  void waitForDone(void);
46 
47  private:
48  MThreadPool(const MThreadPool &) = delete; // not copyable
49  MThreadPool &operator=(const MThreadPool &) = delete; // not copyable
50  bool TryStartInternal(QRunnable*, const QString&, bool);
51  void NotifyAvailable(MPoolThread*);
52  void NotifyDone(MPoolThread*);
53  void ReleaseThread(void);
54 
55 
56  MThreadPoolPrivate *m_priv {nullptr};
57 };
58 
59 #endif // _MYTH_THREAD_POOL_H_
60 
61 /* vim: set expandtab tabstop=4 shiftwidth=4: */
void start(QThread::Priority=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:294
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
QThread::Priority priority(void) const
Definition: mthread.cpp:264
MThread & operator=(const MThread &)=delete