CPN
Computational Process Networks
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
D4R::QueueBase Class Referenceabstract

#include <D4RQueue.h>

+ Inheritance diagram for D4R::QueueBase:
+ Collaboration diagram for D4R::QueueBase:

Public Member Functions

 QueueBase ()
 
virtual ~QueueBase ()
 
void SetReaderNode (shared_ptr< Node > n)
 
void SetWriterNode (shared_ptr< Node > n)
 
virtual void Lock () const =0
 
virtual void Unlock () const =0
 
void SignalReaderTagChanged ()
 
void SignalWriterTagChanged ()
 

Protected Member Functions

void ReadBlock ()
 
void WriteBlock (unsigned qsize)
 
virtual bool ReadBlocked ()=0
 
virtual bool WriteBlocked ()=0
 
virtual void Detect ()=0
 
virtual void UnlockedSignalReaderTagChanged ()
 
virtual void UnlockedSignalWriterTagChanged ()
 
virtual void Wait ()=0
 
virtual void Signal ()=0
 

Protected Attributes

shared_ptr< Nodereader
 
shared_ptr< Nodewriter
 
bool readtagchanged
 
bool writetagchanged
 
bool incomm
 

Private Member Functions

 QueueBase (const QueueBase &)
 
QueueBaseoperator= (const QueueBase &)
 

Detailed Description

The base class for the D4R queue. This class provides methods for the queue to block and override.

Definition at line 39 of file D4RQueue.h.

Constructor & Destructor Documentation

D4R::QueueBase::QueueBase ( )

Definition at line 51 of file D4RQueue.cc.

52  : readtagchanged(false),
53  writetagchanged(false),
54  incomm(false)
55  {}
bool readtagchanged
Definition: D4RQueue.h:124
bool writetagchanged
Definition: D4RQueue.h:125
D4R::QueueBase::~QueueBase ( )
virtual

Reimplemented in CPN::QueueBase.

Definition at line 57 of file D4RQueue.cc.

57 {}
D4R::QueueBase::QueueBase ( const QueueBase )
private

Member Function Documentation

virtual void D4R::QueueBase::Detect ( )
protectedpure virtual

Called by the D4R algorithm when it has detected an artificial deadlock and this queue should be changed.

Implemented in CPN::QueueBase.

Referenced by WriteBlock().

+ Here is the caller graph for this function:

virtual void D4R::QueueBase::Lock ( ) const
pure virtual

These functions are to access the lock for the queue.

Implemented in CPN::QueueBase.

QueueBase& D4R::QueueBase::operator= ( const QueueBase )
private
void D4R::QueueBase::ReadBlock ( )
protected

reader ===> writer ReadBlock requires that you already hold the lock and if it is reentrant then a single unlock will release the lock.

Exceptions
D4R::DeadlockException

Definition at line 71 of file D4RQueue.cc.

References incomm, ReadBlocked(), reader, Signal(), Wait(), writer, and writetagchanged.

Referenced by CPN::QueueBase::WaitForData().

71  {
72  if (!writer) {
73  while (ReadBlocked() && !writer) {
74  Wait();
75  }
76  }
77  if (!ReadBlocked()) { return; }
78  writetagchanged = false;
79  try {
80  while (incomm) { Wait(); }
81  ScopeSetter<bool> ss(incomm, true);
82  AutoUnlock<QueueBase> au(*this);
83  reader->Block(writer->GetPublicTag(), -1);
84  } catch (...) { Signal(); throw; }
85  Signal();
86  while (ReadBlocked()) {
87  if (writetagchanged) {
88  writetagchanged = false;
89  bool detect;
90  try {
91  while (incomm) { Wait(); }
92  ScopeSetter<bool> ss(incomm, true);
93  AutoUnlock<QueueBase> au(*this);
94  detect = reader->Transmit(writer->GetPublicTag());
95  } catch (...) { Signal(); throw; }
96  Signal();
97  if (detect) {
98  throw DeadlockException("True deadlock detected");
99  }
100  } else {
101  Wait();
102  }
103  }
104  }
shared_ptr< Node > reader
Definition: D4RQueue.h:122
virtual void Wait()=0
shared_ptr< Node > writer
Definition: D4RQueue.h:123
virtual bool ReadBlocked()=0
virtual void Signal()=0
bool writetagchanged
Definition: D4RQueue.h:125

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual bool D4R::QueueBase::ReadBlocked ( )
protectedpure virtual
Returns
true if we are blocked

