Skip to content

Commit

Permalink
Remove ClearAllValues() calls from Tick() (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusTomlinson authored Nov 14, 2024
1 parent b7a1661 commit 8c57b94
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 19 deletions.
52 changes: 34 additions & 18 deletions include/dspatch/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ inline bool Component::ConnectInput( const Component::SPtr& fromComponent, int f
// update source output's reference count
it->fromComponent->_DecRefs( it->fromOutput );

// clear input
for ( auto& inputBus : _inputBuses )
{
inputBus.ClearValue( toInput );
}

// replace wire
it->fromComponent = fromComponent.get();
it->fromOutput = fromOutput;
Expand All @@ -238,6 +244,13 @@ inline void Component::DisconnectInput( int inputNo )
// update source output's reference count
it->fromComponent->_DecRefs( it->fromOutput );

// clear input
for ( auto& inputBus : _inputBuses )
{
inputBus.ClearValue( inputNo );
}

// remove wire
_inputWires.erase( it );
}
}
Expand All @@ -253,19 +266,32 @@ inline void Component::DisconnectInput( const Component::SPtr& fromComponent )
// update source output's reference count
fromComponent->_DecRefs( it->fromOutput );

// clear input
for ( auto& inputBus : _inputBuses )
{
inputBus.ClearValue( it->toInput );
}

// remove wire
it = _inputWires.erase( it );
}
}

inline void Component::DisconnectAllInputs()
{
// remove all wires from _inputWires
// update all source output reference counts
for ( const auto& wire : _inputWires )
{
// update source output's reference count
wire.fromComponent->_DecRefs( wire.fromOutput );
}

// clear all inputs
for ( auto& inputBus : _inputBuses )
{
inputBus.ClearAllValues();
}

// remove a;; wires
_inputWires.clear();
}

Expand Down Expand Up @@ -359,46 +385,34 @@ inline int Component::GetBufferCount() const
inline void Component::Tick( int bufferNo )
{
auto& inputBus = _inputBuses[bufferNo];
auto& outputBus = _outputBuses[bufferNo];

// clear inputs
inputBus.ClearAllValues();

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

// clear outputs
outputBus.ClearAllValues();

if ( _bufferCount != 1 && _processOrder == ProcessOrder::InOrder )
{
// wait for our turn to process
_WaitForRelease( bufferNo );

// call Process_() with newly aquired inputs
Process_( inputBus, outputBus );
Process_( inputBus, _outputBuses[bufferNo] );

// signal that we're done processing
_ReleaseNextBuffer( bufferNo );
}
else
{
// call Process_() with newly aquired inputs
Process_( inputBus, outputBus );
Process_( inputBus, _outputBuses[bufferNo] );
}
}

inline void Component::TickParallel( int bufferNo )
{
auto& inputBus = _inputBuses[bufferNo];
auto& outputBus = _outputBuses[bufferNo];

// clear inputs and outputs
inputBus.ClearAllValues();
outputBus.ClearAllValues();

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

// call Process_() with newly aquired inputs
Process_( inputBus, outputBus );
Process_( inputBus, _outputBuses[bufferNo] );

// signal that we're done processing
_ReleaseNextBuffer( bufferNo );
}
else
{
// call Process_() with newly aquired inputs
Process_( inputBus, outputBus );
Process_( inputBus, _outputBuses[bufferNo] );
}

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

if ( !signal.has_value() )
{
toBus.ClearValue( toInput );
return;
}

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

if ( !signal.has_value() )
{
toBus.ClearValue( toInput );
return;
}

Expand Down
6 changes: 6 additions & 0 deletions include/dspatch/SignalBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class SignalBus final
void SetSignal( int toSignalIndex, const fast_any::any& fromSignal );
void MoveSignal( int toSignalIndex, fast_any::any& fromSignal );

void ClearValue( int signalIndex );
void ClearAllValues();

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

inline void SignalBus::ClearValue( int signalIndex )
{
_signals[signalIndex].reset();
}

inline void SignalBus::ClearAllValues()
{
for ( auto& signal : _signals )
Expand Down
2 changes: 1 addition & 1 deletion include/fast_any
Submodule fast_any updated 1 files
+28 −43 any.h
4 changes: 4 additions & 0 deletions tests/components/ChangingCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class ChangingCounter final : public Component
break;
}
}
else
{
outputs.ClearValue( 0 );
}
}

private:
Expand Down
4 changes: 4 additions & 0 deletions tests/components/CircuitProbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class CircuitProbe final : public Component
// inform the counter that the circuit is closed
outputs.SetValue( 0, true );
}
else
{
outputs.ClearValue( 0 );
}
}

private:
Expand Down
4 changes: 4 additions & 0 deletions tests/components/SporadicCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class SporadicCounter final : public Component
outputs.SetValue( 0, _count );
_count += _increment;
}
else
{
outputs.ClearValue( 0 );
}
}

private:
Expand Down

0 comments on commit 8c57b94

Please sign in to comment.