Pothos  0.4.3-gabce2ce6
The Pothos dataflow programming software suite
OutputPortImpl.hpp
Go to the documentation of this file.
1 
11 #pragma once
13 #include <mutex> //lock_guard
14 
15 inline int Pothos::OutputPort::index(void) const
16 {
17  return _index;
18 }
19 
20 inline const std::string &Pothos::OutputPort::name(void) const
21 {
22  return _name;
23 }
24 
25 inline const Pothos::DType &Pothos::OutputPort::dtype(void) const
26 {
27  return _dtype;
28 }
29 
30 inline const std::string &Pothos::OutputPort::domain(void) const
31 {
32  return _domain;
33 }
34 
36 {
37  return _buffer;
38 }
39 
40 inline size_t Pothos::OutputPort::elements(void) const
41 {
42  return _elements;
43 }
44 
45 inline unsigned long long Pothos::OutputPort::totalElements(void) const
46 {
47  return _totalElements;
48 }
49 
50 inline unsigned long long Pothos::OutputPort::totalBuffers(void) const
51 {
52  return _totalBuffers;
53 }
54 
55 inline unsigned long long Pothos::OutputPort::totalLabels(void) const
56 {
57  return _totalLabels;
58 }
59 
60 inline unsigned long long Pothos::OutputPort::totalMessages(void) const
61 {
62  return _totalMessages;
63 }
64 
65 inline void Pothos::OutputPort::produce(const size_t numElements)
66 {
67  _pendingElements += numElements;
68 }
69 
70 inline bool Pothos::OutputPort::isSignal(void) const
71 {
72  return _isSignal;
73 }
74 
76 {
77  _readBeforeWritePort = port;
78 }
79 
80 template <typename ValueType>
81 void Pothos::OutputPort::postMessage(ValueType &&message)
82 {
83  Pothos::OutputPort::_postMessage(Pothos::Object(std::forward<ValueType>(message)));
84 }
85 
86 inline void Pothos::OutputPort::popBuffer(const size_t numBytes)
87 {
88  this->bufferManagerPop(numBytes);
89  _workEvents++;
90 }
91 
92 inline void Pothos::OutputPort::popElements(const size_t numElements)
93 {
94  this->bufferManagerPop(numElements*this->dtype().size());
95  _workEvents++;
96 }
97 
99 {
100  auto &queue = _postedBuffers;
101  if (queue.full()) queue.set_capacity(queue.size()*2);
102  queue.push_back(buffer);
103 
104  //unspecified buffer dtype? copy it from the port
105  if (not buffer.dtype) queue.back().dtype = this->dtype();
106 
107  _totalBuffers++;
108  _workEvents++;
109 }
110 
111 inline void Pothos::OutputPort::postLabel(const Label &label)
112 {
113  _postedLabels.push_back(label.toAdjusted(this->dtype().size(), 1));
114  _totalLabels++;
115  _workEvents++;
116 }
117 
118 inline void Pothos::OutputPort::setReserve(const size_t numElements)
119 {
120  //only mark this change when setting a larger reserve
121  if (numElements > _reserveElements) _workEvents++;
122 
123  _reserveElements = numElements;
124 }
125 
126 inline bool Pothos::OutputPort::bufferManagerEmpty(void)
127 {
128  std::lock_guard<Util::SpinLock> lock(_bufferManagerLock);
129  return not _bufferManager or _bufferManager->empty();
130 }
131 
132 inline void Pothos::OutputPort::bufferManagerFront(Pothos::BufferChunk &buff)
133 {
134  std::lock_guard<Util::SpinLock> lock(_bufferManagerLock);
135  if (not _bufferManager) buff = Pothos::BufferChunk();
136  buff = _bufferManager->front();
137 }
138 
139 inline void Pothos::OutputPort::bufferManagerPop(const size_t numBytes)
140 {
141  std::lock_guard<Util::SpinLock> lock(_bufferManagerLock);
142  return _bufferManager->pop(numBytes);
143 }
144 
145 inline bool Pothos::OutputPort::tokenManagerEmpty(void)
146 {
147  std::lock_guard<Util::SpinLock> lock(_tokenManagerLock);
148  return not _tokenManager or _tokenManager->empty();
149 }
150 
151 inline Pothos::BufferChunk Pothos::OutputPort::tokenManagerPop(void)
152 {
153  std::lock_guard<Util::SpinLock> lock(_tokenManagerLock);
154  if (_tokenManager->empty()) return Pothos::BufferChunk();
155  auto tok = _tokenManager->front();
156  _tokenManager->pop(0);
157  return tok;
158 }
159 
160 inline void Pothos::OutputPort::tokenManagerPop(const size_t numBytes)
161 {
162  std::lock_guard<Util::SpinLock> lock(_tokenManagerLock);
163  return _tokenManager->pop(numBytes);
164 }
Definition: Label.hpp:23
unsigned long long totalLabels(void) const
Definition: OutputPortImpl.hpp:55
void popElements(const size_t numElements)
Definition: OutputPortImpl.hpp:92
size_t elements(void) const
Definition: OutputPortImpl.hpp:40
const std::string & name(void) const
Get the string name identifier for this port.
Definition: OutputPortImpl.hpp:20
void popBuffer(const size_t numBytes)
Definition: OutputPortImpl.hpp:86
Label toAdjusted(const MultType &mult, const DivType &div) const
void postBuffer(const BufferChunk &buffer)
Definition: OutputPortImpl.hpp:98
unsigned long long totalElements(void) const
Definition: OutputPortImpl.hpp:45
const DType & dtype(void) const
Get the data type information for this port.
Definition: OutputPortImpl.hpp:25
Definition: Object.hpp:55
Definition: InputPort.hpp:30
void produce(const size_t numElements)
Definition: OutputPortImpl.hpp:65
void postLabel(const Label &label)
Definition: OutputPortImpl.hpp:111
const BufferChunk & buffer(void) const
Definition: OutputPortImpl.hpp:35
const std::string & domain(void) const
Get the domain information for this port.
Definition: OutputPortImpl.hpp:30
void setReserve(const size_t numElements)
Definition: OutputPortImpl.hpp:118
int index(void) const
Definition: OutputPortImpl.hpp:15
DType dtype
Definition: BufferChunk.hpp:102
bool isSignal(void) const
Definition: OutputPortImpl.hpp:70
Definition: BufferChunk.hpp:30
Definition: DType.hpp:38
unsigned long long totalMessages(void) const
Definition: OutputPortImpl.hpp:60
void setReadBeforeWrite(InputPort *port)
Definition: OutputPortImpl.hpp:75
void postMessage(ValueType &&message)
Definition: OutputPortImpl.hpp:81
unsigned long long totalBuffers(void) const
Definition: OutputPortImpl.hpp:50