This is Unofficial EPICS BASE Doxygen Site
thread.h
Go to the documentation of this file.
1 /* thread.h */
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
9 #ifndef THREAD_H
10 #define THREAD_H
11 
12 #include <memory>
13 #include <sstream>
14 #include <stdexcept>
15 
16 #if __cplusplus>=201103L
17 #include <functional>
18 #endif
19 
20 #include <epicsThread.h>
21 #include <shareLib.h>
22 
23 #include <pv/noDefaultMethods.h>
24 #include <pv/pvType.h>
25 
26 
27 namespace epics { namespace pvData {
28 
37 };
38 
39 class Thread;
40 typedef std::tr1::shared_ptr<Thread> ThreadPtr;
41 typedef std::tr1::shared_ptr<epicsThread> EpicsThreadPtr;
42 
43 typedef epicsThreadRunable Runnable;
44 
45 namespace detail {
46 template<typename C>
47 struct MethRunner : public epicsThreadRunable
48 {
49  typedef void(C::*fn_t)();
51  C* inst;
52  MethRunner(C* i, fn_t f) :fn(f), inst(i) {}
53  virtual ~MethRunner() {}
54  virtual void run()
55  {
56  (inst->*fn)();
57  }
58 };
59 } // namespace detail
60 
67 public:
96  {
97  unsigned int p_prio, p_stack;
98  std::ostringstream p_strm;
99  bool p_autostart;
100  Runnable *p_runner;
101  typedef epics::auto_ptr<Runnable> p_owned_runner_t;
102  p_owned_runner_t p_owned_runner;
103  friend class Thread;
104  Runnable& x_getrunner();
105  void x_setdefault();
106 
107  public:
108  Config();
109  Config(Runnable *r);
110  Config(void(*fn)(void*), void *ptr);
111  template<typename C>
112  Config(C* inst, void(C::*meth)()) {this->x_setdefault();this->run(inst, meth);}
113 #if __cplusplus>=201103L
114  Config(std::function<void()>&& fn);
115 #endif
116 
117  Config& name(const std::string& n);
118  Config& prio(unsigned int p);
120  Config& autostart(bool a);
121 
123  Config& run(Runnable* r);
125  Config& run(void(*fn)(void*), void *ptr);
127  template<typename C>
128  Config& run(C* inst, void(C::*meth)())
129  {
130  this->p_owned_runner.reset(new detail::MethRunner<C>(inst, meth));
131  this->p_runner = this->p_owned_runner.get();
132  return *this;
133  }
134 #if __cplusplus>=201103L
135  Config& run(std::function<void()>&& fn);
136 #endif
137 
139  template<typename T>
140  Config& operator<<(T x) { this->p_strm<<x; return *this; }
141  };
142 
158  Thread(std::string name,
159  ThreadPriority priority,
160  Runnable *runnable,
162 
178  Thread(Runnable &runnable,
179  std::string name,
180  unsigned int stksize,
181  unsigned int priority=lowestPriority);
182 
185  Thread(Config& c);
186 
190  ~Thread();
191 
192  static size_t num_instances;
193 private:
194  Config::p_owned_runner_t p_owned;
195 };
196 
197 
198 }}
199 #endif /* THREAD_H */
#define epicsThreadPriorityMedium
Definition: epicsThread.h:76
int i
Definition: scan.c:967
static size_t num_instances
Definition: thread.h:192
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
Mark external symbols and entry points for shared libraries.
Config(C *inst, void(C::*meth)())
Definition: thread.h:112
epicsThreadStackSizeClass
Definition: epicsThread.h:89
#define epicsThreadPriorityLow
Definition: epicsThread.h:75
#define epicsShareClass
Definition: shareLib.h:206
Config & operator<<(T x)
Append to thread name string. Argument must be understood by std::ostream::operator<<.
Definition: thread.h:140
Config & run(C *inst, void(C::*meth)())
Thread will execute (inst->*meth)()
Definition: thread.h:128
Create a new thread using the given.
Definition: thread.h:95
#define epicsThreadPriorityHigh
Definition: epicsThread.h:77
C++ wrapper for epicsThread from EPICS base.
Definition: thread.h:65
std::tr1::shared_ptr< epicsThread > EpicsThreadPtr
Definition: thread.h:41
C++ and C descriptions for a thread.
std::tr1::shared_ptr< Thread > ThreadPtr
Definition: thread.h:39
#define EPICS_NOT_COPYABLE(CLASS)
Disable implicit copyable.
epicsThreadRunable Runnable
Definition: thread.h:43