This is Unofficial EPICS BASE Doxygen Site
WorkQueue Struct Reference

#include "tpool.h"

+ Inheritance diagram for WorkQueue:
+ Collaboration diagram for WorkQueue:

Public Types

typedef std::tr1::weak_ptr< epicsThreadRunable > value_type
 

Public Member Functions

 WorkQueue (const std::string &name)
 
virtual ~WorkQueue ()
 
void start (unsigned nworkers=1, unsigned prio=epicsThreadPriorityLow)
 
void close ()
 
void add (const value_type &work)
 

Detailed Description

Definition at line 18 of file tpool.h.

Member Typedef Documentation

typedef std::tr1::weak_ptr<epicsThreadRunable> WorkQueue::value_type

Definition at line 20 of file tpool.h.

Constructor & Destructor Documentation

WorkQueue::WorkQueue ( const std::string &  name)

Definition at line 18 of file tpool.cpp.

19  :name(name)
20  ,state(Idle)
21 {}
WorkQueue::~WorkQueue ( )
virtual

Definition at line 23 of file tpool.cpp.

23 { close(); }
void close()
Definition: tpool.cpp:52

Member Function Documentation

void WorkQueue::add ( const value_type work)

Definition at line 79 of file tpool.cpp.

80 {
81  bool empty;
82 
83  {
84  Guard G(mutex);
85  if(state!=Active)
86  return;
87 
88  empty = queue.empty();
89 
90  queue.push_back(work);
91  }
92 
93  if(empty) {
94  wakeup.signal();
95  }
96 }
epics::pvData::BitSetPtr empty
Definition: pvAccess.cpp:135
void WorkQueue::close ( )

Definition at line 52 of file tpool.cpp.

53 {
54  workers_t temp;
55 
56  {
57  Guard G(mutex);
58  if(state!=Active)
59  return;
60 
61  temp.swap(workers);
62  state = Stopping;
63  }
64 
65  wakeup.signal();
66 
67  for(workers_t::iterator it(temp.begin()), end(temp.end()); it!=end; ++it)
68  {
69  (*it)->exitWait();
70  delete *it;
71  }
72 
73  {
74  Guard G(mutex);
75  state = Idle;
76  }
77 }
void WorkQueue::start ( unsigned  nworkers = 1,
unsigned  prio = epicsThreadPriorityLow 
)

Definition at line 25 of file tpool.cpp.

26 {
27  Guard G(mutex);
28 
29  if(state!=Idle)
30  throw std::logic_error("Already started");
31 
32  try {
33  state = Active;
34 
35  for(unsigned i=0; i<nworkers; i++) {
36  p2p::auto_ptr<epicsThread> worker(new epicsThread(*this, name.c_str(),
38  prio));
39 
40  worker->start();
41 
42  workers.push_back(worker.get());
43  worker.release();
44  }
45  }catch(...){
46  UnGuard U(G); // unlock as close() blocks to join any workers which were started
47  close();
48  throw;
49  }
50 }
int i
Definition: scan.c:967
void close()
Definition: tpool.cpp:52
LIBCOM_API unsigned int epicsStdCall epicsThreadGetStackSize(epicsThreadStackSizeClass size)
Definition: osdThread.c:466

The documentation for this struct was generated from the following files: