This is Unofficial EPICS BASE Doxygen Site
putDoneThread.cpp
Go to the documentation of this file.
1 
11 #include "caChannel.h"
12 #include <epicsExit.h>
13 #define epicsExportSharedSymbols
14 #include "putDoneThread.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 PutDoneThreadPtr master;
26  static Mutex mutex;
27  Lock xx(mutex);
28  if(!master) {
29  master = PutDoneThreadPtr(new PutDoneThread());
30  master->start();
31  }
32  return master;
33 }
34 
35 PutDoneThread::PutDoneThread()
36 : isStop(false)
37 {
38 }
39 
40 PutDoneThread::~PutDoneThread()
41 {
42 //std::cout << "PutDoneThread::~PutDoneThread()\n";
43 }
44 
45 
46 void PutDoneThread::start()
47 {
48  thread = std::tr1::shared_ptr<epicsThread>(new epicsThread(
49  *this,
50  "putDoneThread",
53  thread->start();
54 }
55 
56 
57 void PutDoneThread::stop()
58 {
59  {
60  Lock xx(mutex);
61  isStop = true;
62  }
63  waitForCommand.signal();
64  waitForStop.wait();
65 }
66 
67 void PutDoneThread::putDone(NotifyPutRequesterPtr const &notifyPutRequester)
68 {
69  {
70  Lock lock(mutex);
71  if(notifyPutRequester->isOnQueue) return;
72  notifyPutRequester->isOnQueue = true;
73  notifyPutQueue.push(notifyPutRequester);
74  }
75  waitForCommand.signal();
76 }
77 
78 void PutDoneThread::run()
79 {
80  while(true)
81  {
82  waitForCommand.wait();
83  while(true) {
84  bool more = false;
85  NotifyPutRequester* notifyPutRequester(NULL);
86  {
87  Lock lock(mutex);
88  if(!notifyPutQueue.empty())
89  {
90  more = true;
91  NotifyPutRequesterWPtr req(notifyPutQueue.front());
92  notifyPutQueue.pop();
93  NotifyPutRequesterPtr reqPtr(req.lock());
94  if(reqPtr) {
95  notifyPutRequester = reqPtr.get();
96  reqPtr->isOnQueue = false;
97  }
98  }
99  }
100  if(!more) break;
101  if(notifyPutRequester!=NULL)
102  {
103  CAChannelPutPtr channelPut(notifyPutRequester->channelPut.lock());
104  if(channelPut) channelPut->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
LIBCOM_API unsigned int epicsStdCall epicsThreadGetStackSize(epicsThreadStackSizeClass size)
Definition: osdThread.c:466
std::tr1::shared_ptr< PutDoneThread > PutDoneThreadPtr
Definition: caChannel.h:54
pvData
Definition: monitor.h:428
epicsMutex mutex
Definition: pvAccess.cpp:71
#define epicsThreadPriorityLow
Definition: epicsThread.h:75
Extended replacement for the Posix exit and atexit routines.
std::tr1::shared_ptr< CAChannelPut > CAChannelPutPtr
Definition: caChannel.h:60
std::tr1::weak_ptr< NotifyPutRequester > NotifyPutRequesterWPtr
Definition: caChannel.h:53
std::tr1::shared_ptr< NotifyPutRequester > NotifyPutRequesterPtr
Definition: caChannel.h:51
Definition: caget.c:48
epicsMutex Mutex
Definition: lock.h:28