Pothos  0.2.1-g9f04573d
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
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::postBuffer(const BufferChunk &buffer)
93 {
94  auto &queue = _postedBuffers;
95  if (queue.full()) queue.set_capacity(queue.size()*2);
96  queue.push_back(buffer);
97 
98  //unspecified buffer dtype? copy it from the port
99  if (not buffer.dtype) queue.back().dtype = this->dtype();
100 
101  _totalBuffers++;
102  _workEvents++;
103 }
104 
105 inline void Pothos::OutputPort::postLabel(const Label &label)
106 {
107  _postedLabels.push_back(label.toAdjusted(this->dtype().size(), 1));
108  _totalLabels++;
109  _workEvents++;
110 }
111 
112 inline bool Pothos::OutputPort::bufferManagerEmpty(void)
113 {
114  std::lock_guard<Util::SpinLock> lock(_bufferManagerLock);
115  return not _bufferManager or _bufferManager->empty();
116 }
117 
118 inline void Pothos::OutputPort::bufferManagerFront(Pothos::BufferChunk &buff)
119 {
120  std::lock_guard<Util::SpinLock> lock(_bufferManagerLock);
121  if (not _bufferManager) buff = Pothos::BufferChunk();
122  buff = _bufferManager->front();
123 }
124 
125 inline void Pothos::OutputPort::bufferManagerPop(const size_t numBytes)
126 {
127  std::lock_guard<Util::SpinLock> lock(_bufferManagerLock);
128  return _bufferManager->pop(numBytes);
129 }
130 
131 inline bool Pothos::OutputPort::tokenManagerEmpty(void)
132 {
133  std::lock_guard<Util::SpinLock> lock(_tokenManagerLock);
134  return not _tokenManager or _tokenManager->empty();
135 }
136 
137 inline Pothos::BufferChunk Pothos::OutputPort::tokenManagerPop(void)
138 {
139  std::lock_guard<Util::SpinLock> lock(_tokenManagerLock);
140  if (_tokenManager->empty()) return Pothos::BufferChunk();
141  auto tok = _tokenManager->front();
142  _tokenManager->pop(0);
143  return tok;
144 }
145 
146 inline void Pothos::OutputPort::tokenManagerPop(const size_t numBytes)
147 {
148  std::lock_guard<Util::SpinLock> lock(_tokenManagerLock);
149  return _tokenManager->pop(numBytes);
150 }
Definition: Label.hpp:23
unsigned long long totalLabels(void) const
Definition: OutputPortImpl.hpp:55
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:92
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:105
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
int index(void) const
Definition: OutputPortImpl.hpp:15
DType dtype
Definition: BufferChunk.hpp:83
bool isSignal(void) const
Definition: OutputPortImpl.hpp:70
Definition: BufferChunk.hpp:26
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