Implementation of Source/Sinks and connected blocks paradigm #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a POC of the Blocks paradigm we discussed many times. Each thread may be seen as a "building block" with a number of "inputs" and "outputs". I didn't like to use INPUT or OUTPUT or other commonly used words in the embedded world, so to avoid confusion I opted for:
Source
to describe a block outputSink
to describe a block inputEach
Source
may be connected to an unlimited number ofSinks
, but eachSink
may be connected to only oneSource
.To define a
Source
the syntax is:SOURCE(name, type)
wherename
is the name of the source andtype
is the data type that is being transferred.to define a
Sink
the syntax is:SINK(name, type, queueSize)
wherename
andtype
are the same as aSource
,queueSize
define the blocking behavior when theSink
is connected to aSource
, more in detail:queueSize == 0
is a Sink with no buffer so the reading from the sink will block until the connected source send something, and vice versaqueueSize > 0
is a buffered Sink withqueueSize
slots, so the reading will block only if there is no data in the buffer and writing (from the connected Source) will block if the buffer is full.in general, the pace of data flow is dictated by the slowest between a Source and all his connected Sinks.
queueSize == -1
is a special "non-blocking size", in this case, the connection behave like a "shared" variable, so the Source will "instantly update" (without blocking) all connected Sinks and each Sink can be read (without blocking) as many times as needed.An example is available in
example/Blocks