Pothos  0.3.3-g32d3017c
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 
146  void setReserve(const size_t numElements);
147 
151  bool isSlot(void) const;
152 
160  void pushBuffer(const BufferChunk &buffer);
161 
168  void pushLabel(const Label &label);
169 
174  void pushMessage(const Object &message);
175 
180  void clear(void);
181 
182 private:
183  WorkerActor *_actor;
184 
185  //port configuration
186  bool _isSlot;
187  int _index;
188  std::string _name;
189  std::string _alias;
190  DType _dtype;
191  std::string _domain;
192 
193  //state set in pre-work
194  BufferChunk _buffer;
195  size_t _elements;
196  LabelIteratorRange _labelIter;
197 
198  //port stats
199  unsigned long long _totalElements;
200  unsigned long long _totalBuffers;
201  unsigned long long _totalLabels;
202  unsigned long long _totalMessages;
203 
204  //state changes from work
205  size_t _pendingElements;
206  size_t _reserveElements;
207 
208  //counts work actions which we will use to establish activity
209  size_t _workEvents;
210 
211  Util::SpinLock _asyncMessagesLock;
213 
214  Util::SpinLock _slotCallsLock;
216 
217  std::vector<Label> _inlineMessages; //user api structure
218  Util::RingDeque<Label> _inputInlineMessages; //shared structure
219 
220  Util::SpinLock _bufferAccumulatorLock;
221  BufferAccumulator _bufferAccumulator;
222 
223  std::vector<OutputPort *> _subscribers;
224 
226  void asyncMessagesPush(const Object &message, const BufferChunk &token = BufferChunk::null());
227  bool asyncMessagesEmpty(void);
228  Object asyncMessagesPop(void);
229  void asyncMessagesClear(void);
230 
232  void slotCallsPush(const Object &args, const BufferChunk &token);
233  bool slotCallsEmpty(void);
234  Object slotCallsPop(void);
235  void slotCallsClear(void);
236 
238  void inlineMessagesPush(const Label &label);
239  void inlineMessagesClear(void);
240 
242  void bufferAccumulatorFront(BufferChunk &);
243  void bufferAccumulatorPush(const BufferChunk &buffer);
244  void bufferAccumulatorPushNoLock(const BufferChunk &buffer);
245  void bufferAccumulatorPop(const size_t numBytes);
246  void bufferAccumulatorRequire(const size_t numBytes);
247  void bufferAccumulatorClear(void);
248 
250  void bufferLabelPush(
251  const std::vector<Label> &postedLabels,
252  const Util::RingDeque<BufferChunk> &postedBuffers);
253 
254  InputPort(void);
255  InputPort(const InputPort &){} // non construction-copyable
256  InputPort &operator=(const InputPort &){return *this;} // non copyable
257  friend class WorkerActor;
258  friend class OutputPort;
259 };
260 
261 } //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.