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  MThreadPool(const MThreadPool &) = delete; // not copyable
24  MThreadPool &operator=(const MThreadPool &) = delete; // not copyable
25 
26  void Stop(void);
27  void DeletePoolThreads(void);
28 
29  static MThreadPool *globalInstance(void);
30  static void StopAllPools(void);
31  static void ShutdownAllPools(void);
32 
33  void start(QRunnable *runnable, const QString& debugName, int priority = 0);
34  bool tryStart(QRunnable *runnable, const QString& debugName);
35 
36  void startReserved(QRunnable *runnable, const QString& debugName,
37  int waitForAvailMS = 0);
38 
39  int expiryTimeout(void) const;
40  void setExpiryTimeout(int expiryTimeout);
41 
42  int maxThreadCount(void) const;
43  void setMaxThreadCount(int maxThreadCount);
44 
45  int activeThreadCount(void) const;
46 
47  void waitForDone(void);
48 
49  private:
50  bool TryStartInternal(QRunnable *runnable, const QString& debugName, bool reserved);
51  void NotifyAvailable(MPoolThread *thread);
52  void NotifyDone(MPoolThread *thread);
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: */
MThread::start
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:288
mythbaseexp.h
MThreadPoolPrivate
Definition: mthreadpool.cpp:213
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MThreadPool::operator=
MThreadPool & operator=(const MThreadPool &)=delete
MThread::priority
QThread::Priority priority(void) const
Definition: mthread.cpp:258
MThreadPool
Definition: mthreadpool.h:18
MThreadPool::MThreadPool
MThreadPool(const MThreadPool &)=delete
MPoolThread
Definition: mthreadpool.cpp:103