Implemented in CPN::QueueBase.

Referenced by ReadBlock().

+ Here is the caller graph for this function:

void D4R::QueueBase::SetReaderNode ( shared_ptr< Node n)

Set the node which is reading from this queue

Parameters
nthe node

Definition at line 59 of file D4RQueue.cc.

References reader, and Signal().

Referenced by CPN::RemoteQueue::RemoteQueue().

59  {
60  AutoLock<QueueBase> al(*this);
61  reader = n;
62  Signal();
63  }
shared_ptr< Node > reader
Definition: D4RQueue.h:122
virtual void Signal()=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void D4R::QueueBase::SetWriterNode ( shared_ptr< Node n)

Set the node which is writing to this queue.

Parameters
nthe node

Definition at line 65 of file D4RQueue.cc.

References Signal(), and writer.

Referenced by CPN::RemoteQueue::RemoteQueue().

65  {
66  AutoLock<QueueBase> al(*this);
67  writer = n;
68  Signal();
69  }
shared_ptr< Node > writer
Definition: D4RQueue.h:123
virtual void Signal()=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void D4R::QueueBase::Signal ( )
protectedpure virtual

Signal that Wait should return

Implemented in CPN::QueueBase, and CPN::RemoteQueue.

Referenced by ReadBlock(), SetReaderNode(), SetWriterNode(), UnlockedSignalReaderTagChanged(), UnlockedSignalWriterTagChanged(), and WriteBlock().

+ Here is the caller graph for this function:

void D4R::QueueBase::SignalReaderTagChanged ( )

These functions are called by the D4R::Node when thier tag changes.

Definition at line 139 of file D4RQueue.cc.

References UnlockedSignalReaderTagChanged().

139  {
140  AutoLock<QueueBase> al(*this);
142  }
virtual void UnlockedSignalReaderTagChanged()
Definition: D4RQueue.cc:144

+ Here is the call graph for this function:

void D4R::QueueBase::SignalWriterTagChanged ( )

Definition at line 150 of file D4RQueue.cc.

References UnlockedSignalWriterTagChanged().

150  {
151  AutoLock<QueueBase> al(*this);
153  }
virtual void UnlockedSignalWriterTagChanged()
Definition: D4RQueue.cc:155

+ Here is the call graph for this function:

virtual void D4R::QueueBase::Unlock ( ) const
pure virtual

Implemented in CPN::QueueBase.

void D4R::QueueBase::UnlockedSignalReaderTagChanged ( )
protectedvirtual

Reimplemented in CPN::RemoteQueue.

Definition at line 144 of file D4RQueue.cc.

References DEBUG, reader, readtagchanged, Signal(), and writer.

Referenced by CPN::RemoteQueue::D4RTagPacket(), SignalReaderTagChanged(), and CPN::RemoteQueue::UnlockedSignalReaderTagChanged().

144  {
145  DEBUG("%s: (%llu -> %llu)\n", __PRETTY_FUNCTION__, (writer ? writer->GetPrivateTag().Key() : 0), (reader ? reader->GetPrivateTag().Key() : 0));
146  readtagchanged = true;
147  Signal();
148  }
shared_ptr< Node > reader
Definition: D4RQueue.h:122
#define DEBUG(fmt,...)
Definition: D4RQueue.cc:34
shared_ptr< Node > writer
Definition: D4RQueue.h:123
bool readtagchanged
Definition: D4RQueue.h:124
virtual void Signal()=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void D4R::QueueBase::UnlockedSignalWriterTagChanged ( )
protectedvirtual

