Audacity  2.2.0
ODManager Class Referencefinal

A singleton that manages currently running Tasks on an arbitrary number of threads. More...

#include <ODManager.h>

Classes

class  ODManagerHelperThread
 
class  Pauser
 

Public Member Functions

void DemandTrackUpdate (WaveTrack *track, double seconds)
 changes the tasks associated with this Waveform to process the task from a different point in the track More...
 
void DecrementCurrentThreads ()
 Reduces the count of current threads running. Meant to be called when ODTaskThreads end in their own threads. Thread-safe. More...
 
void AddNewTask (movable_ptr< ODTask > &&mtask, bool lockMutex=true)
 Adds a wavetrack, creates a queue member. More...
 
void SignalTaskQueueLoop ()
 Wakes the queue loop up by signalling its condition variable. More...
 
void RemoveWaveTrack (WaveTrack *track)
 removes a wavetrack and notifies its associated tasks to stop using its reference. More...
 
void MakeWaveTrackIndependent (WaveTrack *track)
 if it shares a queue/task, creates a NEW queue/task for the track, and removes it from any previously existing tasks. More...
 
bool MakeWaveTrackDependent (WaveTrack *dependentTrack, WaveTrack *masterTrack)
 
void ReplaceWaveTrack (WaveTrack *oldTrack, WaveTrack *newTrack)
 replace the wavetrack whose wavecache the gui watches for updates More...
 
void AddTask (ODTask *task)
 Adds a task to the running queue. Threas-safe. More...
 
void RemoveTaskIfInQueue (ODTask *task)
 removes a task from the active task queue More...
 
void FillTipForWaveTrack (const WaveTrack *t, wxString &tip)
 fills in the status bar message for a given track More...
 
float GetOverallPercentComplete ()
 Gets the total percent complete for all tasks combined. More...
 
int GetTotalNumTasks ()
 Get Total Number of Tasks. More...
 

Static Public Member Functions

static ODManagerInstanceFirstTime ()
 Gets the singleton instance. More...
 
static ODManagerInstanceNormal ()
 Gets the singleton instance. More...
 
static void Quit ()
 Kills the ODMananger Thread. More...
 
static void MarkLoadedODFlag ()
 sets a flag that is set if we have loaded some OD blockfiles from PCM. More...
 
static void UnmarkLoadedODFlag ()
 resets a flag that is set if we have loaded some OD blockfiles from PCM. More...
 
static bool HasLoadedODFlag ()
 returns a flag that is set if we have loaded some OD blockfiles from PCM. More...
 
static bool IsInstanceCreated ()
 returns whether or not the singleton instance was created yet More...
 

Static Public Attributes

static ODManager *(* Instance )() = &(ODManager::InstanceFirstTime)
 

Protected Member Functions

 ODManager ()
 
 ~ODManager ()
 
void Init ()
 Launches a thread for the manager and starts accepting Tasks. More...
 
void Start ()
 Start the main loop for the manager. More...
 
void UpdateQueues ()
 Remove references in our array to Tasks that have been completed/Schedule NEW ones. More...
 

Protected Attributes

std::vector< movable_ptr
< ODWaveTrackTaskQueue > > 
mQueues
 
ODLock mQueuesMutex
 
std::vector< ODTask * > mTasks
 
ODLock mTasksMutex
 
volatile bool mPause
 
ODLock mPauseLock
 
volatile int mNeedsDraw
 
volatile int mCurrentThreads
 Number of threads currently running. Accessed thru multiple threads. More...
 
ODLock mCurrentThreadsMutex
 
int mMaxThreads
 Maximum number of threads allowed out. More...
 
volatile bool mTerminate
 
ODLock mTerminateMutex
 
volatile bool mTerminated
 
ODLock mTerminatedMutex
 
ODLock mQueueNotEmptyCondLock
 
std::unique_ptr< ODConditionmQueueNotEmptyCond
 

Static Protected Attributes

static std::unique_ptr< ODManagerpMan {}
 

Detailed Description

A singleton that manages currently running Tasks on an arbitrary number of threads.

Constructor & Destructor Documentation

ODManager::ODManager ( )
protected
ODManager::~ODManager ( )
protected

Member Function Documentation

void ODManager::AddNewTask ( movable_ptr< ODTask > &&  mtask,
bool  lockMutex = true 
)

Adds a wavetrack, creates a queue member.

