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

#include <D4RNode.h>

+ Collaboration diagram for D4R::Node:

Public Member Functions

 Node (uint64_t key)
 
 ~Node ()
 
Tag GetPublicTag () const
 
void SetPublicTag (const Tag &t)
 
Tag GetPrivateTag () const
 
void SetPrivateTag (const Tag &t)
 
void AddReader (weak_ptr< QueueBase > q)
 
void AddWriter (weak_ptr< QueueBase > q)
 
void Block (const Tag &t, unsigned qsize)
 
bool Transmit (const Tag &t)
 

Protected Member Functions

void SignalTagChanged ()
 

Protected Attributes

Tag publicTag
 
Tag privateTag
 
PthreadMutex taglock
 
std::list< weak_ptr< QueueBase > > readerlist
 
std::list< weak_ptr< QueueBase > > writerlist
 

Private Member Functions

 Node (const Node &)
 
Nodeoperator= (const Node &)
 

Detailed Description

The node for the D4R algorithm.

Each node has a list of readers and writers. When an action that changes the Tag happens these readers and writers are notified. Note that SetPrivateTag and SetPublicTag do not notify the readers and writers.

Definition at line 84 of file D4RNode.h.

Constructor & Destructor Documentation

D4R::Node::Node ( uint64_t  key)

Definition at line 38 of file D4RNode.cc.

39  : publicTag(key),
40  privateTag(key)
41  {
42  }
Tag publicTag
Definition: D4RNode.h:126
Tag privateTag
Definition: D4RNode.h:127
D4R::Node::~Node ( )

Definition at line 44 of file D4RNode.cc.

44 {}
D4R::Node::Node ( const Node )
private

Member Function Documentation

void D4R::Node::AddReader ( weak_ptr< QueueBase q)
Parameters
qadd the q to the readers.

Definition at line 107 of file D4RNode.cc.

References readerlist, and taglock.

107  {
109  readerlist.push_back(q);
110  }
PthreadMutex taglock
Definition: D4RNode.h:128
std::list< weak_ptr< QueueBase > > readerlist
Definition: D4RNode.h:129
void D4R::Node::AddWriter ( weak_ptr< QueueBase q)
Parameters
qAdd the q to the writers.

Definition at line 111 of file D4RNode.cc.

References taglock, and writerlist.

111  {
113  writerlist.push_back(q);
114  }
std::list< weak_ptr< QueueBase > > writerlist
Definition: D4RNode.h:130
PthreadMutex taglock
Definition: D4RNode.h:128
void D4R::Node::Block ( const Tag t,
unsigned  qsize 
)

Perform the block operation. Note the caller cannot be holding any queue locks.

Parameters
tThe tag of the node we are blocking on
qsizeThe size of the queue if we are blocking on write or -1 if we are blocking on read.

Definition at line 66 of file D4RNode.cc.

References D4R::Tag::Count(), DEBUG, D4R::Tag::Key(), privateTag, publicTag, D4R::Tag::QueueSize(), SignalTagChanged(), taglock, and AutoLock< Lockable >::Unlock().

66  {
68  privateTag.QueueSize(qsize);
69  privateTag.Count(std::max(publicTag.Count(), t.Count()) + 1);
70  DEBUG("Node %llu:%llu block %d\n", privateTag.Count(), privateTag.Key(), (int)privateTag.QueueSize());
72  al.Unlock();
74  }
#define DEBUG(fmt,...)
Definition: D4RNode.cc:33
Tag publicTag
Definition: D4RNode.h:126
uint64_t Key() const
Definition: D4RTag.h:62
PthreadMutex taglock
Definition: D4RNode.h:128
void SignalTagChanged()
Definition: D4RNode.cc:140
Tag privateTag
Definition: D4RNode.h:127
uint64_t QueueSize() const
Definition: D4RTag.h:66
uint64_t Count() const
Definition: D4RTag.h:58

+ Here is the call graph for this function:

Tag D4R::Node::GetPrivateTag ( ) const

Definition at line 56 of file D4RNode.cc.

References privateTag, and taglock.

56  {
58  return privateTag;
59  }
PthreadMutex taglock
Definition: D4RNode.h:128
Tag privateTag
Definition: D4RNode.h:127
Tag D4R::Node::GetPublicTag ( ) const

Definition at line 46 of file D4RNode.cc.

References publicTag, and taglock.

46  {
48  return publicTag;
49  }
Tag publicTag
Definition: D4RNode.h:126
PthreadMutex taglock
Definition: D4RNode.h:128
Node& D4R::Node::operator= ( const Node )
private
void D4R::Node::SetPrivateTag ( const Tag t)

Definition at line 61 of file D4RNode.cc.

References privateTag, and taglock.

61  {
63  privateTag = t;
64  }
PthreadMutex taglock
Definition: D4RNode.h:128
Tag privateTag
Definition: D4RNode.h:127
void D4R::Node::SetPublicTag ( const Tag t)

Definition at line 51 of file D4RNode.cc.

References publicTag, and taglock.

