5 #include <epicsEvent.h>
6 #include <epicsGuard.h>
7 #include <epicsThread.h>
10 #include <pv/sharedPtr.h>
15 typedef epicsGuard<epicsMutex> Guard;
16 typedef epicsGuardRelease<epicsMutex> UnGuard;
18 WorkQueue::WorkQueue(
const std::string& name)
23 WorkQueue::~WorkQueue() { close(); }
25 void WorkQueue::start(
unsigned nworkers,
unsigned prio)
30 throw std::logic_error(
"Already started");
35 for(
unsigned i=0; i<nworkers; i++) {
36 p2p::auto_ptr<epicsThread> worker(
new epicsThread(*
this, name.c_str(),
37 epicsThreadGetStackSize(epicsThreadStackSmall),
42 workers.push_back(worker.get());
52 void WorkQueue::close()
67 for(workers_t::iterator it(temp.begin()), end(temp.end()); it!=end; ++it)
79 void WorkQueue::add(
const value_type& work)
88 empty = queue.empty();
90 queue.push_back(work);
102 std::tr1::shared_ptr<epicsThreadRunable> work;
104 while(state==Active) {
107 work = queue.front().lock();
111 bool last = queue.empty();
120 }
catch(std::exception& e){
121 errlogPrintf(
"%s Unhandled exception from %s: %s\n",
122 name.c_str(),
typeid(work.get()).name(), e.what());