Pothos  0.7.0-gf7fbae99
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 Pothos::BufferChunk Pothos::OutputPort::getBuffer(const size_t numElements)
71 {
72  return this->getBuffer(_dtype, numElements);
73 }
74 
75 inline bool Pothos::OutputPort::isSignal(void) const
76 {
77  return _isSignal;
78 }
79 
81 {
82  _readBeforeWritePort = port;
83 }
84 
85 template <typename ValueType>
86 void Pothos::OutputPort::postMessage(ValueType &&message)
87 {
88  Pothos::OutputPort::_postMessage(Pothos::Object(std::forward<ValueType>(message)));
89 }
90 
91 template <typename T, typename... Args>
93 {
94  Pothos::OutputPort::_postMessage(Pothos::Object::emplace<T>(std::forward<Args>(args)...));
95 }
96 
97 inline void Pothos::OutputPort::popElements(const size_t numElements)
98 {
99  this->bufferManagerPop(numElements*this->dtype().size());
100  _workEvents++;
101 }
102 
103 template <typename ValueType>
104 inline void Pothos::OutputPort::postBuffer(ValueType &&buffer)
105 {
106  auto &queue = _postedBuffers;
107  if (queue.full()) queue.set_capacity(queue.size()*2);
108  auto &r = queue.emplace_back(std::forward<ValueType>(buffer));
109 
110  //unspecified buffer dtype? copy it from the port
111  if (not r.dtype) r.dtype = this->dtype();
112 
113  _totalElements += r.elements();
114  _totalBuffers++;
115  _workEvents++;
116 }
117 
118 template <typename... ValueType>
119 inline void Pothos::OutputPort::postLabel(ValueType&&... label)
120 {
121  _postedLabels.emplace_back(std::forward<ValueType>(label)...);
122  _postedLabels.back().adjust(this->dtype().size(), 1);
123  _totalLabels++;
124  _workEvents++;
125 }
126 
127 inline void Pothos::OutputPort::setReserve(const size_t numElements)
128 {
129  //only mark this change when setting a larger reserve
130  if (numElements > _reserveElements) _workEvents++;
131 
132  _reserveElements = numElements;
133 }
134 
135 inline bool Pothos::OutputPort::bufferManagerEmpty(void)
136 {
137  std::lock_guard<Util::SpinLock> lock(_bufferManagerLock);
138  return not _bufferManager or _bufferManager->empty();
139 }
140 
141 inline void Pothos::OutputPort::bufferManagerFront(Pothos::BufferChunk &buff)
142 {
143  std::lock_guard<Util::SpinLock> lock(_bufferManagerLock);
144  buff = _bufferManager?_bufferManager->front():Pothos::BufferChunk();
145 }
146 
147 inline void Pothos::OutputPort::bufferManagerPop(const size_t numBytes)
148 {
149  std::lock_guard<Util::SpinLock> lock(_bufferManagerLock);
150  return _bufferManager->pop(numBytes);
151 }
152 
153 inline bool Pothos::OutputPort::tokenManagerEmpty(void)
154 {
155  std::lock_guard<Util::SpinLock> lock(_tokenManagerLock);
156  return not _tokenManager or _tokenManager->empty();
157 }
158 
159 inline Pothos::BufferChunk Pothos::OutputPort::tokenManagerPop(void)
160 {
161  std::lock_guard<Util::SpinLock> lock(_tokenManagerLock);
162  if (_tokenManager->empty()) return Pothos::BufferChunk();
163  auto tok = _tokenManager->front();
164  _tokenManager->pop(0);
165  return tok;
166 }
167 
168 inline void Pothos::OutputPort::tokenManagerPop(const size_t numBytes)
169 {
170  std::lock_guard<Util::SpinLock> lock(_tokenManagerLock);
171  return _tokenManager->pop(numBytes);
172 }
void postLabel(ValueType &&... label)
Definition: OutputPortImpl.hpp:119
int index(void) const
Definition: OutputPortImpl.hpp:15
void popElements(const size_t numElements)
Definition: OutputPortImpl.hpp:97
unsigned long long totalElements(void) const
Definition: OutputPortImpl.hpp:45
const std::string & domain(void) const
Get the domain information for this port.
Definition: OutputPortImpl.hpp:30
const BufferChunk & buffer(void) const
Definition: OutputPortImpl.hpp:35
unsigned long long totalLabels(void) const
Definition: OutputPortImpl.hpp:55
unsigned long long totalMessages(void) const
Definition: OutputPortImpl.hpp:60
const DType & dtype(void) const
Get the data type information for this port.
Definition: OutputPortImpl.hpp:25
Definition: Object.hpp:47
Definition: InputPort.hpp:30
const std::string & name(void) const
Get the string name identifier for this port.
Definition: OutputPortImpl.hpp:20
void produce(const size_t numElements)
Definition: OutputPortImpl.hpp:65
bool isSignal(void) const
Definition: OutputPortImpl.hpp:75
void postBuffer(ValueType &&buffer)
Definition: OutputPortImpl.hpp:104
unsigned long long totalBuffers(void) const
Definition: OutputPortImpl.hpp:50
BufferChunk getBuffer(const size_t numElements)
Definition: OutputPortImpl.hpp:70
void setReserve(const size_t numElements)
Definition: OutputPortImpl.hpp:127
size_t elements(void) const
Definition: OutputPortImpl.hpp:40
Definition: BufferChunk.hpp:30
Definition: DType.hpp:38
void setReadBeforeWrite(InputPort *port)
Definition: OutputPortImpl.hpp:80
void postMessage(ValueType &&message)
Definition: OutputPortImpl.hpp:86
void emplaceMessage(Args &&... args)
Definition: OutputPortImpl.hpp:92