Adds a NEW task to the queue. Creates a queue if the tracks associated with the task is not in the list

Parameters
taskthe task to add
lockMutexlocks the mutexes if true (default). This function is used within other ODManager calls, which many need to set this to false.

References ODWaveTrackTaskQueue::AddTask(), AddTask(), mQueues, and mQueuesMutex.

Referenced by AudacityProject::EnqueueODTasks(), PCMImportFileHandle::Import(), ODWaveTrackTaskQueue::MakeWaveTrackIndependent(), and AudacityProject::PopState().

void ODManager::AddTask ( ODTask task)

Adds a task to the running queue. Threas-safe.

Adds a task to running queue. Thread-safe.

References mPause, mPauseLock, mQueueNotEmptyCond, mTasks, and mTasksMutex.

Referenced by AddNewTask(), ODTask::DoSome(), and UpdateQueues().

void ODManager::DecrementCurrentThreads ( )

Reduces the count of current threads running. Meant to be called when ODTaskThreads end in their own threads. Thread-safe.

References mCurrentThreads, and mCurrentThreadsMutex.

Referenced by ODTaskThread::Entry().

void ODManager::DemandTrackUpdate ( WaveTrack track,
double  seconds 
)

changes the tasks associated with this Waveform to process the task from a different point in the track

changes the tasks associated with this Waveform to process the task from a different point in the track

Parameters
trackthe track to update
secondsthe point in the track from which the tasks associated with track should begin processing from.

References mQueues, and mQueuesMutex.

Referenced by SelectHandle::AssignSelection(), and SelectHandle::Click().

void ODManager::FillTipForWaveTrack ( const WaveTrack t,
wxString &  tip 
)

fills in the status bar message for a given track

References mQueues, and mQueuesMutex.

float ODManager::GetOverallPercentComplete ( )

Gets the total percent complete for all tasks combined.

References GetTotalNumTasks(), mQueues, and mQueuesMutex.

Referenced by AudacityProject::OnTimer().

int ODManager::GetTotalNumTasks ( )

Get Total Number of Tasks.

References mQueues, and mQueuesMutex.

Referenced by GetOverallPercentComplete(), and AudacityProject::OnTimer().

bool ODManager::HasLoadedODFlag ( )
static

returns a flag that is set if we have loaded some OD blockfiles from PCM.

References sHasLoadedOD.

Referenced by AudacityProject::EnqueueODTasks(), and DirManager::ProjectFSCK().

void ODManager::Init ( )
protected

Launches a thread for the manager and starts accepting Tasks.

References mCurrentThreads, mMaxThreads, and safenew.

ODManager * ODManager::InstanceFirstTime ( )
static

Gets the singleton instance.

References gManagerCreated, Instance, InstanceNormal(), ODManager(), pMan, and safenew.

ODManager * ODManager::InstanceNormal ( )
static

Gets the singleton instance.

References pMan.

Referenced by InstanceFirstTime().

bool ODManager::MakeWaveTrackDependent ( WaveTrack dependentTrack,
WaveTrack masterTrack 
)

attach the track in question to another, already existing track's queues and tasks. Remove the task/tracks. Returns success if it was possible.. Some ODTask conditions make it impossible until the Tasks finish.

attach the track in question to another, already existing track's queues and tasks. Remove the task/tracks. only works if both tracks exist. Sets needODUpdate flag for the task. This is complicated and will probably need better design in the future.

Returns
returns success. Some ODTask conditions require that the tasks finish before merging. e.g. they have different effects being processed at the same time.

References ODWaveTrackTaskQueue::CanMergeWith(), ODWaveTrackTaskQueue::MergeWaveTrack(), mQueues, and mQueuesMutex.

void ODManager::MakeWaveTrackIndependent ( WaveTrack track)

if it shares a queue/task, creates a NEW queue/task for the track, and removes it from any previously existing tasks.

References ODWaveTrackTaskQueue::MakeWaveTrackIndependent(), mQueues, and mQueuesMutex.

Referenced by WaveTrackMenuTable::SplitStereo().

void ODManager::MarkLoadedODFlag ( )
static

sets a flag that is set if we have loaded some OD blockfiles from PCM.

References sHasLoadedOD.

Referenced by DirManager::HandleXMLTag().

void ODManager::Quit ( )
static

Kills the ODMananger Thread.

