///add track to the masterTrack's queue - this will allow future ODScheduling to affect them together. /// sets the NeedODUpdateFlag since we don't want the head task to finish without haven't dealt with the depednent /// ///@param track the track to bring into the tasks AND tracklist for this queue void ODWaveTrackTaskQueue::MergeWaveTrack(WaveTrack* track) { AddWaveTrack(track); mTasksMutex.Lock(); for(unsigned int i=0;i<mTasks.size();i++) { mTasks[i]->AddWaveTrack(track); mTasks[i]->SetNeedsODUpdate(); } mTasksMutex.Unlock(); }
//if the wavetrack is in this queue, and is not the only wavetrack, clones the tasks and schedules it. void ODWaveTrackTaskQueue::MakeWaveTrackIndependent(WaveTrack* track) { mTracksMutex.Lock(); if(mTracks.size()<2) { //if there is only one track, it is already independent. mTracksMutex.Unlock(); return; } for(unsigned int i=0;i<mTracks.size();i++) { if(mTracks[i]==track) { mTracksMutex.Unlock();//release the lock, since RemoveWaveTrack is a public threadsafe method. RemoveWaveTrack(mTracks[i]); //clone the items in order and add them to the ODManager. mTasksMutex.Lock(); for(unsigned int j=0;j<mTasks.size();j++) { auto task = mTasks[j]->Clone(); task->AddWaveTrack(track); //AddNewTask requires us to relinquish this lock. However, it is safe because ODManager::MakeWaveTrackIndependent //has already locked the m_queuesMutex. mTasksMutex.Unlock(); //AddNewTask locks the m_queuesMutex which is already locked by ODManager::MakeWaveTrackIndependent, //so we pass a boolean flag telling it not to lock again. ODManager::Instance()->AddNewTask(std::move(task), false); mTasksMutex.Lock(); } mTasksMutex.Unlock(); mTracksMutex.Lock(); break; } } mTracksMutex.Unlock(); }