1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-09 08:31:13 +02:00

RAII for locking the all-projects mutex

This commit is contained in:
Paul Licameli 2016-08-02 22:07:20 -04:00
parent cfd7648fce
commit 186679b3a6
5 changed files with 16 additions and 41 deletions

View File

@ -316,9 +316,6 @@ void QuitAudacity(bool bForce)
//temporarilly commented out till it is added to all projects
//delete Profiler::Instance();
//DELETE the static lock for audacity projects
AudacityProject::DeleteAllProjectsDeleteLock();
//remove our logger
std::unique_ptr<wxLog>{ wxLog::SetActiveTarget(NULL) }; // DELETE

View File

@ -173,7 +173,11 @@ std::unique_ptr<TrackList> AudacityProject::msClipboard{ safenew TrackList() };
double AudacityProject::msClipT0 = 0.0;
double AudacityProject::msClipT1 = 0.0;
AudacityProject *AudacityProject::msClipProject = NULL;
ODLock *AudacityProject::msAllProjectDeleteMutex = new ODLock();
ODLock &AudacityProject::AllProjectDeleteMutex()
{
static ODLock theMutex;
return theMutex;
};
#if defined(__WXMAC__)
const int sbarSpaceWidth = 15;
@ -2054,18 +2058,6 @@ void AudacityProject::OnTrackListUpdated(wxCommandEvent & event)
event.Skip();
}
///Prevents deletion of projects from outside threads.
void AudacityProject::AllProjectsDeleteLock()
{
msAllProjectDeleteMutex->Lock();
}
///Reallows deletion of projects from outside threads.
void AudacityProject::AllProjectsDeleteUnlock()
{
msAllProjectDeleteMutex->Unlock();
}
///Handles the redrawing necessary for tasks as they partially update in the background.
void AudacityProject::OnODTaskUpdate(wxCommandEvent & WXUNUSED(event))
{
@ -2454,9 +2446,10 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event)
// have been deleted before this.
mDirManager->Deref();
AllProjectsDeleteLock();
gAudacityProjects.Remove(this);
AllProjectsDeleteUnlock();
{
ODLocker locker{ &AudacityProject::AllProjectDeleteMutex() };
gAudacityProjects.Remove(this);
}
if (gActiveProject == this) {
// Find a NEW active project
@ -4283,16 +4276,6 @@ void AudacityProject::DeleteClipboard()
msClipboard.reset();
}
//static
void AudacityProject::DeleteAllProjectsDeleteLock()
{
if(msAllProjectDeleteMutex)
{
delete msAllProjectDeleteMutex;
msAllProjectDeleteMutex=NULL;
}
}
void AudacityProject::ClearClipboard()
{
msClipT0 = 0.0;

View File

@ -339,7 +339,6 @@ class AUDACITY_DLL_API AudacityProject final : public wxFrame,
// Other commands
static TrackList *GetClipboardTracks();
static void DeleteClipboard();
static void DeleteAllProjectsDeleteLock();
// checkActive is a temporary hack that should be removed as soon as we
// get multiple effect preview working
@ -514,10 +513,6 @@ public:
bool TryToMakeActionAllowed
( CommandFlag & flags, CommandFlag flagsRqd, CommandFlag mask );
///Prevents DELETE from external thread - for e.g. use of GetActiveProject
static void AllProjectsDeleteLock();
static void AllProjectsDeleteUnlock();
void PushState(const wxString &desc, const wxString &shortDesc); // use UndoPush::AUTOSAVE
void PushState(const wxString &desc, const wxString &shortDesc, UndoPush flags);
void RollbackState();
@ -577,9 +572,12 @@ public:
static double msClipT0;
static double msClipT1;
public:
///Prevents DELETE from external thread - for e.g. use of GetActiveProject
//shared by all projects
static ODLock *msAllProjectDeleteMutex;
static ODLock &AllProjectDeleteMutex();
private:
// History/Undo manager
std::unique_ptr<UndoManager> mUndoManager;
bool mDirty{ false };

View File

@ -295,11 +295,10 @@ void ODManager::Start()
{
mNeedsDraw=0;
wxCommandEvent event( EVT_ODTASK_UPDATE );
AudacityProject::AllProjectsDeleteLock();
ODLocker locker{ &AudacityProject::AllProjectDeleteMutex() };
AudacityProject* proj = GetActiveProject();
if(proj)
proj->GetEventHandler()->AddPendingEvent(event);
AudacityProject::AllProjectsDeleteUnlock();
}
mTerminateMutex.Lock();
}

View File

@ -128,7 +128,7 @@ void ODTask::DoSome(float amountWork)
ODManager::Instance()->AddTask(this);
//we did a bit of progress - we should allow a resave.
AudacityProject::AllProjectsDeleteLock();
ODLocker locker{ &AudacityProject::AllProjectDeleteMutex() };
for(unsigned i=0; i<gAudacityProjects.GetCount(); i++)
{
if(IsTaskAssociatedWithProject(gAudacityProjects[i]))
@ -138,7 +138,6 @@ void ODTask::DoSome(float amountWork)
break;
}
}
AudacityProject::AllProjectsDeleteUnlock();
// printf("%s %i is %f done\n", GetTaskName(),GetTaskNumber(),PercentComplete());
@ -152,8 +151,8 @@ void ODTask::DoSome(float amountWork)
//END_TASK_PROFILING("On Demand open an 80 mb wav stereo file");
wxCommandEvent event( EVT_ODTASK_COMPLETE );
AudacityProject::AllProjectsDeleteLock();
ODLocker locker{ &AudacityProject::AllProjectDeleteMutex() };
for(unsigned i=0; i<gAudacityProjects.GetCount(); i++)
{
if(IsTaskAssociatedWithProject(gAudacityProjects[i]))
@ -165,7 +164,6 @@ void ODTask::DoSome(float amountWork)
break;
}
}
AudacityProject::AllProjectsDeleteUnlock();
// printf("%s %i complete\n", GetTaskName(),GetTaskNumber());
}