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