Replace every use of the foreach macro with a C++11 range-based for loop

This prevents a race condition with Qt5. A foreach loop makes a copy of its
Qt container, increasing the reference count to the container's internal
data. Qt5 often asserts isDetached(), which requires the reference count to
be <= 1. This assertion fails when the foreach loop increases the reference
count at exactly the wrong moment. Using a range-based for loop prevents an
unnecessary copy from being made and ensures this race condition isn't
triggered.
This commit is contained in:
Fastigium
2016-03-11 16:35:48 +01:00
parent ac67f2adb8
commit 3c7bfbac64
16 changed files with 27 additions and 50 deletions

View File

@@ -56,13 +56,13 @@ public:
do
{
nphsLeft = false;
foreach( const NotePlayHandle * cnph, nphv )
for( const NotePlayHandle * constNotePlayHandle : nphv )
{
NotePlayHandle * nph = const_cast<NotePlayHandle *>( cnph );
if( nph->state() != ThreadableJob::Done && ! nph->isFinished() )
NotePlayHandle * notePlayHandle = const_cast<NotePlayHandle *>( constNotePlayHandle );
if( notePlayHandle->state() != ThreadableJob::Done && ! notePlayHandle->isFinished() )
{
nphsLeft = true;
nph->process();
notePlayHandle->process();
}
}
}