References IsInstanceCreated(), and pMan.

Referenced by QuitAudacity().

void ODManager::RemoveTaskIfInQueue ( ODTask task)

removes a task from the active task queue

References mTasks, and mTasksMutex.

Referenced by ODWaveTrackTaskQueue::~ODWaveTrackTaskQueue().

void ODManager::RemoveWaveTrack ( WaveTrack track)

removes a wavetrack and notifies its associated tasks to stop using its reference.

References mQueues, and mQueuesMutex.

Referenced by WaveTrack::~WaveTrack().

void ODManager::ReplaceWaveTrack ( WaveTrack oldTrack,
WaveTrack newTrack 
)

replace the wavetrack whose wavecache the gui watches for updates

References mQueues, and mQueuesMutex.

Referenced by Effect::ReplaceProcessedTracks().

void ODManager::SignalTaskQueueLoop ( )

Wakes the queue loop up by signalling its condition variable.

References mPause, mPauseLock, and mQueueNotEmptyCond.

Referenced by AudacityProject::OnTimer().

void ODManager::UnmarkLoadedODFlag ( )
static

resets a flag that is set if we have loaded some OD blockfiles from PCM.

References sHasLoadedOD.

Referenced by AudacityProject::OpenFile().

void ODManager::UpdateQueues ( )
protected

Remove references in our array to Tasks that have been completed/Schedule NEW ones.

remove tasks from ODWaveTrackTaskQueues that have been done. Schedules NEW ones if they exist Also remove queues that have become empty.

References AddTask(), ODWaveTrackTaskQueue::GetFrontTask(), mQueues, and mQueuesMutex.

Referenced by Start().

Member Data Documentation

pfodman ODManager::Instance = &(ODManager::InstanceFirstTime)
static

Gets the singleton instance - this is a function pointer that points to one of the below two instance calls. Note that it is not a member function pointer since it is a static function. the function pointer swapping is valid as long as the initial calls only happen from the main thread.

Referenced by SelectHandle::AssignSelection(), SelectHandle::Click(), ODTask::DoSome(), AudacityProject::EnqueueODTasks(), ODTaskThread::Entry(), ODManager::ODManagerHelperThread::Entry(), PCMImportFileHandle::Import(), InstanceFirstTime(), ODWaveTrackTaskQueue::MakeWaveTrackIndependent(), WaveTrackMenuTable::OnMergeStereo(), AudacityProject::OnTimer(), AudacityProject::PopState(), Effect::ReplaceProcessedTracks(), WaveTrackMenuTable::SplitStereo(), ODWaveTrackTaskQueue::~ODWaveTrackTaskQueue(), and WaveTrack::~WaveTrack().

volatile int ODManager::mCurrentThreads
protected

Number of threads currently running. Accessed thru multiple threads.

Referenced by DecrementCurrentThreads(), Init(), and Start().

ODLock ODManager::mCurrentThreadsMutex
protected

Referenced by DecrementCurrentThreads(), and Start().

int ODManager::mMaxThreads
protected

Maximum number of threads allowed out.

Referenced by Init(), and Start().

volatile int ODManager::mNeedsDraw
protected

Referenced by Start().

volatile bool ODManager::mPause
protected
ODLock ODManager::mPauseLock
protected

Referenced by AddTask(), SignalTaskQueueLoop(), and Start().

std::unique_ptr<ODCondition> ODManager::mQueueNotEmptyCond
protected
ODLock ODManager::mQueueNotEmptyCondLock
protected

Referenced by ODManager(), Start(), and ~ODManager().

std::vector<ODTask*> ODManager::mTasks
protected

Referenced by AddTask(), RemoveTaskIfInQueue(), and Start().

ODLock ODManager::mTasksMutex
protected

Referenced by AddTask(), RemoveTaskIfInQueue(), and Start().

volatile bool ODManager::mTerminate
protected

Referenced by ODManager(), Start(), and ~ODManager().

volatile bool ODManager::mTerminated
protected

Referenced by ODManager(), Start(), and ~ODManager().

ODLock ODManager::mTerminatedMutex
protected

Referenced by Start(), and ~ODManager().

ODLock ODManager::mTerminateMutex
protected

Referenced by Start(), and ~ODManager().

std::unique_ptr< ODManager > ODManager::pMan {}
staticprotected

The documentation for this class was generated from the following files: