Add locking to trackContainer::m_tracks

git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1527 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Paul Giblock
2008-09-02 03:09:12 +00:00
parent da6eef0ec1
commit fe7d269c80
5 changed files with 39 additions and 7 deletions

View File

@@ -564,6 +564,7 @@ void song::playPattern( pattern * _patternToPlay, bool _loop )
void song::updateLength( void )
{
m_length = 0;
m_tracksMutex.lockForRead();
for( trackList::const_iterator it = tracks().begin();
it != tracks().end(); ++it )
{
@@ -573,6 +574,7 @@ void song::updateLength( void )
m_length = cur;
}
}
m_tracksMutex.unlock();
}
@@ -638,11 +640,13 @@ void song::stopExport( void )
void song::insertBar( void )
{
for( trackList::iterator it = tracks().begin();
m_tracksMutex.lockForRead();
for( trackList::const_iterator it = tracks().begin();
it != tracks().end(); ++it )
{
( *it )->insertTact( m_playPos[Mode_PlaySong] );
}
m_tracksMutex.unlock();
}
@@ -650,11 +654,13 @@ void song::insertBar( void )
void song::removeBar( void )
{
for( trackList::iterator it = tracks().begin();
m_tracksMutex.lockForRead();
for( trackList::const_iterator it = tracks().begin();
it != tracks().end(); ++it )
{
( *it )->removeTact( m_playPos[Mode_PlaySong] );
}
m_tracksMutex.unlock();
}
@@ -666,7 +672,6 @@ void song::addBBTrack( void )
track * t = track::create( track::BBTrack, this );
engine::getBBTrackContainer()->setCurrentBB(
bbTrack::numOfBBTrack( t ) );
engine::getMixer()->unlock();
}

View File

@@ -2029,10 +2029,10 @@ tact track::length( void ) const
*/
void track::toggleSolo( void )
{
trackContainer::trackList & tl = m_trackContainer->tracks();
const trackContainer::trackList & tl = m_trackContainer->tracks();
bool solo_before = FALSE;
for( trackContainer::trackList::iterator it = tl.begin();
for( trackContainer::trackList::const_iterator it = tl.begin();
it != tl.end(); ++it )
{
if( *it != this )
@@ -2046,7 +2046,7 @@ void track::toggleSolo( void )
}
const bool solo = m_soloModel.value();
for( trackContainer::trackList::iterator it = tl.begin();
for( trackContainer::trackList::const_iterator it = tl.begin();
it != tl.end(); ++it )
{
if( solo )

View File

@@ -37,7 +37,8 @@
trackContainer::trackContainer( void ) :
model( NULL ),
journallingObject(),
m_tracks()
m_tracks(),
m_tracksMutex()
{
}
@@ -60,10 +61,12 @@ void trackContainer::saveSettings( QDomDocument & _doc, QDomElement & _this )
//mainWindow::saveWidgetState( this, _this );
// save settings of each track
m_tracksMutex.lockForRead();
for( int i = 0; i < m_tracks.size(); ++i )
{
m_tracks[i]->saveState( _doc, _this );
}
m_tracksMutex.unlock();
}
@@ -137,7 +140,9 @@ void trackContainer::addTrack( track * _track )
{
if( _track->type() != track::HiddenAutomationTrack )
{
m_tracksMutex.lockForWrite();
m_tracks.push_back( _track );
m_tracksMutex.unlock();
emit trackAdded( _track );
}
}
@@ -150,7 +155,9 @@ void trackContainer::removeTrack( track * _track )
int index = m_tracks.indexOf( _track );
if( index != -1 )
{
m_tracksMutex.lockForWrite();
m_tracks.remove( index );
m_tracksMutex.unlock();
if( engine::getSong() )
{
@@ -173,10 +180,12 @@ void trackContainer::updateAfterTrackAdd( void )
void trackContainer::clearAllTracks( void )
{
//m_tracksMutex.lockForWrite();
while( !m_tracks.isEmpty() )
{
delete m_tracks.first();
}
//m_tracksMutex.unlock();
}
@@ -185,6 +194,7 @@ void trackContainer::clearAllTracks( void )
int trackContainer::countTracks( track::TrackTypes _tt ) const
{
int cnt = 0;
m_tracksMutex.lockForRead();
for( int i = 0; i < m_tracks.size(); ++i )
{
if( m_tracks[i]->type() == _tt || _tt == track::NumTrackTypes )
@@ -192,6 +202,7 @@ int trackContainer::countTracks( track::TrackTypes _tt ) const
++cnt;
}
}
m_tracksMutex.unlock();
return( cnt );
}