This is Unofficial EPICS BASE Doxygen Site
getDoneThread.cpp
Go to the documentation of this file.
1 
11 #include "caChannel.h"
12 #include <epicsExit.h>
13 #define epicsExportSharedSymbols
14 #include "getDoneThread.h"
15 
16 using namespace epics::pvData;
17 using namespace std;
18 
19 namespace epics {
20 namespace pvAccess {
21 namespace ca {
22 
24 {
25  static GetDoneThreadPtr master;
26  static Mutex mutex;
27  Lock xx(mutex);
28  if(!master) {
29  master = GetDoneThreadPtr(new GetDoneThread());
30  master->start();
31  }
32  return master;
33 }
34 
35 GetDoneThread::GetDoneThread()
36 : isStop(false)
37 {
38 }
39 
40 GetDoneThread::~GetDoneThread()
41 {
42 //std::cout << "GetDoneThread::~GetDoneThread()\n";
43 }
44 
45 
46 void GetDoneThread::start()
47 {
48  thread = std::tr1::shared_ptr<epicsThread>(new epicsThread(
49  *this,
50  "getDoneThread",
53  thread->start();
54 }
55 
56 
57 void GetDoneThread::stop()
58 {
59  {
60  Lock xx(mutex);
61  isStop = true;
62  }
63  waitForCommand.signal();
64  waitForStop.wait();
65 }
66 
67 void GetDoneThread::getDone(NotifyGetRequesterPtr const &notifyGetRequester)
68 {
69  {
70  Lock lock(mutex);
71  if(notifyGetRequester->isOnQueue) return;
72  notifyGetRequester->isOnQueue = true;
73  notifyGetQueue.push(notifyGetRequester);
74  }
75  waitForCommand.signal();
76 }
77 
78 void GetDoneThread::run()
79 {
80  while(true)
81  {
82  waitForCommand.wait();
83  while(true) {
84  bool more = false;
85  NotifyGetRequester* notifyGetRequester(NULL);
86  {
87  Lock lock(mutex);
88  if(!notifyGetQueue.empty())
89  {
90  more = true;
91  NotifyGetRequesterWPtr req(notifyGetQueue.front());
92  notifyGetQueue.pop();
93  NotifyGetRequesterPtr reqPtr(req.lock());
94  if(reqPtr) {
95  notifyGetRequester = reqPtr.get();
96  reqPtr->isOnQueue = false;
97  }
98  }
99  }
100  if(!more) break;
101  if(notifyGetRequester!=NULL)
102  {
103  CAChannelGetPtr channelGet(notifyGetRequester->channelGet.lock());
104  if(channelGet) channelGet->notifyClient();
105  }
106  }
107  if(isStop) {
108  waitForStop.signal();
109  break;
110  }
111  }
112 }
113 
114 }}}
epicsMutexId lock
Definition: osiClockTime.c:37
Definition: memory.hpp:41
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
A lock for multithreading.
Definition: lock.h:36
#define NULL
Definition: catime.c:38
std::tr1::weak_ptr< NotifyGetRequester > NotifyGetRequesterWPtr
Definition: caChannel.h:47
LIBCOM_API unsigned int epicsStdCall epicsThreadGetStackSize(epicsThreadStackSizeClass size)
Definition: osdThread.c:466
pvData
Definition: monitor.h:428
std::tr1::shared_ptr< NotifyGetRequester > NotifyGetRequesterPtr
Definition: caChannel.h:45
epicsMutex mutex
Definition: pvAccess.cpp:71
#define epicsThreadPriorityLow
Definition: epicsThread.h:75
Extended replacement for the Posix exit and atexit routines.
Definition: caget.c:48
std::tr1::shared_ptr< CAChannelGet > CAChannelGetPtr
Definition: caChannel.h:63
epicsMutex Mutex
Definition: lock.h:28
std::tr1::shared_ptr< GetDoneThread > GetDoneThreadPtr
Definition: caChannel.h:48