Skip to content

Commit 8c57b94

Browse files
Remove ClearAllValues() calls from Tick() (#70)
1 parent b7a1661 commit 8c57b94

File tree

6 files changed

+53
-19
lines changed

6 files changed

+53
-19
lines changed

include/dspatch/Component.h

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ inline bool Component::ConnectInput( const Component::SPtr& fromComponent, int f
212212
// update source output's reference count
213213
it->fromComponent->_DecRefs( it->fromOutput );
214214

215+
// clear input
216+
for ( auto& inputBus : _inputBuses )
217+
{
218+
inputBus.ClearValue( toInput );
219+
}
220+
215221
// replace wire
216222
it->fromComponent = fromComponent.get();
217223
it->fromOutput = fromOutput;
@@ -238,6 +244,13 @@ inline void Component::DisconnectInput( int inputNo )
238244
// update source output's reference count
239245
it->fromComponent->_DecRefs( it->fromOutput );
240246

247+
// clear input
248+
for ( auto& inputBus : _inputBuses )
249+
{
250+
inputBus.ClearValue( inputNo );
251+
}
252+
253+
// remove wire
241254
_inputWires.erase( it );
242255
}
243256
}
@@ -253,19 +266,32 @@ inline void Component::DisconnectInput( const Component::SPtr& fromComponent )
253266
// update source output's reference count
254267
fromComponent->_DecRefs( it->fromOutput );
255268

269+
// clear input
270+
for ( auto& inputBus : _inputBuses )
271+
{
272+
inputBus.ClearValue( it->toInput );
273+
}
274+
275+
// remove wire
256276
it = _inputWires.erase( it );
257277
}
258278
}
259279

260280
inline void Component::DisconnectAllInputs()
261281
{
262-
// remove all wires from _inputWires
282+
// update all source output reference counts
263283
for ( const auto& wire : _inputWires )
264284
{
265-
// update source output's reference count
266285
wire.fromComponent->_DecRefs( wire.fromOutput );
267286
}
268287

288+
// clear all inputs
289+
for ( auto& inputBus : _inputBuses )
290+
{
291+
inputBus.ClearAllValues();
292+
}
293+
294+
// remove a;; wires
269295
_inputWires.clear();
270296
}
271297

@@ -359,46 +385,34 @@ inline int Component::GetBufferCount() const
359385
inline void Component::Tick( int bufferNo )
360386
{
361387
auto& inputBus = _inputBuses[bufferNo];
362-
auto& outputBus = _outputBuses[bufferNo];
363-
364-
// clear inputs
365-
inputBus.ClearAllValues();
366388

367389
for ( const auto& wire : _inputWires )
368390
{
369391
// get new inputs from incoming components
370392
wire.fromComponent->_GetOutput( bufferNo, wire.fromOutput, wire.toInput, inputBus );
371393
}
372394

373-
// clear outputs
374-
outputBus.ClearAllValues();
375-
376395
if ( _bufferCount != 1 && _processOrder == ProcessOrder::InOrder )
377396
{
378397
// wait for our turn to process
379398
_WaitForRelease( bufferNo );
380399

381400
// call Process_() with newly aquired inputs
382-
Process_( inputBus, outputBus );
401+
Process_( inputBus, _outputBuses[bufferNo] );
383402

384403
// signal that we're done processing
385404
_ReleaseNextBuffer( bufferNo );
386405
}
387406
else
388407
{
389408
// call Process_() with newly aquired inputs
390-
Process_( inputBus, outputBus );
409+
Process_( inputBus, _outputBuses[bufferNo] );
391410
}
392411
}
393412

394413
inline void Component::TickParallel( int bufferNo )
395414
{
396415
auto& inputBus = _inputBuses[bufferNo];
397-
auto& outputBus = _outputBuses[bufferNo];
398-
399-
// clear inputs and outputs
400-
inputBus.ClearAllValues();
401-
outputBus.ClearAllValues();
402416

403417
for ( const auto& wire : _inputWires )
404418
{
@@ -412,15 +426,15 @@ inline void Component::TickParallel( int bufferNo )
412426
_WaitForRelease( bufferNo );
413427

414428
// call Process_() with newly aquired inputs
415-
Process_( inputBus, outputBus );
429+
Process_( inputBus, _outputBuses[bufferNo] );
416430

417431
// signal that we're done processing
418432
_ReleaseNextBuffer( bufferNo );
419433
}
420434
else
421435
{
422436
// call Process_() with newly aquired inputs
423-
Process_( inputBus, outputBus );
437+
Process_( inputBus, _outputBuses[bufferNo] );
424438
}
425439

426440
// signal that our outputs are ready
@@ -542,6 +556,7 @@ inline void Component::_GetOutput( int bufferNo, int fromOutput, int toInput, DS
542556

543557
if ( !signal.has_value() )
544558
{
559+
toBus.ClearValue( toInput );
545560
return;
546561
}
547562

@@ -575,6 +590,7 @@ inline void Component::_GetOutputParallel( int bufferNo, int fromOutput, int toI
575590

576591
if ( !signal.has_value() )
577592
{
593+
toBus.ClearValue( toInput );
578594
return;
579595
}
580596

include/dspatch/SignalBus.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class SignalBus final
7878
void SetSignal( int toSignalIndex, const fast_any::any& fromSignal );
7979
void MoveSignal( int toSignalIndex, fast_any::any& fromSignal );
8080

81+
void ClearValue( int signalIndex );
8182
void ClearAllValues();
8283

8384
fast_any::type_info GetType( int signalIndex ) const;
@@ -165,6 +166,11 @@ inline void SignalBus::MoveSignal( int toSignalIndex, fast_any::any& fromSignal
165166
_signals[toSignalIndex].swap( fromSignal );
166167
}
167168

169+
inline void SignalBus::ClearValue( int signalIndex )
170+
{
171+
_signals[signalIndex].reset();
172+
}
173+
168174
inline void SignalBus::ClearAllValues()
169175
{
170176
for ( auto& signal : _signals )

include/fast_any

Submodule fast_any updated 1 file

tests/components/ChangingCounter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class ChangingCounter final : public Component
6666
break;
6767
}
6868
}
69+
else
70+
{
71+
outputs.ClearValue( 0 );
72+
}
6973
}
7074

7175
private:

tests/components/CircuitProbe.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class CircuitProbe final : public Component
5252
// inform the counter that the circuit is closed
5353
outputs.SetValue( 0, true );
5454
}
55+
else
56+
{
57+
outputs.ClearValue( 0 );
58+
}
5559
}
5660

5761
private:

tests/components/SporadicCounter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class SporadicCounter final : public Component
5151
outputs.SetValue( 0, _count );
5252
_count += _increment;
5353
}
54+
else
55+
{
56+
outputs.ClearValue( 0 );
57+
}
5458
}
5559

5660
private:

0 commit comments

Comments
 (0)