Skip to content

Commit

Permalink
Use "Parallel" prefix for all non-series entities
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusTomlinson committed Apr 5, 2024
1 parent 4c658ae commit 5a59690
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
39 changes: 20 additions & 19 deletions include/dspatch/Circuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class Circuit final

for ( auto component : *_components )
{
component->TickSeries( _bufferNo );
component->Tick( _bufferNo );
}
}
}
Expand All @@ -316,20 +316,20 @@ class Circuit final
std::condition_variable _resumeCondt, _syncCondt;
};

class ParallelCircuitThread final
class CircuitThreadParallel final
{
public:
ParallelCircuitThread( const ParallelCircuitThread& ) = delete;
ParallelCircuitThread& operator=( const ParallelCircuitThread& ) = delete;
CircuitThreadParallel( const CircuitThreadParallel& ) = delete;
CircuitThreadParallel& operator=( const CircuitThreadParallel& ) = delete;

inline ParallelCircuitThread() = default;
inline CircuitThreadParallel() = default;

// cppcheck-suppress missingMemberCopy
inline ParallelCircuitThread( ParallelCircuitThread&& )
inline CircuitThreadParallel( CircuitThreadParallel&& )
{
}

inline ~ParallelCircuitThread()
inline ~CircuitThreadParallel()
{
Stop();
}
Expand All @@ -344,7 +344,7 @@ class Circuit final
_stop = false;
_gotSync = false;

_thread = std::thread( &ParallelCircuitThread::_Run, this );
_thread = std::thread( &CircuitThreadParallel::_Run, this );
}

inline void Stop()
Expand Down Expand Up @@ -430,12 +430,13 @@ class Circuit final

AutoTickThread _autoTickThread;

std::vector<DSPatch::Component*> _components;
std::set<DSPatch::Component::SPtr> _componentsSet;

std::vector<DSPatch::Component*> _components;
std::vector<DSPatch::Component*> _componentsParallel;

std::vector<CircuitThread> _circuitThreads;
std::vector<std::vector<ParallelCircuitThread>> _parallelCircuitThreads;
std::vector<std::vector<CircuitThreadParallel>> _circuitThreadsParallel;

bool _circuitDirty = false;
};
Expand Down Expand Up @@ -633,7 +634,7 @@ inline void Circuit::SetThreadCount( int threadCount )
_threadCount = threadCount;

// stop all threads
for ( auto& circuitThreads : _parallelCircuitThreads )
for ( auto& circuitThreads : _circuitThreadsParallel )
{
for ( auto& circuitThread : circuitThreads )
{
Expand All @@ -644,20 +645,20 @@ inline void Circuit::SetThreadCount( int threadCount )
// resize thread array
if ( _threadCount == 0 )
{
_parallelCircuitThreads.resize( 0 );
_circuitThreadsParallel.resize( 0 );
SetBufferCount( _bufferCount );
}
else
{
_parallelCircuitThreads.resize( _bufferCount == 0 ? 1 : _bufferCount );
for ( auto& circuitThread : _parallelCircuitThreads )
_circuitThreadsParallel.resize( _bufferCount == 0 ? 1 : _bufferCount );
for ( auto& circuitThread : _circuitThreadsParallel )
{
circuitThread.resize( _threadCount );
}

// initialise and start all threads
int i = 0;
for ( auto& circuitThreads : _parallelCircuitThreads )
for ( auto& circuitThreads : _circuitThreadsParallel )
{
int j = 0;
for ( auto& circuitThread : circuitThreads )
Expand Down Expand Up @@ -691,7 +692,7 @@ inline void Circuit::Tick()
// tick all internal components
for ( auto component : _components )
{
component->TickSeries( 0 );
component->Tick( 0 );
}

return;
Expand All @@ -700,7 +701,7 @@ inline void Circuit::Tick()
// =======================================================
else if ( _threadCount != 0 )
{
auto& circuitThreads = _parallelCircuitThreads[_currentBuffer];
auto& circuitThreads = _circuitThreadsParallel[_currentBuffer];

for ( auto& circuitThread : circuitThreads )
{
Expand Down Expand Up @@ -729,7 +730,7 @@ inline void Circuit::Sync()
{
circuitThread.Sync();
}
for ( auto& circuitThreads : _parallelCircuitThreads )
for ( auto& circuitThreads : _circuitThreadsParallel )
{
for ( auto& circuitThread : circuitThreads )
{
Expand Down Expand Up @@ -779,7 +780,7 @@ inline void Circuit::_Optimize()

for ( auto component : _components )
{
component->ScanSeries( orderedComponents );
component->Scan( orderedComponents );
}
for ( auto component : _components )
{
Expand Down
10 changes: 5 additions & 5 deletions include/dspatch/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ class Component
void SetBufferCount( int bufferCount, int startBuffer );
int GetBufferCount() const;

void TickSeries( int bufferNo );
void Tick( int bufferNo );
void TickParallel( int bufferNo );

void ScanSeries( std::vector<Component*>& components );
void Scan( std::vector<Component*>& components );
void ScanParallel( std::vector<std::vector<DSPatch::Component*>>& componentsMap, int& scanPosition );
void EndScan();

Expand Down Expand Up @@ -356,7 +356,7 @@ inline int Component::GetBufferCount() const
return (int)_inputBuses.size();
}

inline void Component::TickSeries( int bufferNo )
inline void Component::Tick( int bufferNo )
{
auto& inputBus = _inputBuses[bufferNo];
auto& outputBus = _outputBuses[bufferNo];
Expand Down Expand Up @@ -434,7 +434,7 @@ inline void Component::TickParallel( int bufferNo )
}
}

inline void Component::ScanSeries( std::vector<Component*>& components )
inline void Component::Scan( std::vector<Component*>& components )
{
// continue only if this component has not already been scanned
if ( _scanPosition != -1 )
Expand All @@ -448,7 +448,7 @@ inline void Component::ScanSeries( std::vector<Component*>& components )
for ( const auto& wire : _inputWires )
{
// scan incoming components
wire.fromComponent->ScanSeries( components );
wire.fromComponent->Scan( components );
}

components.emplace_back( this );
Expand Down
8 changes: 4 additions & 4 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ TEST_CASE( "FeedbackTestNoCircuit" )
// Tick the circuit 100 times
for ( int i = 0; i < 100; ++i )
{
counter->TickSeries( 0 );
adder->TickSeries( 0 );
passthrough->TickSeries( 0 );
probe->TickSeries( 0 );
counter->Tick( 0 );
adder->Tick( 0 );
passthrough->Tick( 0 );
probe->Tick( 0 );
}
}

Expand Down

0 comments on commit 5a59690

Please sign in to comment.