This is Unofficial EPICS BASE Doxygen Site
channelConnectThread.cpp
Go to the documentation of this file.
1 
11 #include "caChannel.h"
12 #include <epicsExit.h>
13 #define epicsExportSharedSymbols
14 #include "channelConnectThread.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 ChannelConnectThreadPtr master;
26  static Mutex mutex;
27  Lock xx(mutex);
28  if(!master) {
30  master->start();
31  }
32  return master;
33 }
34 
35 ChannelConnectThread::ChannelConnectThread()
36 : isStop(false)
37 {
38 }
39 
40 ChannelConnectThread::~ChannelConnectThread()
41 {
42 //std::cout << "ChannelConnectThread::~ChannelConnectThread()\n";
43 }
44 
45 
46 void ChannelConnectThread::start()
47 {
48  thread = std::tr1::shared_ptr<epicsThread>(new epicsThread(
49  *this,
50  "channelConnectThread",
53  thread->start();
54 }
55 
56 
57 void ChannelConnectThread::stop()
58 {
59  {
60  Lock xx(mutex);
61  isStop = true;
62  }
63  waitForCommand.signal();
64  waitForStop.wait();
65 }
66 
67 void ChannelConnectThread::channelConnected(
68  NotifyChannelRequesterPtr const &notifyChannelRequester)
69 {
70  {
71  Lock lock(mutex);
72  if(notifyChannelRequester->isOnQueue) return;
73  notifyChannelRequester->isOnQueue = true;
74  notifyChannelQueue.push(notifyChannelRequester);
75  }
76  waitForCommand.signal();
77 }
78 
79 void ChannelConnectThread::run()
80 {
81  while(true)
82  {
83  waitForCommand.wait();
84  while(true) {
85  bool more = false;
86  NotifyChannelRequester* notifyChannelRequester(NULL);
87  {
88  Lock lock(mutex);
89  if(!notifyChannelQueue.empty())
90  {
91  more = true;
92  NotifyChannelRequesterWPtr req(notifyChannelQueue.front());
93  notifyChannelQueue.pop();
94  NotifyChannelRequesterPtr reqPtr(req.lock());
95  if(reqPtr) {
96  notifyChannelRequester = reqPtr.get();
97  reqPtr->isOnQueue = false;
98  }
99  }
100  }
101  if(!more) break;
102  if(notifyChannelRequester!=NULL)
103  {
104  CAChannelPtr channel(notifyChannelRequester->channel.lock());
105  if(channel) channel->notifyClient();
106  }
107  }
108  if(isStop) {
109  waitForStop.signal();
110  break;
111  }
112  }
113 }
114 
115 }}}
epicsMutexId lock
Definition: osiClockTime.c:37
std::tr1::weak_ptr< NotifyChannelRequester > NotifyChannelRequesterWPtr
Definition: memory.hpp:41
std::tr1::shared_ptr< NotifyChannelRequester > NotifyChannelRequesterPtr
Definition: caChannel.h:37
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< CAChannel > CAChannelPtr
Definition: caChannel.h:31
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.
Definition: caget.c:48
epicsMutex Mutex
Definition: lock.h:28
std::tr1::shared_ptr< ChannelConnectThread > ChannelConnectThreadPtr
Definition: caChannel.h:34