51  {
53  publicTag = t;
54  }
Tag publicTag
Definition: D4RNode.h:126
PthreadMutex taglock
Definition: D4RNode.h:128
void D4R::Node::SignalTagChanged ( )
protected

Definition at line 140 of file D4RNode.cc.

References D4R::GetQueues(), readerlist, D4R::SignalReader(), D4R::SignalWriter(), taglock, and writerlist.

Referenced by Block(), and Transmit().

140  {
141  std::list<shared_ptr<QueueBase> > readers;
142  std::list<shared_ptr<QueueBase> > writers;
143  {
145  GetQueues(readerlist, readers);
146  GetQueues(writerlist, writers);
147  }
148  std::for_each(readers.begin(), readers.end(), &SignalReader);
149  std::for_each(writers.begin(), writers.end(), &SignalWriter);
150  }
void SignalWriter(shared_ptr< QueueBase > q)
Definition: D4RNode.cc:120
std::list< weak_ptr< QueueBase > > writerlist
Definition: D4RNode.h:130
PthreadMutex taglock
Definition: D4RNode.h:128
void GetQueues(QueueList &qlist, std::list< shared_ptr< QueueBase > > &out)
Definition: D4RNode.cc:125
void SignalReader(shared_ptr< QueueBase > q)
Definition: D4RNode.cc:116
std::list< weak_ptr< QueueBase > > readerlist
Definition: D4RNode.h:129

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool D4R::Node::Transmit ( const Tag t)

Called by the queue when the Tag on the node we are blocked on changes. Note the caller cannot be holding any queue locks.

Parameters
tThe new tag.
Returns
true if we have detected deadlock false otherwise.

Definition at line 76 of file D4RNode.cc.

References D4R::Tag::Count(), DEBUG, D4R::Tag::Key(), D4R::Tag::Priority(), privateTag, publicTag, D4R::Tag::QueueKey(), D4R::Tag::QueueSize(), SignalTagChanged(), taglock, and AutoLock< Lockable >::Unlock().

76  {
78  if (publicTag < t) {
79 
80  DEBUG("Transfer: publicTag < t\n\tPrivate: (%llu, %llu, %d, %llu)\n\tPublic: (%llu, %llu, %d, %llu)\n\t t: (%llu, %llu, %d, %llu)\n",
83  t.Count(), t.Key(), (int)t.QueueSize(), t.QueueKey());
84 
85  uint128_t priority = std::min(privateTag.Priority(), t.Priority());
86  publicTag = t;
87  publicTag.Priority(priority);
88  al.Unlock();
90  } else if (publicTag == t) {
91 
92  DEBUG("Transfer: publicTag == t\n\tPrivate: (%llu, %llu, %d, %llu)\n\tPublic: (%llu, %llu, %d, %llu)\n\t t: (%llu, %llu, %d, %llu)\n",
94  publicTag.Count(), publicTag.Key(), (int)publicTag.QueueSize(), publicTag.QueueKey(),
95  t.Count(), t.Key(), (int)t.QueueSize(), t.QueueKey());
96 
97  return publicTag.Priority() == privateTag.Priority();
98  } else {
99  DEBUG("Transfer: publicTag > t NOP\n\tPrivate: (%llu, %llu, %d, %llu)\n\tPublic: (%llu, %llu, %d, %llu)\n\t t: (%llu, %llu, %d, %llu)\n",
101  publicTag.Count(), publicTag.Key(), (int)publicTag.QueueSize(), publicTag.QueueKey(),
102  t.Count(), t.Key(), (int)t.QueueSize(), t.QueueKey());
103  }
104  return false;
105  }
#define DEBUG(fmt,...)
Definition: D4RNode.cc:33
uint64_t QueueKey() const
Definition: D4RTag.h:71
Tag publicTag
Definition: D4RNode.h:126
uint64_t Key() const
Definition: D4RTag.h:62
PthreadMutex taglock
Definition: D4RNode.h:128
void SignalTagChanged()
Definition: D4RNode.cc:140
const uint128_t & Priority() const
Definition: D4RTag.h:76
Tag privateTag
Definition: D4RNode.h:127
uint64_t QueueSize() const
Definition: D4RTag.h:66
uint64_t Count() const
Definition: D4RTag.h:58

+ Here is the call graph for this function:

Member Data Documentation

Tag D4R::Node::privateTag
protected

Definition at line 127 of file D4RNode.h.

Referenced by Block(), GetPrivateTag(), SetPrivateTag(), and Transmit().

Tag D4R::Node::publicTag
protected

Definition at line 126 of file D4RNode.h.

Referenced by Block(), GetPublicTag(), SetPublicTag(), and Transmit().

std::list<weak_ptr<QueueBase> > D4R::Node::readerlist
protected

Definition at line 129 of file D4RNode.h.

Referenced by AddReader(), and SignalTagChanged().

PthreadMutex D4R::Node::taglock
mutableprotected
std::list<weak_ptr<QueueBase> > D4R::Node::writerlist
protected

Definition at line 130 of file D4RNode.h.

Referenced by AddWriter(), and SignalTagChanged().


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