Skip to content

Commit

Permalink
More optimizatons
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusTomlinson committed Mar 28, 2023
1 parent 23100a1 commit 2cd89dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,33 +264,34 @@ bool Component::Tick( Component::TickMode mode, int bufferNo )
// 1. set tickStatus -> TickStarted
p->tickStatuses[bufferNo] = internal::Component::TickStatus::TickStarted;

// 2. tick incoming components
for ( auto& wire : p->inputWires )
if ( mode == TickMode::Parallel )
{
if ( mode == TickMode::Series )
{
wire.fromComponent->Tick( mode, bufferNo );
}
else if ( mode == TickMode::Parallel )
// 2. tick incoming components
for ( auto& wire : p->inputWires )
{
if ( !wire.fromComponent->Tick( mode, bufferNo ) )
{
p->feedbackWires[bufferNo].emplace( &wire );
}
}
}

// 3. set tickStatus -> Ticking
p->tickStatuses[bufferNo] = internal::Component::TickStatus::Ticking;
// 3. set tickStatus -> Ticking
p->tickStatuses[bufferNo] = internal::Component::TickStatus::Ticking;

// do tick
if ( mode == TickMode::Series )
{
_DoTick( mode, bufferNo );
p->componentThreads[bufferNo].Resume( mode );
}
else if ( mode == TickMode::Parallel )
else
{
p->componentThreads[bufferNo].Resume( mode );
// 2. tick incoming components
for ( auto& wire : p->inputWires )
{
wire.fromComponent->Tick( mode, bufferNo );
}

// 3. set tickStatus -> Ticking
p->tickStatuses[bufferNo] = internal::Component::TickStatus::Ticking;

_DoTick( mode, bufferNo );
}
}
else if ( p->tickStatuses[bufferNo] == internal::Component::TickStatus::TickStarted )
Expand Down
6 changes: 6 additions & 0 deletions src/internal/AutoTickThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,14 @@ void AutoTickThread::Pause()

void AutoTickThread::Resume()
{
if ( !_pause )
{
return;
}

std::lock_guard<std::mutex> lock( _resumeMutex );

// cppcheck-suppress knownConditionTrueFalse
if ( _pause )
{
_resumeCondt.notify_all();
Expand Down
10 changes: 10 additions & 0 deletions src/internal/CircuitThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ void CircuitThread::SyncAndResume( DSPatch::Component::TickMode mode )
return;
}

if ( _gotSync )
{
std::lock_guard<std::mutex> lock( _resumeMutex );
_gotSync = false; // reset the sync flag

_gotResume = true; // set the resume flag
_resumeCondt.notify_all();
return;
}

std::unique_lock<std::mutex> lock( _resumeMutex );

if ( !_gotSync ) // if haven't already got sync
Expand Down

0 comments on commit 2cd89dc

Please sign in to comment.