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 #include "mythchrono.h"
10 
11 class MThreadPoolPrivate;
12 class MPoolThread;
13 class QRunnable;
14 
19 {
20  friend class MPoolThread;
21  public:
22  explicit MThreadPool(const QString &name);
23  ~MThreadPool();
24  MThreadPool(const MThreadPool &) = delete; // not copyable
25  MThreadPool &operator=(const MThreadPool &) = delete; // not copyable
26 
27  void Stop(void);
28  void DeletePoolThreads(void);
29 
30  static MThreadPool *globalInstance(void);
31  static void StopAllPools(void);
32  static void ShutdownAllPools(void);
33 
34  void start(QRunnable *runnable, const QString& debugName, int priority = 0);
35  bool tryStart(QRunnable *runnable, const QString& debugName);
36 
37  void startReserved(QRunnable *runnable, const QString& debugName,
38  std::chrono::milliseconds waitForAvailMS = 0ms);
39 
40  std::chrono::milliseconds expiryTimeout(void) const;
41  void setExpiryTimeout(std::chrono::milliseconds expiryTimeout);
42 
43  int maxThreadCount(void) const;
44  void setMaxThreadCount(int maxThreadCount);
45 
46  int activeThreadCount(void) const;
47 
48  void waitForDone(void);
49 
50  private:
51  bool TryStartInternal(QRunnable *runnable, const QString& debugName, bool reserved);
52  void NotifyAvailable(MPoolThread *thread);
53  void NotifyDone(MPoolThread *thread);
54  void ReleaseThread(void);
55 
56 
57  MThreadPoolPrivate *m_priv {nullptr};
58 };
59 
60 #endif // MYTH_THREAD_POOL_H
61 
62 /* 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:286
mythbaseexp.h
MThreadPoolPrivate
Definition: mthreadpool.cpp:215
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MThread::priority
QThread::Priority priority(void) const
Definition: mthread.cpp:256
MThreadPool
Definition: mthreadpool.h:18
MThread::operator=
MThread & operator=(const MThread &)=delete
mythchrono.h
MPoolThread
Definition: mthreadpool.cpp:105