pva2pva 1.4.2
Loading...
Searching...
No Matches
tpool.h
1#ifndef TPOOL_H
2#define TPOOL_H
3
4#include <stdexcept>
5#include <deque>
6#include <vector>
7#include <string>
8
9#include <errlog.h>
10#include <epicsThread.h>
11#include <epicsMutex.h>
12#include <epicsEvent.h>
13
14#include <pv/sharedPtr.h>
15
16struct WorkQueue : private epicsThreadRunable
17{
18 typedef std::tr1::weak_ptr<epicsThreadRunable> value_type;
19
20private:
21 const std::string name;
22
23 epicsMutex mutex;
24
25 enum state_t {
26 Idle,
27 Active,
28 Stopping,
29 } state;
30
31 typedef std::deque<value_type> queue_t;
32 queue_t queue;
33
34 epicsEvent wakeup;
35
36 typedef std::vector<epicsThread*> workers_t;
37 workers_t workers;
38
39public:
40 WorkQueue(const std::string& name);
41 virtual ~WorkQueue();
42
43 void start(unsigned nworkers=1, unsigned prio = epicsThreadPriorityLow);
44 void close();
45
46 void add(const value_type& work);
47
48private:
49 virtual void run();
50};
51
52#endif // TPOOL_H