Pothos  0.3.0-ga8f2d4e2
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
InputPort.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 #include <Pothos/Config.hpp>
13 #include <Pothos/Object/Object.hpp>
19 #include <Pothos/Util/SpinLock.hpp>
20 #include <string>
21 
22 namespace Pothos {
23 
24 class WorkerActor;
25 class OutputPort;
26 
31 {
32 public:
33 
35  ~InputPort(void);
36 
42  int index(void) const;
43 
45  const std::string &name(void) const;
46 
48  const std::string &alias(void) const;
49 
51  void setAlias(const std::string &alias);
52 
54  const DType &dtype(void) const;
55 
57  const std::string &domain(void) const;
58 
63  const BufferChunk &buffer(void) const;
64 
69  size_t elements(void) const;
70 
76  unsigned long long totalElements(void) const;
77 
83  unsigned long long totalBuffers(void) const;
84 
90  unsigned long long totalLabels(void) const;
91 
97  unsigned long long totalMessages(void) const;
98 
100  bool hasMessage(void);
101 
107  const LabelIteratorRange &labels(void) const;
108 
117  void removeLabel(const Label &label);
118 
125  void consume(const size_t numElements);
126 
132  Object popMessage(void);
133 
142  void setReserve(const size_t numElements);
143 
147  bool isSlot(void) const;
148 
156  void pushBuffer(const BufferChunk &buffer);
157 
164  void pushLabel(const Label &label);
165 
170  void pushMessage(const Object &message);
171 
176  void clear(void);
177 
178 private:
179  WorkerActor *_actor;
180 
181  //port configuration
182  bool _isSlot;
183  int _index;
184  std::string _name;
185  std::string _alias;
186  DType _dtype;
187  std::string _domain;
188 
189  //state set in pre-work
190  BufferChunk _buffer;
191  size_t _elements;
192  LabelIteratorRange _labelIter;
193 
194  //port stats
195  unsigned long long _totalElements;
196  unsigned long long _totalBuffers;
197  unsigned long long _totalLabels;
198  unsigned long long _totalMessages;
199 
200  //state changes from work
201  size_t _pendingElements;
202  size_t _reserveElements;
203 
204  //counts work actions which we will use to establish activity
205  size_t _workEvents;
206 
207  Util::SpinLock _asyncMessagesLock;
209 
210  Util::SpinLock _slotCallsLock;
212 
213  std::vector<Label> _inlineMessages; //user api structure
214  Util::RingDeque<Label> _inputInlineMessages; //shared structure
215 
216  Util::SpinLock _bufferAccumulatorLock;
217  BufferAccumulator _bufferAccumulator;
218 
219  std::vector<OutputPort *> _subscribers;
220 
222  void asyncMessagesPush(const Object &message, const BufferChunk &token = BufferChunk::null());
223  bool asyncMessagesEmpty(void);
224  Object asyncMessagesPop(void);
225  void asyncMessagesClear(void);
226 
228  void slotCallsPush(const Object &args, const BufferChunk &token);
229  bool slotCallsEmpty(void);
230  Object slotCallsPop(void);
231  void slotCallsClear(void);
232 
234  void inlineMessagesPush(const Label &label);
235  void inlineMessagesClear(void);
236 
238  void bufferAccumulatorFront(BufferChunk &);
239  void bufferAccumulatorPush(const BufferChunk &buffer);
240  void bufferAccumulatorPushNoLock(const BufferChunk &buffer);
241  void bufferAccumulatorPop(const size_t numBytes);
242  void bufferAccumulatorRequire(const size_t numBytes);
243  void bufferAccumulatorClear(void);
244 
246  void bufferLabelPush(
247  const std::vector<Label> &postedLabels,
248  const Util::RingDeque<BufferChunk> &postedBuffers);
249 
250  InputPort(void);
251  InputPort(const InputPort &){} // non construction-copyable
252  InputPort &operator=(const InputPort &){return *this;} // non copyable
253  friend class WorkerActor;
254  friend class OutputPort;
255 };
256 
257 } //namespace Pothos
Definition: Label.hpp:23
Definition: BufferAccumulator.hpp:31
Definition: Label.hpp:86
#define POTHOS_API
Definition: Config.hpp:41
Definition: OutputPort.hpp:30
Definition: SpinLock.hpp:26
Definition: Object.hpp:55
Definition: InputPort.hpp:30
Definition: RingDeque.hpp:28
Definition: BufferChunk.hpp:26
Definition: DType.hpp:38
static const BufferChunk & null(void)
Get a const reference to a null/empty BufferChunk.