Reimplemented in CPN::RemoteQueue.

Definition at line 155 of file D4RQueue.cc.

References DEBUG, reader, Signal(), writer, and writetagchanged.

Referenced by CPN::RemoteQueue::D4RTagPacket(), SignalWriterTagChanged(), and CPN::RemoteQueue::UnlockedSignalWriterTagChanged().

155  {
156  DEBUG("%s: (%llu -> %llu)\n", __PRETTY_FUNCTION__, (writer ? writer->GetPrivateTag().Key() : 0), (reader ? reader->GetPrivateTag().Key() : 0));
157  writetagchanged = true;
158  Signal();
159  }
shared_ptr< Node > reader
Definition: D4RQueue.h:122
#define DEBUG(fmt,...)
Definition: D4RQueue.cc:34
shared_ptr< Node > writer
Definition: D4RQueue.h:123
virtual void Signal()=0
bool writetagchanged
Definition: D4RQueue.h:125

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void D4R::QueueBase::Wait ( )
protectedpure virtual

Wait untill Signal is called. Must be holding the lock to call.

Implemented in CPN::QueueBase.

Referenced by ReadBlock(), and WriteBlock().

+ Here is the caller graph for this function:

void D4R::QueueBase::WriteBlock ( unsigned  qsize)
protected

writer ===> reader WriteBlock requires that you already hold the lock and if it is reentrant then a single unlock will release the lock.

Definition at line 106 of file D4RQueue.cc.

References Detect(), incomm, reader, readtagchanged, Signal(), Wait(), WriteBlocked(), and writer.

Referenced by CPN::QueueBase::GetRawEnqueuePtr(), and CPN::QueueBase::WaitForFreespace().

106  {
107  if (!reader) {
108  while (WriteBlocked() && !reader) {
109  Wait();
110  }
111  }
112  if (!WriteBlocked()) { return; }
113  readtagchanged = false;
114  try {
115  while (incomm) { Wait(); }
116  ScopeSetter<bool> ss(incomm, true);
117  AutoUnlock<QueueBase> au(*this);
118  writer->Block(reader->GetPublicTag(), qsize);
119  } catch (...) { Signal(); throw; }
120  Signal();
121  while (WriteBlocked()) {
122  if (readtagchanged) {
123  readtagchanged = false;
124  bool detect;
125  try {
126  while (incomm) { Wait(); }
127  ScopeSetter<bool> ss(incomm, true);
128  AutoUnlock<QueueBase> au(*this);
129  detect = writer->Transmit(reader->GetPublicTag());
130  } catch (...) { Signal(); throw; }
131  Signal();
132  if (detect) { Detect(); }
133  } else {
134  Wait();
135  }
136  }
137  }
virtual void Detect()=0
shared_ptr< Node > reader
Definition: D4RQueue.h:122
virtual bool WriteBlocked()=0
virtual void Wait()=0
shared_ptr< Node > writer
Definition: D4RQueue.h:123
bool readtagchanged
Definition: D4RQueue.h:124
virtual void Signal()=0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual bool D4R::QueueBase::WriteBlocked ( )
protectedpure virtual
Returns
true if we are blocked.

Implemented in CPN::QueueBase.

Referenced by WriteBlock().

+ Here is the caller graph for this function:

Member Data Documentation

bool D4R::QueueBase::incomm
protected

Definition at line 126 of file D4RQueue.h.

Referenced by ReadBlock(), and WriteBlock().

shared_ptr<Node> D4R::QueueBase::reader
protected
bool D4R::QueueBase::readtagchanged
protected

Definition at line 124 of file D4RQueue.h.

Referenced by UnlockedSignalReaderTagChanged(), and WriteBlock().

shared_ptr<Node> D4R::QueueBase::writer
protected
bool D4R::QueueBase::writetagchanged
protected

Definition at line 125 of file D4RQueue.h.

Referenced by ReadBlock(), and UnlockedSignalWriterTagChanged().


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