Transient Recorder Framework
TRWorkerThread.h
Go to the documentation of this file.
1 /* This file is part of the Transient Recorder Framework.
2  * It is subject to the license terms in the LICENSE.txt file found in the
3  * top-level directory of this distribution and at
4  * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. No part
5  * of the Transient Recorder Framework, including this file, may be copied,
6  * modified, propagated, or distributed except according to the terms
7  * contained in the LICENSE.txt file.
8  */
9 
16 #ifndef TRANSREC_WORKER_THREAD_H
17 #define TRANSREC_WORKER_THREAD_H
18 
19 #include <deque>
20 #include <string>
21 
22 #include <epicsMutex.h>
23 #include <epicsEvent.h>
24 #include <epicsThread.h>
25 
26 #include "TRNonCopyable.h"
27 
34 {
35 public:
42  virtual void runWorkerThreadTask (int id) = 0;
43 };
44 
45 class TRWorkerThreadTask;
46 
54  private TRNonCopyable,
55  private epicsThreadRunable
56 {
57  friend class TRWorkerThreadTask;
58 
59 public:
68  TRWorkerThread (std::string const &thread_name);
69 
77  ~TRWorkerThread ();
78 
85  void start ();
86 
90  void stop ();
91 
92 private:
93  bool m_stop;
94  epicsThread m_thread;
95  epicsMutex m_mutex;
96  epicsEvent m_event;
97  std::deque<TRWorkerThreadTask *> m_queue;
98 
99 private:
100  void run ();
101 };
102 
112  private TRNonCopyable
113 {
114  friend class TRWorkerThread;
115 
116 public:
124 
134  TRWorkerThreadTask (TRWorkerThread *worker, TRWorkerThreadRunnable *runnable, int id);
135 
143  void init (TRWorkerThread *worker, TRWorkerThreadRunnable *runnable, int id);
144 
157  ~TRWorkerThreadTask ();
158 
168  bool start ();
169 
175  bool cancel ();
176 
177 private:
178  TRWorkerThread *m_worker;
179  TRWorkerThreadRunnable *m_runnable;
180  int m_id;
181 };
182 
183 #endif
virtual void runWorkerThreadTask(int id)=0
Called on the helper thread request to execute a request.
void start()
Start the worker thread.
bool start()
Queues the task for execution.
This class is used to execute worker thread tasks.
Definition: TRWorkerThread.h:33
Represents a task submitted to the worker thread.
Definition: TRWorkerThread.h:111
A simple worker thread with a queue of tasks.
Definition: TRWorkerThread.h:53